feat: create trpc route to fetch download link (#7495)

* feat: create trpc route to fetch download link

Signed-off-by: Udit Takkar <[email protected]>

* fix: removing file, adding isdownloadable logix

Signed-off-by: Udit Takkar <[email protected]>

* chore

Signed-off-by: Udit Takkar <[email protected]>

* fix: type error

Signed-off-by: Udit Takkar <[email protected]>

* Some performance enhancements and better error logging

* Add error message here too

---------

Signed-off-by: Udit Takkar <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
Udit TakkarandAlex van Andel authored and GitHub committed 2023-03-05 12:59:07 +00:00
1 parent cc1d606ba8
commit 2dddd4ce77
8 files changed
+204 -122

No files matched your search

@@ -1,39 +0,0 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { z } from "zod";
import { fetcher } from "@calcom/app-store/dailyvideo/lib/VideoApiAdapter";
import { getSession } from "@calcom/lib/auth";
import { IS_SELF_HOSTED } from "@calcom/lib/constants";
import { defaultHandler, defaultResponder } from "@calcom/lib/server";
const getAccessLinkSchema = z.object({
download_link: z.string().url(),
// expires (timestamp), s3_bucket, s3_region, s3_key
});
const requestQuery = z.object({
recordingId: z.string(),
});
const isDownloadAllowed = async (req: NextApiRequest) => {
if (IS_SELF_HOSTED) return true;
const session = await getSession({ req });
// Check if user belong to active team
return !session?.user?.belongsToActiveTeam;
};
async function handler(
req: NextApiRequest,
res: NextApiResponse<z.infer<typeof getAccessLinkSchema> | void>
) {
const { recordingId } = requestQuery.parse(req.query);
if (!(await isDownloadAllowed(req))) return res.status(403);
const response = await fetcher(`/recordings/${recordingId}/access-link`).then(getAccessLinkSchema.parse);
return res.status(200).json(response);
}
export default defaultHandler({
GET: Promise.resolve({ default: defaultResponder(handler) }),
});