@maas/payload-plugin-media-cloud 0.0.37 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/adapter/handleUpload.mjs +9 -9
  2. package/dist/adapter/handleUpload.mjs.map +1 -1
  3. package/dist/adapter/staticHandler.mjs +1 -1
  4. package/dist/adapter/staticHandler.mjs.map +1 -1
  5. package/dist/adapter/storageAdapter.mjs +1 -1
  6. package/dist/collectionHooks/afterChange.mjs +14 -3
  7. package/dist/collectionHooks/afterChange.mjs.map +1 -1
  8. package/dist/collections/mediaCollection.mjs +2 -3
  9. package/dist/collections/mediaCollection.mjs.map +1 -1
  10. package/dist/components/uploadHandler/uploadHandler.mjs +117 -99
  11. package/dist/components/uploadHandler/uploadHandler.mjs.map +1 -1
  12. package/dist/components/uploadManager/uploadManager.mjs +2 -2
  13. package/dist/components/uploadManager/uploadManager.mjs.map +1 -1
  14. package/dist/endpoints/fileExistsHandler.mjs +3 -3
  15. package/dist/endpoints/fileExistsHandler.mjs.map +1 -1
  16. package/dist/endpoints/muxAssetHandler.mjs +2 -2
  17. package/dist/endpoints/muxAssetHandler.mjs.map +1 -1
  18. package/dist/endpoints/muxCreateUploadHandler.mjs +2 -2
  19. package/dist/endpoints/muxCreateUploadHandler.mjs.map +1 -1
  20. package/dist/fields/mux.mjs +0 -3
  21. package/dist/fields/mux.mjs.map +1 -1
  22. package/dist/tus/stores/s3/s3Store.mjs +15 -1
  23. package/dist/tus/stores/s3/s3Store.mjs.map +1 -1
  24. package/dist/types/errors.d.mts +8 -0
  25. package/dist/types/errors.mjs +8 -0
  26. package/dist/types/errors.mjs.map +1 -1
  27. package/dist/types/index.d.mts +5 -1
  28. package/dist/utils/defaultOptions.mjs +5 -1
  29. package/dist/utils/defaultOptions.mjs.map +1 -1
  30. package/dist/utils/file.mjs +1 -1
  31. package/dist/utils/file.mjs.map +1 -1
  32. package/package.json +7 -5
@@ -1 +1 @@
1
- {"version":3,"file":"file.mjs","names":["magicError: UseMagicErrorReturn"],"sources":["../../src/utils/file.ts"],"sourcesContent":["import { fileTypeFromBuffer } from 'file-type'\nimport { parse } from 'pathe'\n\nimport { getFileExistsHandler } from '../endpoints/fileExistsHandler'\n\nimport { useMagicError, type UseMagicErrorReturn } from '@maas/error-handler'\nimport { MediaCloudErrors } from '../types/errors'\n\nimport type { S3Store } from '../tus/stores/s3/s3Store'\nimport type { MediaCloudPluginOptions, MimeType } from '../types'\n\nconst magicError: UseMagicErrorReturn = useMagicError({\n prefix: 'PLUGIN-MEDIA-CLOUD',\n})\n\nconst { logError, throwError } = magicError\n\nconst MUX_SUPPORTED_VIDEO_FORMATS = new Set([\n 'application/mxf',\n 'video/3gpp',\n 'video/3gpp2',\n 'video/mp2t',\n 'video/mp4',\n 'video/mpeg',\n 'video/quicktime',\n 'video/webm',\n 'video/x-f4v',\n 'video/x-flv',\n 'video/x-matroska',\n 'video/x-ms-asf',\n 'video/x-ms-wmv',\n 'video/x-msvideo',\n 'video/x-mxf',\n])\n\n/**\n * Checks if a file is a video file supported by Mux\n * @param file - The file to check\n * @returns Promise that resolves to true if the file is a supported video format, false otherwise\n */\nexport async function isVideo(file: File): Promise<boolean> {\n try {\n const buffer = new Uint8Array(await file.arrayBuffer())\n const fileType = await fileTypeFromBuffer(buffer)\n\n return fileType?.mime\n ? MUX_SUPPORTED_VIDEO_FORMATS.has(fileType.mime)\n : false\n } catch {\n return false\n }\n}\n\nconst allowedMimeTypes = new Set<MimeType>([\n 'application/mxf',\n 'video/3gpp',\n 'video/3gpp2',\n 'video/mp2t',\n 'video/mp4',\n 'video/mpeg',\n 'video/quicktime',\n 'video/webm',\n 'video/x-f4v',\n 'video/x-flv',\n 'video/x-matroska',\n 'video/x-ms-asf',\n 'video/x-ms-wmv',\n 'video/x-msvideo',\n 'video/x-mxf',\n 'image/apng',\n 'image/avif',\n 'image/gif',\n 'image/jpeg',\n 'image/png',\n 'image/svg+xml',\n 'image/webp',\n])\n\n/**\n * Check the mime type against allowed mime types\n * @param mimeType - The file to check\n */\nfunction validateMimeType(mimeType: string) {\n if (!allowedMimeTypes.has(mimeType as MimeType)) {\n throwError(MediaCloudErrors.FILE_TYPE_UNSUPPORTED_ERROR)\n }\n}\n\n/**\n * Gets the MIME type of a file using file-type library\n * @param file - The file to check\n * @returns Promise that resolves to the MIME type of the file or undefined if it cannot be determined\n */\nexport async function getMimeType(file: File): Promise<MimeType | undefined> {\n try {\n const buffer = new Uint8Array(await file.arrayBuffer())\n const fileType = await fileTypeFromBuffer(buffer)\n\n if (!fileType?.mime) {\n logError(MediaCloudErrors.FILE_TYPE_ERROR.message)\n return undefined\n }\n\n validateMimeType(fileType.mime)\n return fileType.mime as MimeType\n } catch (_error) {\n logError(MediaCloudErrors.FILE_TYPE_ERROR.message)\n return undefined\n }\n}\n\n/**\n * Generates a unique filename by appending a random suffix if needed\n * @param originalFilename - The original filename\n * @returns A unique filename with a random suffix appended before the extension\n */\nexport function generateUniqueFilename(originalFilename: string): string {\n const timestamp = Date.now().toString(36)\n // Parse name and extension\n const { name, ext } = parse(originalFilename)\n\n // Sanitize name\n const sanitizedName = sanitizeFilename(name)\n\n return `${sanitizedName}-${timestamp}${ext}`\n}\n\n/**\n * Sanitizes a filename by removing/replacing invalid characters and handling edge cases\n * Converts all non-alphanumeric characters (except dots for extensions) to underscores\n * @param filename - The filename to sanitize\n * @returns A sanitized filename safe for all operating systems\n * @throws {TypeError} When filename is not a string\n */\nexport function sanitizeFilename(filename: string): string {\n try {\n const parsed = parse(filename)\n const sanitized = parsed.name\n .replace(/[^a-zA-Z0-9_.-]/g, '_')\n .replace(/_{2,}/g, '_')\n .replace(/^_|_$/g, '')\n return `${sanitized}${parsed.ext}`\n } catch (_error) {\n logError(MediaCloudErrors.FILENAME_SANITIZE_ERROR.message)\n return filename\n }\n}\n\ninterface CreateFileEndpointsArgs {\n getS3Store: () => S3Store\n pluginOptions: MediaCloudPluginOptions\n}\n\nexport function createFileEndpoints(args: CreateFileEndpointsArgs) {\n const { getS3Store, pluginOptions } = args\n\n const collection = pluginOptions.collection\n magicError.assert(collection, MediaCloudErrors.COLLECTION_REQUIRED)\n\n return [\n {\n handler: getFileExistsHandler({ getS3Store, collection }),\n method: 'get' as const,\n path: '/uploads/:filename/exists',\n },\n ]\n}\n"],"mappings":";;;;;;;AAWA,MAAMA,aAAkC,cAAc,EACpD,QAAQ,sBACT,CAAC;AAEF,MAAM,EAAE,UAAU,eAAe;AAEjC,MAAM,8BAA8B,IAAI,IAAI;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;AAOF,eAAsB,QAAQ,MAA8B;AAC1D,KAAI;EAEF,MAAM,WAAW,MAAM,mBADR,IAAI,WAAW,MAAM,KAAK,aAAa,CAAC,CACN;AAEjD,SAAO,UAAU,OACb,4BAA4B,IAAI,SAAS,KAAK,GAC9C;SACE;AACN,SAAO;;;AAIX,MAAM,mBAAmB,IAAI,IAAc;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;AAMF,SAAS,iBAAiB,UAAkB;AAC1C,KAAI,CAAC,iBAAiB,IAAI,SAAqB,CAC7C,YAAW,iBAAiB,4BAA4B;;;;;;;AAS5D,eAAsB,YAAY,MAA2C;AAC3E,KAAI;EAEF,MAAM,WAAW,MAAM,mBADR,IAAI,WAAW,MAAM,KAAK,aAAa,CAAC,CACN;AAEjD,MAAI,CAAC,UAAU,MAAM;AACnB,YAAS,iBAAiB,gBAAgB,QAAQ;AAClD;;AAGF,mBAAiB,SAAS,KAAK;AAC/B,SAAO,SAAS;UACT,QAAQ;AACf,WAAS,iBAAiB,gBAAgB,QAAQ;AAClD;;;;;;;;AASJ,SAAgB,uBAAuB,kBAAkC;CACvE,MAAM,YAAY,KAAK,KAAK,CAAC,SAAS,GAAG;CAEzC,MAAM,EAAE,MAAM,QAAQ,MAAM,iBAAiB;AAK7C,QAAO,GAFe,iBAAiB,KAAK,CAEpB,GAAG,YAAY;;;;;;;;;AAUzC,SAAgB,iBAAiB,UAA0B;AACzD,KAAI;EACF,MAAM,SAAS,MAAM,SAAS;AAK9B,SAAO,GAJW,OAAO,KACtB,QAAQ,oBAAoB,IAAI,CAChC,QAAQ,UAAU,IAAI,CACtB,QAAQ,UAAU,GAAG,GACF,OAAO;UACtB,QAAQ;AACf,WAAS,iBAAiB,wBAAwB,QAAQ;AAC1D,SAAO;;;AASX,SAAgB,oBAAoB,MAA+B;CACjE,MAAM,EAAE,YAAY,kBAAkB;CAEtC,MAAM,aAAa,cAAc;AACjC,YAAW,OAAO,YAAY,iBAAiB,oBAAoB;AAEnE,QAAO,CACL;EACE,SAAS,qBAAqB;GAAE;GAAY;GAAY,CAAC;EACzD,QAAQ;EACR,MAAM;EACP,CACF"}
1
+ {"version":3,"file":"file.mjs","names":["magicError: UseMagicErrorReturn"],"sources":["../../src/utils/file.ts"],"sourcesContent":["import { fileTypeFromBuffer } from 'file-type'\nimport { parse } from 'pathe'\n\nimport { getFileExistsHandler } from '../endpoints/fileExistsHandler'\n\nimport { useMagicError, type UseMagicErrorReturn } from '@maas/error-handler'\nimport { MediaCloudErrors } from '../types/errors'\n\nimport type { S3Store } from '../tus/stores/s3/s3Store'\nimport type { MediaCloudPluginOptions, MimeType } from '../types'\n\nconst magicError: UseMagicErrorReturn = useMagicError({\n prefix: 'PLUGIN-MEDIA-CLOUD',\n})\n\nconst { logError, throwError } = magicError\n\nconst MUX_SUPPORTED_VIDEO_FORMATS = new Set([\n 'application/mxf',\n 'video/3gpp',\n 'video/3gpp2',\n 'video/mp2t',\n 'video/mp4',\n 'video/mpeg',\n 'video/quicktime',\n 'video/webm',\n 'video/x-f4v',\n 'video/x-flv',\n 'video/x-matroska',\n 'video/x-ms-asf',\n 'video/x-ms-wmv',\n 'video/x-msvideo',\n 'video/x-mxf',\n])\n\n/**\n * Checks if a file is a video file supported by Mux\n * @param file - The file to check\n * @returns Promise that resolves to true if the file is a supported video format, false otherwise\n */\nexport async function isVideo(file: File): Promise<boolean> {\n try {\n const buffer = new Uint8Array(await file.arrayBuffer())\n const fileType = await fileTypeFromBuffer(buffer)\n\n return fileType?.mime\n ? MUX_SUPPORTED_VIDEO_FORMATS.has(fileType.mime)\n : false\n } catch {\n return false\n }\n}\n\nconst allowedMimeTypes = new Set<MimeType>([\n 'application/mxf',\n 'video/3gpp',\n 'video/3gpp2',\n 'video/mp2t',\n 'video/mp4',\n 'video/mpeg',\n 'video/quicktime',\n 'video/webm',\n 'video/x-f4v',\n 'video/x-flv',\n 'video/x-matroska',\n 'video/x-ms-asf',\n 'video/x-ms-wmv',\n 'video/x-msvideo',\n 'video/x-mxf',\n 'image/apng',\n 'image/avif',\n 'image/gif',\n 'image/jpeg',\n 'image/png',\n 'image/svg+xml',\n 'image/webp',\n])\n\n/**\n * Check the mime type against allowed mime types\n * @param mimeType - The file to check\n */\nfunction validateMimeType(mimeType: string) {\n if (!allowedMimeTypes.has(mimeType as MimeType)) {\n throwError(MediaCloudErrors.FILE_TYPE_UNSUPPORTED_ERROR)\n }\n}\n\n/**\n * Gets the MIME type of a file using file-type library\n * @param file - The file to check\n * @returns Promise that resolves to the MIME type of the file or undefined if it cannot be determined\n */\nexport async function getMimeType(file: File): Promise<MimeType | undefined> {\n try {\n const buffer = new Uint8Array(await file.arrayBuffer())\n const fileType = await fileTypeFromBuffer(buffer)\n\n if (!fileType?.mime) {\n logError(MediaCloudErrors.FILE_TYPE_ERROR.message)\n return undefined\n }\n\n validateMimeType(fileType.mime)\n return fileType.mime as MimeType\n } catch (_error) {\n logError(MediaCloudErrors.FILE_TYPE_ERROR.message)\n return undefined\n }\n}\n\n/**\n * Generates a unique filename by appending a random suffix if needed\n * @param originalFilename - The original filename\n * @returns A unique filename with a random suffix appended before the extension\n */\nexport function generateUniqueFilename(originalFilename: string): string {\n const timestamp = Date.now().toString(36)\n // Parse name and extension\n const { name, ext } = parse(originalFilename)\n\n return `${name}-${timestamp}${ext}`\n}\n\n/**\n * Sanitizes a filename by removing/replacing invalid characters and handling edge cases\n * Converts all non-alphanumeric characters (except dots for extensions) to underscores\n * @param filename - The filename to sanitize\n * @returns A sanitized filename safe for all operating systems\n * @throws {TypeError} When filename is not a string\n */\nexport function sanitizeFilename(filename: string): string {\n try {\n const parsed = parse(filename)\n const sanitized = parsed.name\n .replace(/[^a-zA-Z0-9_.-]/g, '_')\n .replace(/_{2,}/g, '_')\n .replace(/^_|_$/g, '')\n return `${sanitized}${parsed.ext}`\n } catch (_error) {\n logError(MediaCloudErrors.FILENAME_SANITIZE_ERROR.message)\n return filename\n }\n}\n\ninterface CreateFileEndpointsArgs {\n getS3Store: () => S3Store\n pluginOptions: MediaCloudPluginOptions\n}\n\nexport function createFileEndpoints(args: CreateFileEndpointsArgs) {\n const { getS3Store, pluginOptions } = args\n\n const collection = pluginOptions.collection\n magicError.assert(collection, MediaCloudErrors.COLLECTION_REQUIRED)\n\n return [\n {\n handler: getFileExistsHandler({ getS3Store, collection }),\n method: 'get' as const,\n path: '/uploads/:filename/exists',\n },\n ]\n}\n"],"mappings":";;;;;;;AAWA,MAAMA,aAAkC,cAAc,EACpD,QAAQ,sBACT,CAAC;AAEF,MAAM,EAAE,UAAU,eAAe;AAEjC,MAAM,8BAA8B,IAAI,IAAI;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;AAOF,eAAsB,QAAQ,MAA8B;AAC1D,KAAI;EAEF,MAAM,WAAW,MAAM,mBADR,IAAI,WAAW,MAAM,KAAK,aAAa,CAAC,CACN;AAEjD,SAAO,UAAU,OACb,4BAA4B,IAAI,SAAS,KAAK,GAC9C;SACE;AACN,SAAO;;;AAIX,MAAM,mBAAmB,IAAI,IAAc;CACzC;CACA;CACA;CACA;CACA;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3
+ "version": "0.0.39",
4
4
  "type": "module",
5
5
  "contributors": [
6
6
  {
@@ -38,6 +38,7 @@
38
38
  "@fastify/deepmerge": "3.1.0",
39
39
  "@mux/mux-node": "^12.8.1",
40
40
  "@mux/upchunk": "^3.5.0",
41
+ "@smithy/node-http-handler": "^4.4.10",
41
42
  "@tus/server": "^2.3.0",
42
43
  "@tus/utils": "^0.6.0",
43
44
  "defu": "^6.1.4",
@@ -45,6 +46,7 @@
45
46
  "image-size": "^2.0.2",
46
47
  "mitt": "^3.0.1",
47
48
  "multistream": "^4.1.0",
49
+ "p-queue": "^9.1.0",
48
50
  "pathe": "^2.0.3",
49
51
  "tus-js-client": "^4.3.1"
50
52
  },
@@ -70,9 +72,9 @@
70
72
  "@babel/preset-react": "^7.28.5",
71
73
  "@babel/preset-typescript": "^7.28.5",
72
74
  "@mux/mux-player-react": "^3.9.2",
73
- "@payloadcms/plugin-cloud-storage": "3.75.0",
74
- "@payloadcms/translations": "3.75.0",
75
- "@payloadcms/ui": "3.75.0",
75
+ "@payloadcms/plugin-cloud-storage": "3.77.0",
76
+ "@payloadcms/translations": "3.77.0",
77
+ "@payloadcms/ui": "3.77.0",
76
78
  "@rollup/plugin-babel": "^6.1.0",
77
79
  "@types/multistream": "^4.1.3",
78
80
  "@types/node": "^22.19.1",
@@ -81,7 +83,7 @@
81
83
  "babel-plugin-react-compiler": "^1.0.0",
82
84
  "glob": "^13.0.0",
83
85
  "next": "15.4.8",
84
- "payload": "3.75.0",
86
+ "payload": "3.77.0",
85
87
  "react": "19.2.1",
86
88
  "react-dom": "19.2.1",
87
89
  "tsdown": "^0.16.8",