@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 1.88 kB
Source Map (JSON)
{"version":3,"file":"check-can-store.mjs","names":[],"sources":["../../../../src/services/processed-images/checks/check-can-store.ts"],"sourcesContent":["import { copy } from \"../../../libs/i18n/index.js\";\nimport type { ServiceFn } from \"../../../utils/services/types.js\";\nimport getStorageUsage from \"../../media/get-storage-usage.js\";\n\nconst checkCanStore: ServiceFn<\n\t[\n\t\t{\n\t\t\tsize: number;\n\t\t\ttenantKey?: string | null;\n\t\t},\n\t],\n\t{\n\t\tproposedSize: number;\n\t}\n> = async (context, data) => {\n\tconst maxFileSize = context.config.media.limits.uploadBytes;\n\tconst storageLimit = context.config.media.limits.storageBytes;\n\n\tif (data.size > maxFileSize) {\n\t\treturn {\n\t\t\terror: undefined,\n\t\t\tdata: {\n\t\t\t\tproposedSize: 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tconst storageUsageRes = await getStorageUsage(context, {\n\t\ttenantKey: data.tenantKey ?? null,\n\t});\n\tif (storageUsageRes.error) return storageUsageRes;\n\n\tconst proposedSize = storageUsageRes.data.total + data.size;\n\tif (storageLimit !== false && proposedSize > storageLimit) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tmessage: copy(\"server:core.processed.images.size.limit.exceeded\"),\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\tproposedSize: proposedSize,\n\t\t},\n\t};\n};\n\nexport default checkCanStore;\n"],"mappings":"oGAIA,MAAM,EAUF,MAAO,EAAS,IAAS,CAC5B,IAAM,EAAc,EAAQ,OAAO,MAAM,OAAO,YAC1C,EAAe,EAAQ,OAAO,MAAM,OAAO,aAEjD,GAAI,EAAK,KAAO,EACf,MAAO,CACN,MAAO,IAAA,GACP,KAAM,CACL,aAAc,CACf,CACD,EAGD,IAAM,EAAkB,MAAM,EAAgB,EAAS,CACtD,UAAW,EAAK,WAAa,IAC9B,CAAC,EACD,GAAI,EAAgB,MAAO,OAAO,EAElC,IAAM,EAAe,EAAgB,KAAK,MAAQ,EAAK,KAWvD,OAVI,IAAiB,IAAS,EAAe,EACrC,CACN,MAAO,CACN,KAAM,QACN,QAAS,EAAK,kDAAkD,CACjE,EACA,KAAM,IAAA,EACP,EAGM,CACN,MAAO,IAAA,GACP,KAAM,CACS,cACf,CACD,CACD"}