UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 3.65 kB
{"version":3,"file":"resolve-poster.mjs","names":["formatter"],"sources":["../../../../src/services/media/helpers/resolve-poster.ts"],"sourcesContent":["import formatter from \"../../../libs/formatters/index.js\";\nimport { copy } from \"../../../libs/i18n/index.js\";\nimport { MediaRepository } from \"../../../libs/repositories/index.js\";\nimport type { ServiceFn } from \"../../../utils/services/types.js\";\n\nconst resolvePoster: ServiceFn<\n\t[\n\t\t{\n\t\t\tposterId: number;\n\t\t\tparentId?: number;\n\t\t},\n\t],\n\t{\n\t\tid: number;\n\t}\n> = async (context, data) => {\n\tif (data.parentId !== undefined && data.posterId === data.parentId) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tstatus: 400,\n\t\t\t\terrors: {\n\t\t\t\t\tposterId: {\n\t\t\t\t\t\tcode: \"media_error\",\n\t\t\t\t\t\tmessage: copy(\"server:core.media.poster.cannot.reference.self\"),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\tconst Media = new MediaRepository(context.db.client, context.config.db);\n\n\tconst posterRes = await Media.selectSingleById({\n\t\tid: data.posterId,\n\t\ttenantKey: context.request.tenantKey,\n\t\tincludeOwned: data.parentId !== undefined,\n\t\tvalidation: {\n\t\t\tenabled: true,\n\t\t\tdefaultError: {\n\t\t\t\tmessage: copy(\"server:core.media.poster.not.found\"),\n\t\t\t\tstatus: 404,\n\t\t\t},\n\t\t},\n\t});\n\tif (posterRes.error) return posterRes;\n\tif (\n\t\tposterRes.data.parent_media_id !== null &&\n\t\t!(\n\t\t\tposterRes.data.relation_type === \"poster\" &&\n\t\t\tposterRes.data.parent_media_id === data.parentId\n\t\t)\n\t) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tstatus: 404,\n\t\t\t\tmessage: copy(\"server:core.media.poster.not.found\"),\n\t\t\t},\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\tif (posterRes.data.type !== \"image\") {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tstatus: 400,\n\t\t\t\terrors: {\n\t\t\t\t\tposterId: {\n\t\t\t\t\t\tcode: \"media_error\",\n\t\t\t\t\t\tmessage: copy(\"server:core.media.poster.must.be.image\"),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\tif (formatter.formatBoolean(posterRes.data.is_deleted)) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tstatus: 400,\n\t\t\t\terrors: {\n\t\t\t\t\tposterId: {\n\t\t\t\t\t\tcode: \"media_error\",\n\t\t\t\t\t\tmessage: copy(\"server:core.media.poster.not.found\"),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: {\n\t\t\tid: posterRes.data.id,\n\t\t},\n\t};\n};\n\nexport default resolvePoster;\n"],"mappings":"yJAKA,MAAM,EAUF,MAAO,EAAS,IAAS,CAC5B,GAAI,EAAK,WAAa,IAAA,IAAa,EAAK,WAAa,EAAK,SACzD,MAAO,CACN,MAAO,CACN,KAAM,QACN,OAAQ,IACR,OAAQ,CACP,SAAU,CACT,KAAM,cACN,QAAS,EAAK,gDAAgD,CAC/D,CACD,CACD,EACA,KAAM,IAAA,EACP,EAKD,IAAM,EAAY,MAAM,IAFN,EAAgB,EAAQ,GAAG,OAAQ,EAAQ,OAAO,EAExC,CAAC,CAAC,iBAAiB,CAC9C,GAAI,EAAK,SACT,UAAW,EAAQ,QAAQ,UAC3B,aAAc,EAAK,WAAa,IAAA,GAChC,WAAY,CACX,QAAS,GACT,aAAc,CACb,QAAS,EAAK,oCAAoC,EAClD,OAAQ,GACT,CACD,CACD,CAAC,EAmDD,OAlDI,EAAU,MAAc,EAE3B,EAAU,KAAK,kBAAoB,MACnC,EACC,EAAU,KAAK,gBAAkB,UACjC,EAAU,KAAK,kBAAoB,EAAK,UAGlC,CACN,MAAO,CACN,KAAM,QACN,OAAQ,IACR,QAAS,EAAK,oCAAoC,CACnD,EACA,KAAM,IAAA,EACP,EAGG,EAAU,KAAK,OAAS,QAgBxBA,EAAU,cAAc,EAAU,KAAK,UAAU,EAC7C,CACN,MAAO,CACN,KAAM,QACN,OAAQ,IACR,OAAQ,CACP,SAAU,CACT,KAAM,cACN,QAAS,EAAK,oCAAoC,CACnD,CACD,CACD,EACA,KAAM,IAAA,EACP,EAGM,CACN,MAAO,IAAA,GACP,KAAM,CACL,GAAI,EAAU,KAAK,EACpB,CACD,EApCQ,CACN,MAAO,CACN,KAAM,QACN,OAAQ,IACR,OAAQ,CACP,SAAU,CACT,KAAM,cACN,QAAS,EAAK,wCAAwC,CACvD,CACD,CACD,EACA,KAAM,IAAA,EACP,CAyBF"}