@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 3.94 kB
Source Map (JSON)
{"version":3,"file":"get-single.mjs","names":["mediaServices.client.getSingle"],"sources":["../../../../../../src/libs/http/controllers/media/client/get-single.ts"],"sourcesContent":["import { minutesToSeconds } from \"date-fns\";\nimport { createFactory } from \"hono/factory\";\nimport { describeRoute } from \"hono-openapi\";\nimport z from \"zod\";\nimport { controllerSchemas } from \"../../../../../schemas/media.js\";\nimport { mediaServices } 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 cacheKeys from \"../../../../kv/cache-keys.js\";\nimport { ClientScopes } from \"../../../../permission/client-scopes.js\";\nimport cache from \"../../../middleware/cache.js\";\nimport clientAuthentication from \"../../../middleware/client-authenticate.js\";\nimport clientScopes from \"../../../middleware/client-scopes.js\";\nimport validate from \"../../../middleware/validate.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 getSingleController = factory.createHandlers(\n\tdescribeRoute({\n\t\tdescription:\n\t\t\t\"Get a single media item by ID via the client integration. Returns translated metadata.\",\n\t\ttags: [\"client-media\"],\n\t\tsummary: \"Get Media\",\n\t\tresponses: openAPI.responses({\n\t\t\tschema: z.toJSONSchema(controllerSchemas.client.getSingle.response),\n\t\t}),\n\t\tparameters: openAPI.parameters({\n\t\t\tparams: controllerSchemas.client.getSingle.params,\n\t\t\theaders: {\n\t\t\t\tauthorization: true,\n\t\t\t},\n\t\t}),\n\t}),\n\tclientAuthentication,\n\tclientScopes([ClientScopes.MediaRead]),\n\tvalidate(\"param\", controllerSchemas.client.getSingle.params),\n\tcache({\n\t\tttl: minutesToSeconds(5),\n\t\tmode: \"static\",\n\t\tstaticKey: (c) => {\n\t\t\tconst id = c.req.param(\"id\");\n\t\t\tif (!id) return null;\n\n\t\t\treturn cacheKeys.http.static.clientMediaSingle(\n\t\t\t\tid,\n\t\t\t\tc.get(\"tenant\")?.key ?? null,\n\t\t\t);\n\t\t},\n\t}),\n\tasync (c) => {\n\t\tconst { id } = c.req.valid(\"param\");\n\t\tconst context = createServiceContext(c);\n\n\t\tconst media = await serviceWrapper(mediaServices.client.getSingle, {\n\t\t\ttransaction: false,\n\t\t\tdefaultError: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tname: copy(\"server:core.routes.media.fetch.error.name\"),\n\t\t\t\tmessage: copy(\"server:core.routes.media.fetch.error.message\"),\n\t\t\t},\n\t\t})(context, {\n\t\t\tid: Number.parseInt(id, 10),\n\t\t});\n\t\tif (media.error) throw new LucidAPIError(media.error);\n\n\t\tc.status(200);\n\t\treturn c.json(\n\t\t\tformatAPIResponse(c, {\n\t\t\t\tdata: media.data,\n\t\t\t}),\n\t\t);\n\t},\n);\n\nexport default getSingleController;\n"],"mappings":"w6BAqBA,MAAM,EAFU,EAEkB,CAAC,CAAC,eACnC,EAAc,CACb,YACC,yFACD,KAAM,CAAC,cAAc,EACrB,QAAS,YACT,UAAW,EAAQ,UAAU,CAC5B,OAAQ,EAAE,aAAa,EAAkB,OAAO,UAAU,QAAQ,CACnE,CAAC,EACD,WAAY,EAAQ,WAAW,CAC9B,OAAQ,EAAkB,OAAO,UAAU,OAC3C,QAAS,CACR,cAAe,EAChB,CACD,CAAC,CACF,CAAC,EACD,EACA,EAAa,CAAC,EAAa,SAAS,CAAC,EACrC,EAAS,QAAS,EAAkB,OAAO,UAAU,MAAM,EAC3D,EAAM,CACL,IAAK,EAAiB,CAAC,EACvB,KAAM,SACN,UAAY,GAAM,CACjB,IAAM,EAAK,EAAE,IAAI,MAAM,IAAI,EAG3B,OAFK,EAEE,EAAU,KAAK,OAAO,kBAC5B,EACA,EAAE,IAAI,QAAQ,CAAC,EAAE,KAAO,IACzB,EALgB,IAMjB,CACD,CAAC,EACD,KAAO,IAAM,CACZ,GAAM,CAAE,MAAO,EAAE,IAAI,MAAM,OAAO,EAC5B,EAAU,EAAqB,CAAC,EAEhC,EAAQ,MAAM,EAAeA,EAAgC,CAClE,YAAa,GACb,aAAc,CACb,KAAM,QACN,KAAM,EAAK,2CAA2C,EACtD,QAAS,EAAK,8CAA8C,CAC7D,CACD,CAAC,CAAC,CAAC,EAAS,CACX,GAAI,OAAO,SAAS,EAAI,EAAE,CAC3B,CAAC,EACD,GAAI,EAAM,MAAO,MAAM,IAAI,EAAc,EAAM,KAAK,EAGpD,OADA,EAAE,OAAO,GAAG,EACL,EAAE,KACR,EAAkB,EAAG,CACpB,KAAM,EAAM,IACb,CAAC,CACF,CACD,CACD"}