diff --git a/server/routes/api/documents/documents.ts b/server/routes/api/documents/documents.ts index 23c8a0eee..d3cd1e745 100644 --- a/server/routes/api/documents/documents.ts +++ b/server/routes/api/documents/documents.ts @@ -442,13 +442,12 @@ router.post( }), validate(T.DocumentsExportSchema), async (ctx: APIContext) => { - const { id, shareId } = ctx.input; + const { id } = ctx.input; const { user } = ctx.state; const accept = ctx.request.headers["accept"]; const { document } = await documentLoader({ id, - shareId, user, // We need the collaborative state to generate HTML. includeState: !accept?.includes("text/markdown"), @@ -672,7 +671,9 @@ router.post( let response; if (shareId) { + const teamFromCtx = await getTeamFromContext(ctx); const { share, document } = await documentLoader({ + teamId: teamFromCtx?.id, shareId, user, }); diff --git a/server/routes/api/documents/schema.ts b/server/routes/api/documents/schema.ts index 192542697..9d01d3a6d 100644 --- a/server/routes/api/documents/schema.ts +++ b/server/routes/api/documents/schema.ts @@ -114,17 +114,7 @@ export const DocumentsInfoSchema = z export type DocumentsInfoReq = z.infer; -export const DocumentsExportSchema = z - .object({ - /** Id of the document to be exported */ - id: z.string().uuid().optional(), - - /** Share Id, if available */ - shareId: z.string().uuid().optional(), - }) - .refine((obj) => !(isEmpty(obj.id) && isEmpty(obj.shareId)), { - message: "one of id or shareId is required", - }); +export const DocumentsExportSchema = BaseIdSchema.extend({}); export type DocumentsExportReq = z.infer; @@ -154,7 +144,10 @@ export const DocumentsSearchSchema = SearchQuerySchema.merge( userId: z.string().uuid().optional(), /** Filter results for the team derived from shareId */ - shareId: z.string().uuid().optional(), + shareId: z + .string() + .refine((val) => isUUID(val) || SHARE_URL_SLUG_REGEX.test(val)) + .optional(), /** Min words to be shown in the results snippets */ snippetMinWords: z.number().default(20),