UNPKG

@lucidcms/core

Version:

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

1 lines 1.76 kB
{"version":3,"file":"create-profile-picture-upload-session.mjs","names":["mediaServices.createUploadSession"],"sources":["../../../src/services/account/create-profile-picture-upload-session.ts"],"sourcesContent":["import type { UploadSessionResponse } from \"@lucidcms/types\";\nimport { copy } from \"../../libs/i18n/index.js\";\nimport { getMediaType } from \"../../utils/media/index.js\";\nimport type { ServiceFn } from \"../../utils/services/types.js\";\nimport { mediaServices } from \"../index.js\";\n\nconst createProfilePictureUploadSession: ServiceFn<\n\t[\n\t\t{\n\t\t\tfileName: string;\n\t\t\tmimeType: string;\n\t\t\tsize: number;\n\t\t\tuserId: number;\n\t\t},\n\t],\n\tUploadSessionResponse\n> = async (context, data) => {\n\tif (getMediaType(data.mimeType) !== \"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\tmimeType: {\n\t\t\t\t\t\tcode: \"media_error\",\n\t\t\t\t\t\tmessage: copy(\"server:core.media.errors.invalid.type\", {\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\ttype: \"image\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\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 mediaServices.createUploadSession(context, {\n\t\tfileName: data.fileName,\n\t\tmimeType: data.mimeType,\n\t\tsize: data.size,\n\t\tpublic: true,\n\t\tuserId: data.userId,\n\t});\n};\n\nexport default createProfilePictureUploadSession;\n"],"mappings":"sJAMA,MAAM,EAUF,MAAO,EAAS,IACf,EAAa,EAAK,QAAQ,IAAM,QAoB7BA,EAAkC,EAAS,CACjD,SAAU,EAAK,SACf,SAAU,EAAK,SACf,KAAM,EAAK,KACX,OAAQ,GACR,OAAQ,EAAK,MACd,CAAC,EAzBO,CACN,MAAO,CACN,KAAM,QACN,OAAQ,IACR,OAAQ,CACP,SAAU,CACT,KAAM,cACN,QAAS,EAAK,wCAAyC,CACtD,KAAM,CACL,KAAM,OACP,CACD,CAAC,CACF,CACD,CACD,EACA,KAAM,IAAA,EACP"}