@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 4 kB
Source Map (JSON)
{"version":3,"file":"create-preview.mjs","names":["previewSessionServices.create"],"sources":["../../../../../src/libs/http/controllers/documents/create-preview.ts"],"sourcesContent":["import { createFactory } from \"hono/factory\";\nimport { describeRoute } from \"hono-openapi\";\nimport z from \"zod\";\nimport { controllerSchemas } from \"../../../../schemas/documents.js\";\nimport { previewSessionServices } from \"../../../../services/index.js\";\nimport { LucidAPIError } from \"../../../../utils/errors/index.js\";\nimport serviceWrapper from \"../../../../utils/services/service-wrapper.js\";\nimport { copy } from \"../../../i18n/index.js\";\nimport authenticate from \"../../middleware/authenticate.js\";\nimport collectionPermissions from \"../../middleware/collection-permissions.js\";\nimport validate from \"../../middleware/validate.js\";\nimport validateCSRF from \"../../middleware/validate-csrf.js\";\nimport openAPI from \"../../openapi/index.js\";\nimport formatAPIResponse from \"../../utils/build-response.js\";\nimport createServiceContext from \"../../utils/create-service-context.js\";\n\nconst factory = createFactory();\n\nconst createPreviewController = factory.createHandlers(\n\tdescribeRoute({\n\t\tdescription:\n\t\t\t\"Create an expiring preview from a persisted document version.\",\n\t\ttags: [\"documents\"],\n\t\tsummary: \"Create Preview\",\n\t\tresponses: openAPI.responses({\n\t\t\tschema: z.toJSONSchema(controllerSchemas.createPreview.response),\n\t\t}),\n\t\trequestBody: openAPI.requestBody(controllerSchemas.createPreview.body),\n\t\tparameters: openAPI.parameters({\n\t\t\tparams: controllerSchemas.createPreview.params,\n\t\t\theaders: { csrf: true },\n\t\t}),\n\t}),\n\tvalidateCSRF,\n\tauthenticate(),\n\tvalidate(\"json\", controllerSchemas.createPreview.body),\n\tvalidate(\"param\", controllerSchemas.createPreview.params),\n\tcollectionPermissions(\"read\"),\n\tasync (c) => {\n\t\tconst { collectionKey, id } = c.req.valid(\"param\");\n\t\tconst { locale, mode, versionType, versionId } = c.req.valid(\"json\");\n\t\tconst context = createServiceContext(c);\n\n\t\tconst previewRes = await serviceWrapper(previewSessionServices.create, {\n\t\t\ttransaction: true,\n\t\t\tlogError: true,\n\t\t\tdefaultError: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tname: copy(\"server:core.routes.document.fetch.error.name\"),\n\t\t\t\tmessage: copy(\"server:core.routes.document.fetch.error.message\"),\n\t\t\t},\n\t\t})(context, {\n\t\t\tcollectionKey,\n\t\t\tdocumentId: Number.parseInt(id, 10),\n\t\t\tversionType,\n\t\t\tversionId,\n\t\t\tmode,\n\t\t\tlocale,\n\t\t\tcreator: c.get(\"auth\"),\n\t\t});\n\t\tif (previewRes.error) throw new LucidAPIError(previewRes.error);\n\n\t\tc.header(\"Cache-Control\", \"private, no-store\");\n\t\tc.header(\"Pragma\", \"no-cache\");\n\t\tc.header(\"Referrer-Policy\", \"no-referrer\");\n\n\t\tc.status(200);\n\t\treturn c.json(formatAPIResponse(c, { data: previewRes.data }));\n\t},\n);\n\nexport default createPreviewController;\n"],"mappings":"ivBAkBA,MAAM,EAFU,EAEsB,CAAC,CAAC,eACvC,EAAc,CACb,YACC,gEACD,KAAM,CAAC,WAAW,EAClB,QAAS,iBACT,UAAW,EAAQ,UAAU,CAC5B,OAAQ,EAAE,aAAa,EAAkB,cAAc,QAAQ,CAChE,CAAC,EACD,YAAa,EAAQ,YAAY,EAAkB,cAAc,IAAI,EACrE,WAAY,EAAQ,WAAW,CAC9B,OAAQ,EAAkB,cAAc,OACxC,QAAS,CAAE,KAAM,EAAK,CACvB,CAAC,CACF,CAAC,EACD,EACA,EAAa,EACb,EAAS,OAAQ,EAAkB,cAAc,IAAI,EACrD,EAAS,QAAS,EAAkB,cAAc,MAAM,EACxD,EAAsB,MAAM,EAC5B,KAAO,IAAM,CACZ,GAAM,CAAE,gBAAe,MAAO,EAAE,IAAI,MAAM,OAAO,EAC3C,CAAE,SAAQ,OAAM,cAAa,aAAc,EAAE,IAAI,MAAM,MAAM,EAC7D,EAAU,EAAqB,CAAC,EAEhC,EAAa,MAAM,EAAeA,EAA+B,CACtE,YAAa,GACb,SAAU,GACV,aAAc,CACb,KAAM,QACN,KAAM,EAAK,8CAA8C,EACzD,QAAS,EAAK,iDAAiD,CAChE,CACD,CAAC,CAAC,CAAC,EAAS,CACX,gBACA,WAAY,OAAO,SAAS,EAAI,EAAE,EAClC,cACA,YACA,OACA,SACA,QAAS,EAAE,IAAI,MAAM,CACtB,CAAC,EACD,GAAI,EAAW,MAAO,MAAM,IAAI,EAAc,EAAW,KAAK,EAO9D,OALA,EAAE,OAAO,gBAAiB,mBAAmB,EAC7C,EAAE,OAAO,SAAU,UAAU,EAC7B,EAAE,OAAO,kBAAmB,aAAa,EAEzC,EAAE,OAAO,GAAG,EACL,EAAE,KAAK,EAAkB,EAAG,CAAE,KAAM,EAAW,IAAK,CAAC,CAAC,CAC9D,CACD"}