@maas/payload-plugin-media-cloud 0.0.9 → 0.0.11
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.
- package/dist/adapter/{handleDelete.d.ts → handleDelete.d.mts} +2 -2
- package/dist/adapter/{handleDelete.js → handleDelete.mjs} +32 -25
- package/dist/adapter/handleDelete.mjs.map +1 -0
- package/dist/adapter/{handleUpload.d.ts → handleUpload.d.mts} +1 -1
- package/dist/adapter/{handleUpload.js → handleUpload.mjs} +2 -2
- package/dist/adapter/handleUpload.mjs.map +1 -0
- package/dist/adapter/{staticHandler.d.ts → staticHandler.d.mts} +2 -2
- package/dist/adapter/{staticHandler.js → staticHandler.mjs} +1 -1
- package/dist/adapter/staticHandler.mjs.map +1 -0
- package/dist/adapter/{storageAdapter.d.ts → storageAdapter.d.mts} +3 -3
- package/dist/adapter/{storageAdapter.js → storageAdapter.mjs} +4 -4
- package/dist/adapter/storageAdapter.mjs.map +1 -0
- package/dist/collections/{mediaCollection.d.ts → mediaCollection.d.mts} +3 -2
- package/dist/collections/{mediaCollection.js → mediaCollection.mjs} +29 -8
- package/dist/collections/mediaCollection.mjs.map +1 -0
- package/dist/components/index.d.mts +7 -0
- package/dist/components/index.mjs +5 -0
- package/dist/components/mux-preview/index.d.mts +2 -0
- package/dist/components/mux-preview/index.mjs +3 -0
- package/dist/components/mux-preview/{mux-preview.d.ts → mux-preview.d.mts} +1 -1
- package/dist/components/mux-preview/{mux-preview.js → mux-preview.mjs} +2 -11
- package/dist/components/mux-preview/mux-preview.mjs.map +1 -0
- package/dist/components/upload-handler/index.d.mts +2 -0
- package/dist/components/upload-handler/index.mjs +3 -0
- package/dist/components/upload-handler/{upload-handler.d.ts → upload-handler.d.mts} +1 -1
- package/dist/components/upload-handler/{upload-handler.js → upload-handler.mjs} +35 -39
- package/dist/components/upload-handler/upload-handler.mjs.map +1 -0
- package/dist/components/upload-manager/index.d.mts +2 -0
- package/dist/components/upload-manager/index.mjs +3 -0
- package/dist/components/upload-manager/{upload-manager.d.ts → upload-manager.d.mts} +5 -15
- package/dist/components/upload-manager/upload-manager.mjs +273 -0
- package/dist/components/upload-manager/upload-manager.mjs.map +1 -0
- package/dist/endpoints/{muxAssetHandler.d.ts → muxAssetHandler.d.mts} +2 -2
- package/dist/endpoints/{muxAssetHandler.js → muxAssetHandler.mjs} +16 -13
- package/dist/endpoints/muxAssetHandler.mjs.map +1 -0
- package/dist/endpoints/{muxCreateUploadHandler.d.ts → muxCreateUploadHandler.d.mts} +3 -3
- package/dist/endpoints/{muxCreateUploadHandler.js → muxCreateUploadHandler.mjs} +4 -5
- package/dist/endpoints/muxCreateUploadHandler.mjs.map +1 -0
- package/dist/endpoints/{muxWebhookHandler.d.ts → muxWebhookHandler.d.mts} +2 -2
- package/dist/endpoints/muxWebhookHandler.mjs +71 -0
- package/dist/endpoints/muxWebhookHandler.mjs.map +1 -0
- package/dist/endpoints/tusPostProcessorHandler.d.mts +11 -0
- package/dist/endpoints/tusPostProcessorHandler.mjs +46 -0
- package/dist/endpoints/tusPostProcessorHandler.mjs.map +1 -0
- package/dist/error-handler/dist/{index.js → index.mjs} +4 -8
- package/dist/error-handler/dist/index.mjs.map +1 -0
- package/dist/hooks/useErrorHandler.d.mts +183 -0
- package/dist/hooks/{useErrorHandler.js → useErrorHandler.mjs} +3 -3
- package/dist/hooks/useErrorHandler.mjs.map +1 -0
- package/dist/hooks/useMediaCloudEmitter.d.mts +26 -0
- package/dist/hooks/{useEmitter.js → useMediaCloudEmitter.mjs} +4 -4
- package/dist/hooks/useMediaCloudEmitter.mjs.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +3 -0
- package/dist/{plugin.d.ts → plugin.d.mts} +2 -2
- package/dist/plugin.mjs +98 -0
- package/dist/plugin.mjs.map +1 -0
- package/dist/tus/stores/s3/{expiration-manager.d.ts → expiration-manager.d.mts} +1 -1
- package/dist/tus/stores/s3/{expiration-manager.js → expiration-manager.mjs} +1 -1
- package/dist/tus/stores/s3/expiration-manager.mjs.map +1 -0
- package/dist/tus/stores/s3/{file-operations.d.ts → file-operations.d.mts} +1 -1
- package/dist/tus/stores/s3/{file-operations.js → file-operations.mjs} +4 -5
- package/dist/tus/stores/s3/file-operations.mjs.map +1 -0
- package/dist/tus/stores/s3/index.d.mts +15 -0
- package/dist/tus/stores/s3/index.mjs +30 -0
- package/dist/tus/stores/s3/index.mjs.map +1 -0
- package/dist/tus/stores/s3/{metadata-manager.d.ts → metadata-manager.d.mts} +2 -2
- package/dist/tus/stores/s3/{metadata-manager.js → metadata-manager.mjs} +3 -3
- package/dist/tus/stores/s3/metadata-manager.mjs.map +1 -0
- package/dist/tus/stores/s3/{parts-manager.d.ts → parts-manager.d.mts} +5 -5
- package/dist/tus/stores/s3/{parts-manager.js → parts-manager.mjs} +11 -15
- package/dist/tus/stores/s3/parts-manager.mjs.map +1 -0
- package/dist/tus/stores/s3/{s3-store.d.ts → s3-store.d.mts} +7 -7
- package/dist/tus/stores/s3/{s3-store.js → s3-store.mjs} +19 -30
- package/dist/tus/stores/s3/s3-store.mjs.map +1 -0
- package/dist/tus/stores/s3/{semaphore.d.ts → semaphore.d.mts} +1 -1
- package/dist/tus/stores/s3/{semaphore.js → semaphore.mjs} +2 -3
- package/dist/tus/stores/s3/semaphore.mjs.map +1 -0
- package/dist/types/errors.d.mts +146 -0
- package/dist/types/{errors.js → errors.mjs} +19 -3
- package/dist/types/errors.mjs.map +1 -0
- package/dist/types/{index.d.ts → index.d.mts} +31 -3
- package/dist/types/index.mjs +1 -0
- package/dist/utils/{file.d.ts → file.d.mts} +1 -1
- package/dist/utils/{file.js → file.mjs} +7 -11
- package/dist/utils/file.mjs.map +1 -0
- package/dist/utils/mux.d.mts +39 -0
- package/dist/utils/mux.mjs +56 -0
- package/dist/utils/mux.mjs.map +1 -0
- package/dist/utils/tus.d.mts +56 -0
- package/dist/utils/tus.mjs +85 -0
- package/dist/utils/tus.mjs.map +1 -0
- package/package.json +25 -16
- package/dist/adapter/handleDelete.js.map +0 -1
- package/dist/adapter/handleUpload.js.map +0 -1
- package/dist/adapter/staticHandler.js.map +0 -1
- package/dist/adapter/storageAdapter.js.map +0 -1
- package/dist/collections/mediaCollection.js.map +0 -1
- package/dist/components/index.d.ts +0 -4
- package/dist/components/index.js +0 -5
- package/dist/components/mux-preview/index.d.ts +0 -2
- package/dist/components/mux-preview/index.js +0 -3
- package/dist/components/mux-preview/mux-preview.js.map +0 -1
- package/dist/components/upload-handler/index.d.ts +0 -2
- package/dist/components/upload-handler/index.js +0 -3
- package/dist/components/upload-handler/upload-handler.js.map +0 -1
- package/dist/components/upload-manager/index.d.ts +0 -2
- package/dist/components/upload-manager/index.js +0 -3
- package/dist/components/upload-manager/upload-manager.js +0 -315
- package/dist/components/upload-manager/upload-manager.js.map +0 -1
- package/dist/endpoints/muxAssetHandler.js.map +0 -1
- package/dist/endpoints/muxCreateUploadHandler.js.map +0 -1
- package/dist/endpoints/muxWebhookHandler.js +0 -49
- package/dist/endpoints/muxWebhookHandler.js.map +0 -1
- package/dist/error-handler/dist/index.js.map +0 -1
- package/dist/hooks/useEmitter.d.ts +0 -47
- package/dist/hooks/useEmitter.js.map +0 -1
- package/dist/hooks/useErrorHandler.d.ts +0 -12
- package/dist/hooks/useErrorHandler.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/plugin.js +0 -244
- package/dist/plugin.js.map +0 -1
- package/dist/tus/stores/s3/expiration-manager.js.map +0 -1
- package/dist/tus/stores/s3/file-operations.js.map +0 -1
- package/dist/tus/stores/s3/metadata-manager.js.map +0 -1
- package/dist/tus/stores/s3/parts-manager.js.map +0 -1
- package/dist/tus/stores/s3/s3-store.js.map +0 -1
- package/dist/tus/stores/s3/semaphore.js.map +0 -1
- package/dist/types/errors.d.ts +0 -8
- package/dist/types/errors.js.map +0 -1
- package/dist/types/index.js +0 -0
- package/dist/utils/file.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S3Store } from "../tus/stores/s3/s3-store.
|
|
1
|
+
import { S3Store } from "../tus/stores/s3/s3-store.mjs";
|
|
2
2
|
import { Mux as Mux$1 } from "@mux/mux-node";
|
|
3
3
|
import { HandleDelete } from "@payloadcms/plugin-cloud-storage/types";
|
|
4
4
|
|
|
@@ -17,4 +17,4 @@ interface HandleDeleteArgs {
|
|
|
17
17
|
declare function getHandleDelete(args: HandleDeleteArgs): HandleDelete;
|
|
18
18
|
//#endregion
|
|
19
19
|
export { getHandleDelete };
|
|
20
|
-
//# sourceMappingURL=handleDelete.d.
|
|
20
|
+
//# sourceMappingURL=handleDelete.d.mts.map
|
|
@@ -1,31 +1,9 @@
|
|
|
1
|
-
import { MediaCloudErrors } from "../types/errors.
|
|
2
|
-
import { useErrorHandler } from "../hooks/useErrorHandler.
|
|
1
|
+
import { MediaCloudErrors } from "../types/errors.mjs";
|
|
2
|
+
import { useErrorHandler } from "../hooks/useErrorHandler.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapter/handleDelete.ts
|
|
5
5
|
const { logError } = useErrorHandler();
|
|
6
6
|
/**
|
|
7
|
-
* Creates a handle delete function for processing file deletions from both Mux and S3 storage
|
|
8
|
-
* @param args - The arguments for creating the delete handler
|
|
9
|
-
* @param args.s3Store - The S3Store instance for S3 file operations
|
|
10
|
-
* @param args.getMuxClient - Function that returns a Mux client instance
|
|
11
|
-
* @returns A HandleDelete function that processes deletion requests based on storage type
|
|
12
|
-
*/
|
|
13
|
-
function getHandleDelete(args) {
|
|
14
|
-
const { s3Store, getMuxClient } = args;
|
|
15
|
-
return async ({ doc, req }) => {
|
|
16
|
-
if (req?.method !== "DELETE" || !doc) return;
|
|
17
|
-
const media = doc;
|
|
18
|
-
if (media?.storage === "mux" && media.mux?.uploadId) await deleteMuxAsset({
|
|
19
|
-
getMuxClient,
|
|
20
|
-
uploadId: media.mux.uploadId
|
|
21
|
-
});
|
|
22
|
-
else if (media.filename) await deleteS3File({
|
|
23
|
-
s3Store,
|
|
24
|
-
filename: media.filename
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
7
|
* Deletes a Mux asset by upload ID
|
|
30
8
|
* @param args - The arguments for deleting the Mux asset
|
|
31
9
|
* @param args.getMuxClient - Function that returns a Mux client instance
|
|
@@ -64,7 +42,36 @@ async function deleteS3File(args) {
|
|
|
64
42
|
logError(MediaCloudErrors.S3_DELETE_ERROR);
|
|
65
43
|
}
|
|
66
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a handle delete function for processing file deletions from both Mux and S3 storage
|
|
47
|
+
* @param args - The arguments for creating the delete handler
|
|
48
|
+
* @param args.s3Store - The S3Store instance for S3 file operations
|
|
49
|
+
* @param args.getMuxClient - Function that returns a Mux client instance
|
|
50
|
+
* @returns A HandleDelete function that processes deletion requests based on storage type
|
|
51
|
+
*/
|
|
52
|
+
function getHandleDelete(args) {
|
|
53
|
+
const { s3Store, getMuxClient } = args;
|
|
54
|
+
return async ({ doc, req }) => {
|
|
55
|
+
if (req?.method !== "DELETE" || !doc) return;
|
|
56
|
+
const media = doc;
|
|
57
|
+
switch (media?.storage) {
|
|
58
|
+
case "mux":
|
|
59
|
+
if (media.mux?.uploadId) await deleteMuxAsset({
|
|
60
|
+
getMuxClient,
|
|
61
|
+
uploadId: media.mux.uploadId
|
|
62
|
+
});
|
|
63
|
+
break;
|
|
64
|
+
case "s3":
|
|
65
|
+
if (media.filename) await deleteS3File({
|
|
66
|
+
s3Store,
|
|
67
|
+
filename: media.filename
|
|
68
|
+
});
|
|
69
|
+
break;
|
|
70
|
+
default: logError(MediaCloudErrors.UNKNOWN_STORAGE_TYPE);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
67
74
|
|
|
68
75
|
//#endregion
|
|
69
76
|
export { getHandleDelete };
|
|
70
|
-
//# sourceMappingURL=handleDelete.
|
|
77
|
+
//# sourceMappingURL=handleDelete.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleDelete.mjs","names":[],"sources":["../../src/adapter/handleDelete.ts"],"sourcesContent":["import { useErrorHandler } from '../hooks/useErrorHandler'\nimport { MediaCloudErrors } from '../types/errors'\n\nimport type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\nimport type { Document } from 'payload'\nimport type { Mux } from '@mux/mux-node'\nimport type { S3Store } from '../tus/stores/s3/s3-store'\n\ninterface HandleDeleteArgs {\n s3Store: S3Store\n getMuxClient: () => Mux\n}\n\ninterface DeleteMuxAssetArgs {\n getMuxClient: () => Mux\n uploadId: string\n}\n\ninterface DeleteS3FileArgs {\n s3Store: S3Store\n filename: string\n}\n\nconst { logError } = useErrorHandler()\n\n/**\n * Deletes a Mux asset by upload ID\n * @param args - The arguments for deleting the Mux asset\n * @param args.getMuxClient - Function that returns a Mux client instance\n * @param args.uploadId - The upload ID of the Mux asset to delete\n * @returns Promise that resolves when the asset is deleted or rejects on error\n */\nasync function deleteMuxAsset(args: DeleteMuxAssetArgs): Promise<void> {\n const { getMuxClient, uploadId } = args\n\n try {\n const mux = getMuxClient()\n const assets = await mux.video.assets.list({ upload_id: uploadId })\n if (assets.data.length > 0) {\n const asset = assets.data[0]\n await mux.video.assets.delete(asset.id)\n }\n } catch (_error) {\n logError(MediaCloudErrors.MUX_ASSET_DELETE_ERROR)\n }\n}\n\n/**\n * Deletes a file from S3 storage including its metadata info file\n * @param args - The arguments for deleting the S3 file\n * @param args.s3Store - The S3Store instance for S3 operations\n * @param args.filename - The filename of the file to delete from S3\n * @returns Promise that resolves when the file is deleted or rejects on error\n */\nasync function deleteS3File(args: DeleteS3FileArgs): Promise<void> {\n const { s3Store, filename } = args\n\n try {\n const { client, bucket } = s3Store\n await client.deleteObjects({\n Bucket: bucket,\n Delete: {\n Objects: [{ Key: filename }, { Key: `${filename}.info` }],\n },\n })\n } catch (_error) {\n logError(MediaCloudErrors.S3_DELETE_ERROR)\n }\n}\n\n/**\n * Creates a handle delete function for processing file deletions from both Mux and S3 storage\n * @param args - The arguments for creating the delete handler\n * @param args.s3Store - The S3Store instance for S3 file operations\n * @param args.getMuxClient - Function that returns a Mux client instance\n * @returns A HandleDelete function that processes deletion requests based on storage type\n */\nexport function getHandleDelete(args: HandleDeleteArgs): HandleDelete {\n const { s3Store, getMuxClient } = args\n return async ({ doc, req }) => {\n if (req?.method !== 'DELETE' || !doc) {\n return\n }\n\n const media = doc as Document\n\n switch (media?.storage) {\n case 'mux':\n if (media.mux?.uploadId) {\n await deleteMuxAsset({ getMuxClient, uploadId: media.mux.uploadId })\n }\n break\n case 's3':\n if (media.filename) {\n await deleteS3File({ s3Store, filename: media.filename })\n }\n break\n default:\n logError(MediaCloudErrors.UNKNOWN_STORAGE_TYPE)\n }\n }\n}\n"],"mappings":";;;;AAuBA,MAAM,EAAE,aAAa,iBAAiB;;;;;;;;AAStC,eAAe,eAAe,MAAyC;CACrE,MAAM,EAAE,cAAc,aAAa;AAEnC,KAAI;EACF,MAAM,MAAM,cAAc;EAC1B,MAAM,SAAS,MAAM,IAAI,MAAM,OAAO,KAAK,EAAE,WAAW,UAAU,CAAC;AACnE,MAAI,OAAO,KAAK,SAAS,GAAG;GAC1B,MAAM,QAAQ,OAAO,KAAK;AAC1B,SAAM,IAAI,MAAM,OAAO,OAAO,MAAM,GAAG;;UAElC,QAAQ;AACf,WAAS,iBAAiB,uBAAuB;;;;;;;;;;AAWrD,eAAe,aAAa,MAAuC;CACjE,MAAM,EAAE,SAAS,aAAa;AAE9B,KAAI;EACF,MAAM,EAAE,QAAQ,WAAW;AAC3B,QAAM,OAAO,cAAc;GACzB,QAAQ;GACR,QAAQ,EACN,SAAS,CAAC,EAAE,KAAK,UAAU,EAAE,EAAE,KAAK,GAAG,SAAS,QAAQ,CAAC,EAC1D;GACF,CAAC;UACK,QAAQ;AACf,WAAS,iBAAiB,gBAAgB;;;;;;;;;;AAW9C,SAAgB,gBAAgB,MAAsC;CACpE,MAAM,EAAE,SAAS,iBAAiB;AAClC,QAAO,OAAO,EAAE,KAAK,UAAU;AAC7B,MAAI,KAAK,WAAW,YAAY,CAAC,IAC/B;EAGF,MAAM,QAAQ;AAEd,UAAQ,OAAO,SAAf;GACE,KAAK;AACH,QAAI,MAAM,KAAK,SACb,OAAM,eAAe;KAAE;KAAc,UAAU,MAAM,IAAI;KAAU,CAAC;AAEtE;GACF,KAAK;AACH,QAAI,MAAM,SACR,OAAM,aAAa;KAAE;KAAS,UAAU,MAAM;KAAU,CAAC;AAE3D;GACF,QACE,UAAS,iBAAiB,qBAAqB"}
|
|
@@ -12,7 +12,7 @@ function getHandleUpload() {
|
|
|
12
12
|
case "mux":
|
|
13
13
|
data.storage = "mux";
|
|
14
14
|
data.mux = {
|
|
15
|
-
uploadId: ctx.uploadId
|
|
15
|
+
uploadId: ctx.uploadId ?? "",
|
|
16
16
|
status: "preparing"
|
|
17
17
|
};
|
|
18
18
|
break;
|
|
@@ -26,4 +26,4 @@ function getHandleUpload() {
|
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
28
|
export { getHandleUpload };
|
|
29
|
-
//# sourceMappingURL=handleUpload.
|
|
29
|
+
//# sourceMappingURL=handleUpload.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleUpload.mjs","names":[],"sources":["../../src/adapter/handleUpload.ts"],"sourcesContent":["import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\n\ninterface ClientUploadContext {\n storage: 'mux' | 's3'\n uploadId?: string\n mimeType?: string\n}\n\n/**\n * Creates a handle upload function for processing file uploads to both Mux and S3 storage\n * @returns A HandleUpload function that processes client upload context and updates document data\n */\nexport function getHandleUpload(): HandleUpload {\n return async function ({ clientUploadContext, data }) {\n if (!clientUploadContext) {\n return data\n }\n\n const ctx = clientUploadContext as ClientUploadContext\n data.mimeType = ctx.mimeType\n\n switch (ctx.storage) {\n case 'mux':\n data.storage = 'mux'\n data.mux = {\n uploadId: ctx.uploadId ?? '',\n status: 'preparing',\n }\n break\n default:\n data.storage = 's3'\n break\n }\n\n return data\n }\n}\n"],"mappings":";;;;;AAYA,SAAgB,kBAAgC;AAC9C,QAAO,eAAgB,EAAE,qBAAqB,QAAQ;AACpD,MAAI,CAAC,oBACH,QAAO;EAGT,MAAM,MAAM;AACZ,OAAK,WAAW,IAAI;AAEpB,UAAQ,IAAI,SAAZ;GACE,KAAK;AACH,SAAK,UAAU;AACf,SAAK,MAAM;KACT,UAAU,IAAI,YAAY;KAC1B,QAAQ;KACT;AACD;GACF;AACE,SAAK,UAAU;AACf;;AAGJ,SAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S3Store } from "../tus/stores/s3/s3-store.
|
|
1
|
+
import { S3Store } from "../tus/stores/s3/s3-store.mjs";
|
|
2
2
|
import { StaticHandler } from "@payloadcms/plugin-cloud-storage/types";
|
|
3
3
|
|
|
4
4
|
//#region src/adapter/staticHandler.d.ts
|
|
@@ -14,4 +14,4 @@ interface StaticHandlerArgs {
|
|
|
14
14
|
declare function getStaticHandler(args: StaticHandlerArgs): StaticHandler;
|
|
15
15
|
//#endregion
|
|
16
16
|
export { getStaticHandler };
|
|
17
|
-
//# sourceMappingURL=staticHandler.d.
|
|
17
|
+
//# sourceMappingURL=staticHandler.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staticHandler.mjs","names":["stream"],"sources":["../../src/adapter/staticHandler.ts"],"sourcesContent":["import { Readable } from 'node:stream'\nimport type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { Document } from 'payload'\nimport type { S3Store } from '../tus/stores/s3/s3-store'\n\ninterface StaticHandlerArgs {\n s3Store: S3Store\n}\n\ninterface ServeS3FileArgs {\n s3Store: S3Store\n doc: Document\n}\n\ninterface CreateEmptyResponseArgs {\n mimeType?: string\n}\n\n/**\n * Creates a static handler that serves files from S3 or returns empty responses for Mux assets\n * @param args - The arguments for creating the static handler\n * @param args.s3Store - The S3Store instance used for file operations\n * @returns A StaticHandler function that serves files or empty responses based on storage type\n */\nexport function getStaticHandler(args: StaticHandlerArgs): StaticHandler {\n const { s3Store } = args\n return async (req, { params }) => {\n const { payload } = req\n const filename = params.filename\n\n const { docs } = await payload.find({\n collection: 'media',\n where: { filename: { equals: filename } },\n })\n\n const doc = docs[0] as Document\n\n if (!doc) {\n return createEmptyResponse()\n }\n\n if (doc.storage === 'mux') {\n return createEmptyResponse({ mimeType: doc.mimeType })\n }\n\n return await serveS3File({ s3Store, doc })\n }\n}\n\n/**\n * Creates an empty response with appropriate headers\n * @param args - Optional arguments for the empty response\n * @param args.mimeType - The MIME type to set in the Content-Type header\n * @returns A Response object with empty content and appropriate headers\n */\nfunction createEmptyResponse(args?: CreateEmptyResponseArgs): Response {\n const { mimeType = 'application/octet-stream' } = args ?? {}\n return new Response(new Uint8Array(0), {\n status: 200,\n headers: {\n 'Content-Type': mimeType,\n 'Content-Length': '0',\n },\n })\n}\n\n/**\n * Serves a file from S3 storage\n * @param args - The arguments for serving the S3 file\n * @param args.s3Store - The S3Store instance to read the file from\n * @param args.doc - The document containing file metadata\n * @returns A Promise that resolves to a Response object containing the file stream or empty response on error\n */\nasync function serveS3File({\n s3Store,\n doc,\n}: ServeS3FileArgs): Promise<Response> {\n try {\n const stream = await s3Store.read(doc.filename)\n\n if (stream) {\n const webStream = Readable.toWeb(stream) as ReadableStream<Uint8Array>\n return new Response(webStream)\n }\n } catch (_error) {\n // File not found or other error, fall back to empty response\n }\n\n return createEmptyResponse({})\n}\n"],"mappings":";;;;;;;;;AAwBA,SAAgB,iBAAiB,MAAwC;CACvE,MAAM,EAAE,YAAY;AACpB,QAAO,OAAO,KAAK,EAAE,aAAa;EAChC,MAAM,EAAE,YAAY;EACpB,MAAM,WAAW,OAAO;EAExB,MAAM,EAAE,SAAS,MAAM,QAAQ,KAAK;GAClC,YAAY;GACZ,OAAO,EAAE,UAAU,EAAE,QAAQ,UAAU,EAAE;GAC1C,CAAC;EAEF,MAAM,MAAM,KAAK;AAEjB,MAAI,CAAC,IACH,QAAO,qBAAqB;AAG9B,MAAI,IAAI,YAAY,MAClB,QAAO,oBAAoB,EAAE,UAAU,IAAI,UAAU,CAAC;AAGxD,SAAO,MAAM,YAAY;GAAE;GAAS;GAAK,CAAC;;;;;;;;;AAU9C,SAAS,oBAAoB,MAA0C;CACrE,MAAM,EAAE,WAAW,+BAA+B,QAAQ,EAAE;AAC5D,QAAO,IAAI,SAAS,IAAI,WAAW,EAAE,EAAE;EACrC,QAAQ;EACR,SAAS;GACP,gBAAgB;GAChB,kBAAkB;GACnB;EACF,CAAC;;;;;;;;;AAUJ,eAAe,YAAY,EACzB,SACA,OACqC;AACrC,KAAI;EACF,MAAMA,WAAS,MAAM,QAAQ,KAAK,IAAI,SAAS;AAE/C,MAAIA,UAAQ;GACV,MAAM,YAAY,SAAS,MAAMA,SAAO;AACxC,UAAO,IAAI,SAAS,UAAU;;UAEzB,QAAQ;AAIjB,QAAO,oBAAoB,EAAE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MediaCloudPluginOptions } from "../types/index.
|
|
2
|
-
import { S3Store } from "../tus/stores/s3/s3-store.
|
|
1
|
+
import { MediaCloudPluginOptions } from "../types/index.mjs";
|
|
2
|
+
import { S3Store } from "../tus/stores/s3/s3-store.mjs";
|
|
3
3
|
import { Mux as Mux$1 } from "@mux/mux-node";
|
|
4
4
|
import { Adapter } from "@payloadcms/plugin-cloud-storage/types";
|
|
5
5
|
|
|
@@ -20,4 +20,4 @@ interface StorageAdapterArgs {
|
|
|
20
20
|
declare function getStorageAdapter(args: StorageAdapterArgs): Adapter;
|
|
21
21
|
//#endregion
|
|
22
22
|
export { getStorageAdapter };
|
|
23
|
-
//# sourceMappingURL=storageAdapter.d.
|
|
23
|
+
//# sourceMappingURL=storageAdapter.d.mts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getHandleUpload } from "./handleUpload.
|
|
2
|
-
import { getHandleDelete } from "./handleDelete.
|
|
3
|
-
import { getStaticHandler } from "./staticHandler.
|
|
1
|
+
import { getHandleUpload } from "./handleUpload.mjs";
|
|
2
|
+
import { getHandleDelete } from "./handleDelete.mjs";
|
|
3
|
+
import { getStaticHandler } from "./staticHandler.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/adapter/storageAdapter.ts
|
|
6
6
|
/**
|
|
@@ -27,4 +27,4 @@ function getStorageAdapter(args) {
|
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
29
|
export { getStorageAdapter };
|
|
30
|
-
//# sourceMappingURL=storageAdapter.
|
|
30
|
+
//# sourceMappingURL=storageAdapter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storageAdapter.mjs","names":[],"sources":["../../src/adapter/storageAdapter.ts"],"sourcesContent":["import { getHandleUpload } from './handleUpload'\nimport { getHandleDelete } from './handleDelete'\nimport { getStaticHandler } from './staticHandler'\n\nimport type {\n Adapter,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Mux } from '@mux/mux-node'\nimport type { MediaCloudPluginOptions } from '../types'\nimport type { S3Store } from '../tus/stores/s3/s3-store'\n\ninterface StorageAdapterArgs {\n pluginOptions: MediaCloudPluginOptions\n s3Store: S3Store\n getMuxClient: () => Mux\n}\n\n/**\n * Creates the storage adapter for media cloud plugin\n * @param args - The arguments for creating the storage adapter\n * @param args.pluginOptions - The media cloud plugin options\n * @param args.s3Store - The S3Store instance for file operations\n * @param args.getMuxClient - Function that returns a Mux client instance\n * @returns An Adapter function that returns a GeneratedAdapter configuration\n */\nexport function getStorageAdapter(args: StorageAdapterArgs): Adapter {\n const { s3Store, getMuxClient } = args\n\n return (): GeneratedAdapter => ({\n name: 'media-cloud',\n clientUploads: true,\n handleUpload: getHandleUpload(),\n handleDelete: getHandleDelete({ s3Store, getMuxClient }),\n staticHandler: getStaticHandler({ s3Store }),\n })\n}\n"],"mappings":";;;;;;;;;;;;;AA0BA,SAAgB,kBAAkB,MAAmC;CACnE,MAAM,EAAE,SAAS,iBAAiB;AAElC,eAAgC;EAC9B,MAAM;EACN,eAAe;EACf,cAAc,iBAAiB;EAC/B,cAAc,gBAAgB;GAAE;GAAS;GAAc,CAAC;EACxD,eAAe,iBAAiB,EAAE,SAAS,CAAC;EAC7C"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { S3Store } from "../tus/stores/s3/s3-store.
|
|
1
|
+
import { S3Store } from "../tus/stores/s3/s3-store.mjs";
|
|
2
2
|
import { CollectionConfig } from "payload";
|
|
3
3
|
|
|
4
4
|
//#region src/collections/mediaCollection.d.ts
|
|
5
5
|
interface GetMediaCollectionArgs {
|
|
6
6
|
s3Store: S3Store;
|
|
7
|
+
baseCollection?: CollectionConfig;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* Creates a media collection configuration for Payload CMS
|
|
@@ -13,4 +14,4 @@ interface GetMediaCollectionArgs {
|
|
|
13
14
|
declare function getMediaCollection(args: GetMediaCollectionArgs): CollectionConfig;
|
|
14
15
|
//#endregion
|
|
15
16
|
export { getMediaCollection };
|
|
16
|
-
//# sourceMappingURL=mediaCollection.d.
|
|
17
|
+
//# sourceMappingURL=mediaCollection.d.mts.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { deepmerge as deepmerge$1 } from "@fastify/deepmerge";
|
|
2
|
+
|
|
1
3
|
//#region src/collections/mediaCollection.ts
|
|
2
4
|
/**
|
|
3
5
|
* Creates a media collection configuration for Payload CMS
|
|
@@ -5,8 +7,8 @@
|
|
|
5
7
|
* @returns A configured Payload collection for media files
|
|
6
8
|
*/
|
|
7
9
|
function getMediaCollection(args) {
|
|
8
|
-
const { s3Store } = args;
|
|
9
|
-
return {
|
|
10
|
+
const { s3Store, baseCollection = {} } = args;
|
|
11
|
+
return deepmerge$1({ all: true })(baseCollection, {
|
|
10
12
|
slug: "media",
|
|
11
13
|
access: {
|
|
12
14
|
read: () => true,
|
|
@@ -22,10 +24,7 @@ function getMediaCollection(args) {
|
|
|
22
24
|
hideRemoveFile: true,
|
|
23
25
|
adminThumbnail({ doc }) {
|
|
24
26
|
if (doc?.storage === "mux" && doc?.mux?.playbackId) return `https://image.mux.com/${doc.mux.playbackId}/thumbnail.jpg?width=200&height=200&fit_mode=pad`;
|
|
25
|
-
else if (doc?.storage === "s3") {
|
|
26
|
-
const url = s3Store.getUrl(doc.filename);
|
|
27
|
-
return `https://wsrv.nl/?url=${url}?width=200&height=200&default=1`;
|
|
28
|
-
}
|
|
27
|
+
else if (doc?.storage === "s3") return `https://wsrv.nl/?url=${s3Store.getUrl(doc.filename)}?width=200&height=200&default=1`;
|
|
29
28
|
return null;
|
|
30
29
|
}
|
|
31
30
|
},
|
|
@@ -45,6 +44,28 @@ function getMediaCollection(args) {
|
|
|
45
44
|
label: "Copyright",
|
|
46
45
|
type: "text"
|
|
47
46
|
},
|
|
47
|
+
{
|
|
48
|
+
type: "row",
|
|
49
|
+
fields: [{
|
|
50
|
+
name: "width",
|
|
51
|
+
label: "Width",
|
|
52
|
+
type: "text",
|
|
53
|
+
admin: {
|
|
54
|
+
readOnly: true,
|
|
55
|
+
hidden: false,
|
|
56
|
+
width: "50%"
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
name: "height",
|
|
60
|
+
label: "Height",
|
|
61
|
+
type: "number",
|
|
62
|
+
admin: {
|
|
63
|
+
readOnly: true,
|
|
64
|
+
hidden: false,
|
|
65
|
+
width: "50%"
|
|
66
|
+
}
|
|
67
|
+
}]
|
|
68
|
+
},
|
|
48
69
|
{
|
|
49
70
|
name: "storage",
|
|
50
71
|
label: "Storage",
|
|
@@ -136,9 +157,9 @@ function getMediaCollection(args) {
|
|
|
136
157
|
]
|
|
137
158
|
}
|
|
138
159
|
]
|
|
139
|
-
};
|
|
160
|
+
});
|
|
140
161
|
}
|
|
141
162
|
|
|
142
163
|
//#endregion
|
|
143
164
|
export { getMediaCollection };
|
|
144
|
-
//# sourceMappingURL=mediaCollection.
|
|
165
|
+
//# sourceMappingURL=mediaCollection.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaCollection.mjs","names":["deepmerge"],"sources":["../../src/collections/mediaCollection.ts"],"sourcesContent":["import { deepmerge } from '@fastify/deepmerge'\n\nimport type { CollectionConfig } from 'payload'\nimport type { Document } from 'payload'\nimport type { S3Store } from './../tus/stores/s3/s3-store'\n\ninterface GetMediaCollectionArgs {\n s3Store: S3Store\n baseCollection?: CollectionConfig\n}\n\n/**\n * Creates a media collection configuration for Payload CMS\n * @param args - Arguments including the S3Store instance\n * @returns A configured Payload collection for media files\n */\nexport function getMediaCollection(\n args: GetMediaCollectionArgs\n): CollectionConfig {\n const { s3Store, baseCollection = {} } = args\n\n const config: CollectionConfig = {\n slug: 'media',\n access: {\n read: () => true,\n delete: () => true,\n },\n admin: {\n group: 'Media Cloud',\n pagination: {\n defaultLimit: 50,\n },\n },\n upload: {\n crop: false,\n displayPreview: true,\n hideRemoveFile: true,\n adminThumbnail({ doc }: { doc: Document }) {\n if (doc?.storage === 'mux' && doc?.mux?.playbackId) {\n return `https://image.mux.com/${doc.mux.playbackId}/thumbnail.jpg?width=200&height=200&fit_mode=pad`\n } else if (doc?.storage === 's3') {\n // @TODO: Make configurable\n const url = s3Store.getUrl(doc.filename)\n return `https://wsrv.nl/?url=${url}?width=200&height=200&default=1`\n }\n return null\n },\n },\n fields: [\n {\n name: 'alt',\n label: 'Alternative Text',\n type: 'text',\n },\n {\n name: 'caption',\n label: 'Caption',\n type: 'text',\n },\n {\n name: 'copyright',\n label: 'Copyright',\n type: 'text',\n },\n {\n type: 'row',\n fields: [\n {\n name: 'width',\n label: 'Width',\n type: 'text',\n admin: {\n readOnly: true,\n hidden: false,\n width: '50%',\n },\n },\n {\n name: 'height',\n label: 'Height',\n type: 'number',\n admin: {\n readOnly: true,\n hidden: false,\n width: '50%',\n },\n },\n ],\n },\n {\n name: 'storage',\n label: 'Storage',\n type: 'select',\n options: [\n {\n label: 'Mux',\n value: 'mux',\n },\n {\n label: 'S3',\n value: 's3',\n },\n ],\n admin: {\n readOnly: true,\n },\n },\n {\n name: 'mux',\n label: 'Mux',\n type: 'group',\n admin: {\n disableListColumn: true,\n disableBulkEdit: true,\n disableListFilter: true,\n readOnly: true,\n condition: (data) => {\n return data.storage === 'mux'\n },\n },\n fields: [\n {\n name: 'preview',\n type: 'ui',\n admin: {\n condition: (data) => {\n return data.storage === 'mux'\n },\n disableListColumn: true,\n components: {\n Field: '@maas/payload-plugin-media-cloud/components#MuxPreview',\n },\n },\n },\n {\n name: 'status',\n label: 'Status',\n type: 'text',\n },\n {\n name: 'uploadId',\n label: 'Upload ID',\n type: 'text',\n },\n {\n name: 'assetId',\n label: 'Asset ID',\n type: 'text',\n },\n {\n name: 'playbackId',\n label: 'Playback ID',\n type: 'text',\n },\n {\n name: 'aspectRatio',\n label: 'Aspect Ratio',\n type: 'text',\n },\n {\n name: 'duration',\n label: 'Duration',\n type: 'number',\n },\n {\n name: 'tracks',\n label: 'Tracks',\n type: 'json',\n },\n {\n name: 'maxResolutionTier',\n label: 'Max Resolution Tier',\n type: 'text',\n },\n {\n name: 'videoQuality',\n label: 'Video Quality',\n type: 'text',\n },\n {\n name: 'staticRenditions',\n label: 'Static Renditions',\n type: 'json',\n },\n ],\n },\n ],\n }\n\n const mergedConfig = deepmerge({ all: true })(baseCollection, config)\n\n return mergedConfig\n}\n"],"mappings":";;;;;;;;AAgBA,SAAgB,mBACd,MACkB;CAClB,MAAM,EAAE,SAAS,iBAAiB,EAAE,KAAK;AA4KzC,QAFqBA,YAAU,EAAE,KAAK,MAAM,CAAC,CAAC,gBAxKb;EAC/B,MAAM;EACN,QAAQ;GACN,YAAY;GACZ,cAAc;GACf;EACD,OAAO;GACL,OAAO;GACP,YAAY,EACV,cAAc,IACf;GACF;EACD,QAAQ;GACN,MAAM;GACN,gBAAgB;GAChB,gBAAgB;GAChB,eAAe,EAAE,OAA0B;AACzC,QAAI,KAAK,YAAY,SAAS,KAAK,KAAK,WACtC,QAAO,yBAAyB,IAAI,IAAI,WAAW;aAC1C,KAAK,YAAY,KAG1B,QAAO,wBADK,QAAQ,OAAO,IAAI,SAAS,CACL;AAErC,WAAO;;GAEV;EACD,QAAQ;GACN;IACE,MAAM;IACN,OAAO;IACP,MAAM;IACP;GACD;IACE,MAAM;IACN,OAAO;IACP,MAAM;IACP;GACD;IACE,MAAM;IACN,OAAO;IACP,MAAM;IACP;GACD;IACE,MAAM;IACN,QAAQ,CACN;KACE,MAAM;KACN,OAAO;KACP,MAAM;KACN,OAAO;MACL,UAAU;MACV,QAAQ;MACR,OAAO;MACR;KACF,EACD;KACE,MAAM;KACN,OAAO;KACP,MAAM;KACN,OAAO;MACL,UAAU;MACV,QAAQ;MACR,OAAO;MACR;KACF,CACF;IACF;GACD;IACE,MAAM;IACN,OAAO;IACP,MAAM;IACN,SAAS,CACP;KACE,OAAO;KACP,OAAO;KACR,EACD;KACE,OAAO;KACP,OAAO;KACR,CACF;IACD,OAAO,EACL,UAAU,MACX;IACF;GACD;IACE,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;KACL,mBAAmB;KACnB,iBAAiB;KACjB,mBAAmB;KACnB,UAAU;KACV,YAAY,SAAS;AACnB,aAAO,KAAK,YAAY;;KAE3B;IACD,QAAQ;KACN;MACE,MAAM;MACN,MAAM;MACN,OAAO;OACL,YAAY,SAAS;AACnB,eAAO,KAAK,YAAY;;OAE1B,mBAAmB;OACnB,YAAY,EACV,OAAO,0DACR;OACF;MACF;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;MACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;MACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;MACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;MACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;MACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;MACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;MACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;MACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;MACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;MACP;KACF;IACF;GACF;EACF,CAEoE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MuxPreview } from "./mux-preview/mux-preview.mjs";
|
|
2
|
+
import "./mux-preview/index.mjs";
|
|
3
|
+
import { UploadHandler } from "./upload-handler/upload-handler.mjs";
|
|
4
|
+
import "./upload-handler/index.mjs";
|
|
5
|
+
import { UploadManagerProvider, useUploadManagerContext } from "./upload-manager/upload-manager.mjs";
|
|
6
|
+
import "./upload-manager/index.mjs";
|
|
7
|
+
export { MuxPreview, UploadHandler, UploadManagerProvider, useUploadManagerContext };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MuxPreview } from "./mux-preview/mux-preview.mjs";
|
|
2
|
+
import { UploadHandler } from "./upload-handler/upload-handler.mjs";
|
|
3
|
+
import { UploadManagerProvider, useUploadManagerContext } from "./upload-manager/upload-manager.mjs";
|
|
4
|
+
|
|
5
|
+
export { MuxPreview, UploadHandler, UploadManagerProvider, useUploadManagerContext };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
import { useEffect, useState } from "react";
|
|
5
4
|
import MuxPlayer from "@mux/mux-player-react";
|
|
6
|
-
import { jsx } from "react/jsx-runtime";
|
|
7
5
|
|
|
8
6
|
//#region src/components/mux-preview/mux-preview.tsx
|
|
9
7
|
/**
|
|
@@ -23,16 +21,9 @@ function MuxPreview(props) {
|
|
|
23
21
|
const docId = window.location.pathname.split("/").pop();
|
|
24
22
|
if (collection && docId && docId !== "create" && docId !== "admin") fetch(`/api/${collection}/${docId}`).then((res) => res.json()).then((data) => setPlaybackId(data.mux?.playbackId || null)).catch(() => setPlaybackId(null));
|
|
25
23
|
}, [props.schemaPath, isClient]);
|
|
26
|
-
return isClient && playbackId ?
|
|
27
|
-
playbackId,
|
|
28
|
-
streamType: "on-demand",
|
|
29
|
-
disableTracking: true,
|
|
30
|
-
style: { height: "60vh" },
|
|
31
|
-
nohotkeys: true,
|
|
32
|
-
preload: "metadata"
|
|
33
|
-
}) : null;
|
|
24
|
+
return isClient && playbackId ? <MuxPlayer playbackId={playbackId} streamType="on-demand" disableTracking={true} style={{ height: "60vh" }} nohotkeys={true} preload="metadata" /> : null;
|
|
34
25
|
}
|
|
35
26
|
|
|
36
27
|
//#endregion
|
|
37
28
|
export { MuxPreview };
|
|
38
|
-
//# sourceMappingURL=mux-preview.
|
|
29
|
+
//# sourceMappingURL=mux-preview.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mux-preview.mjs","names":[],"sources":["../../../src/components/mux-preview/mux-preview.tsx"],"sourcesContent":["'use client'\n\nimport { useEffect, useState } from 'react'\nimport MuxPlayer from '@mux/mux-player-react'\n\nimport type React from 'react'\nimport type { UIFieldClientProps } from 'payload'\n\n/**\n * React component for previewing Mux video assets\n * @param props - The UI field client props containing field data\n * @returns JSX element for Mux video preview\n */\nexport function MuxPreview(props: UIFieldClientProps) {\n const [playbackId, setPlaybackId] = useState<string | null>(null)\n const [isClient, setIsClient] = useState(false)\n\n // Ensure we’re on the client side\n useEffect(() => {\n setIsClient(true)\n }, [])\n\n useEffect(() => {\n if (!isClient) {\n return\n }\n\n // Get collection from schemaPath and ID from URL\n const collection = props.schemaPath?.split('.')[0] // \"media.muxPlayer\" -> \"media\"\n const docId = window.location.pathname.split('/').pop() // Get last part of URL\n\n if (collection && docId && docId !== 'create' && docId !== 'admin') {\n fetch(`/api/${collection}/${docId}`)\n .then((res) => res.json())\n .then((data) => setPlaybackId(data.mux?.playbackId || null))\n .catch(() => setPlaybackId(null))\n }\n }, [props.schemaPath, isClient])\n\n // Only render on client with playbackId\n return isClient && playbackId ? (\n <MuxPlayer\n playbackId={playbackId}\n streamType=\"on-demand\"\n disableTracking={true}\n style={{ height: '60vh' }}\n nohotkeys={true}\n preload=\"metadata\"\n />\n ) : null\n}\n"],"mappings":";;;;;;;;;;;AAaA,SAAgB,WAAW,OAA2B;CACpD,MAAM,CAAC,YAAY,iBAAiB,SAAwB,KAAK;CACjE,MAAM,CAAC,UAAU,eAAe,SAAS,MAAM;AAG/C,iBAAgB;AACd,cAAY,KAAK;IAChB,EAAE,CAAC;AAEN,iBAAgB;AACd,MAAI,CAAC,SACH;EAIF,MAAM,aAAa,MAAM,YAAY,MAAM,IAAI,CAAC;EAChD,MAAM,QAAQ,OAAO,SAAS,SAAS,MAAM,IAAI,CAAC,KAAK;AAEvD,MAAI,cAAc,SAAS,UAAU,YAAY,UAAU,QACzD,OAAM,QAAQ,WAAW,GAAG,QAAQ,CACjC,MAAM,QAAQ,IAAI,MAAM,CAAC,CACzB,MAAM,SAAS,cAAc,KAAK,KAAK,cAAc,KAAK,CAAC,CAC3D,YAAY,cAAc,KAAK,CAAC;IAEpC,CAAC,MAAM,YAAY,SAAS,CAAC;AAGhC,QAAO,YAAY,aACjB,CAAC,UACC,YAAY,YACZ,uBACA,iBAAiB,MACjB,OAAO,EAAE,QAAQ,QAAQ,EACzB,WAAW,MACX,wBAEA"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { emitter } from "../../hooks/useEmitter.js";
|
|
3
|
+
import { MediaCloudErrors } from "../../types/errors.mjs";
|
|
4
|
+
import { useErrorHandler } from "../../hooks/useErrorHandler.mjs";
|
|
5
|
+
import { getFileType, isVideo, sanitizeFilename } from "../../utils/file.mjs";
|
|
6
|
+
import { useMediaCloudEmitter } from "../../hooks/useMediaCloudEmitter.mjs";
|
|
8
7
|
import * as upchunk from "@mux/upchunk";
|
|
9
8
|
import * as tus from "tus-js-client";
|
|
10
9
|
import { toast } from "@payloadcms/ui";
|
|
@@ -12,6 +11,7 @@ import { createClientUploadHandler } from "@payloadcms/plugin-cloud-storage/clie
|
|
|
12
11
|
|
|
13
12
|
//#region src/components/upload-handler/upload-handler.tsx
|
|
14
13
|
const { logError, throwError } = useErrorHandler();
|
|
14
|
+
const emitter = useMediaCloudEmitter();
|
|
15
15
|
const MUX_CHUNK_SIZE = 30720;
|
|
16
16
|
const TUS_CHUNK_SIZE = 1024 * 1024;
|
|
17
17
|
const TUS_RETRY_DELAYS = [
|
|
@@ -25,13 +25,12 @@ const TUS_RETRY_DELAYS = [
|
|
|
25
25
|
* @param uploadUrl - The upload URL to parse
|
|
26
26
|
* @returns The extracted upload ID or empty string if parsing fails
|
|
27
27
|
*/
|
|
28
|
-
function
|
|
28
|
+
function parseFilename(uploadUrl) {
|
|
29
29
|
if (!uploadUrl) {
|
|
30
30
|
logError(MediaCloudErrors.UPLOAD_NO_URL);
|
|
31
31
|
return "";
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
return url.pathname.split("/").pop() || "";
|
|
33
|
+
return new URL(uploadUrl).pathname.split("/").pop() || "";
|
|
35
34
|
}
|
|
36
35
|
/**
|
|
37
36
|
* Handles Mux video upload with progress tracking
|
|
@@ -45,7 +44,7 @@ async function muxUpload(args) {
|
|
|
45
44
|
const getAssetEndpoint = `${serverURL}${apiRoute}/mux/asset`;
|
|
46
45
|
updateFilename(filename);
|
|
47
46
|
try {
|
|
48
|
-
const
|
|
47
|
+
const { url, uploadId } = await (await fetch(getUploadUrlEndpoint, {
|
|
49
48
|
body: JSON.stringify({
|
|
50
49
|
filename,
|
|
51
50
|
mimeType
|
|
@@ -53,35 +52,34 @@ async function muxUpload(args) {
|
|
|
53
52
|
credentials: "include",
|
|
54
53
|
method: "POST",
|
|
55
54
|
headers: { "Content-Type": "application/json" }
|
|
56
|
-
});
|
|
57
|
-
const { url, uploadId } = await response.json();
|
|
55
|
+
})).json();
|
|
58
56
|
const uploader = await upchunk.createUpload({
|
|
59
57
|
endpoint: url,
|
|
60
58
|
file,
|
|
61
59
|
chunkSize: MUX_CHUNK_SIZE
|
|
62
60
|
});
|
|
63
|
-
emitter.emit("
|
|
64
|
-
id: uploadId,
|
|
61
|
+
emitter.emit("addUpload", {
|
|
65
62
|
filename,
|
|
63
|
+
uploadId,
|
|
66
64
|
polling: false,
|
|
67
65
|
pollingUrl: getAssetEndpoint
|
|
68
66
|
});
|
|
69
|
-
uploader.on("error", ()
|
|
67
|
+
uploader.on("error", function() {
|
|
70
68
|
logError(MediaCloudErrors.MUX_UPLOAD_ERROR);
|
|
71
69
|
toast.error("Video upload failed");
|
|
72
|
-
emitter.emit("
|
|
70
|
+
emitter.emit("removeUpload", { uploadId });
|
|
73
71
|
});
|
|
74
|
-
uploader.on("progress", (progress)
|
|
75
|
-
emitter.emit("
|
|
76
|
-
|
|
72
|
+
uploader.on("progress", function(progress) {
|
|
73
|
+
emitter.emit("updateUpload", {
|
|
74
|
+
filename,
|
|
77
75
|
progress: progress.detail
|
|
78
76
|
});
|
|
79
77
|
});
|
|
80
|
-
uploader.on("success", ()
|
|
81
|
-
emitter.emit("
|
|
78
|
+
uploader.on("success", function() {
|
|
79
|
+
emitter.emit("uploadComplete", { filename });
|
|
82
80
|
});
|
|
83
81
|
return {
|
|
84
|
-
|
|
82
|
+
filename,
|
|
85
83
|
mimeType,
|
|
86
84
|
storage: "mux"
|
|
87
85
|
};
|
|
@@ -114,32 +112,30 @@ async function tusUpload(args) {
|
|
|
114
112
|
contentDisposition: "inline",
|
|
115
113
|
contentLength: filesize
|
|
116
114
|
},
|
|
117
|
-
onError: ()
|
|
115
|
+
onError: function() {
|
|
118
116
|
logError(MediaCloudErrors.TUS_UPLOAD_ERROR);
|
|
119
117
|
toast.error("File upload failed");
|
|
120
118
|
resolve(null);
|
|
121
119
|
},
|
|
122
|
-
onProgress: (bytesUploaded, bytesTotal)
|
|
120
|
+
onProgress: function(bytesUploaded, bytesTotal) {
|
|
123
121
|
const percentage = Math.round(bytesUploaded / bytesTotal * 100);
|
|
124
|
-
const
|
|
125
|
-
emitter.emit("
|
|
126
|
-
|
|
122
|
+
const filename$1 = parseFilename(upload?.url);
|
|
123
|
+
emitter.emit("updateUpload", {
|
|
124
|
+
filename: filename$1,
|
|
127
125
|
progress: percentage
|
|
128
126
|
});
|
|
129
127
|
},
|
|
130
|
-
onSuccess: ()
|
|
131
|
-
const
|
|
132
|
-
emitter.emit("
|
|
128
|
+
onSuccess: function() {
|
|
129
|
+
const filename$1 = parseFilename(upload?.url);
|
|
130
|
+
emitter.emit("uploadComplete", { filename: filename$1 });
|
|
131
|
+
fetch(`${serverURL}${apiRoute}/uploads/${filename$1}/process`);
|
|
133
132
|
},
|
|
134
|
-
onUploadUrlAvailable: ()
|
|
135
|
-
const
|
|
136
|
-
updateFilename(
|
|
137
|
-
emitter.emit("
|
|
138
|
-
id: uploadId,
|
|
139
|
-
filename
|
|
140
|
-
});
|
|
133
|
+
onUploadUrlAvailable: function() {
|
|
134
|
+
const filename$1 = parseFilename(upload?.url);
|
|
135
|
+
updateFilename(filename$1);
|
|
136
|
+
emitter.emit("addUpload", { filename: filename$1 });
|
|
141
137
|
resolve({
|
|
142
|
-
|
|
138
|
+
filename: filename$1,
|
|
143
139
|
mimeType,
|
|
144
140
|
storage: "s3"
|
|
145
141
|
});
|
|
@@ -148,7 +144,7 @@ async function tusUpload(args) {
|
|
|
148
144
|
upload.start();
|
|
149
145
|
});
|
|
150
146
|
}
|
|
151
|
-
const UploadHandler = createClientUploadHandler({ handler: async (args)
|
|
147
|
+
const UploadHandler = createClientUploadHandler({ handler: async function(args) {
|
|
152
148
|
const { serverURL, apiRoute, file, updateFilename } = args;
|
|
153
149
|
try {
|
|
154
150
|
const mimeType = await getFileType(file);
|
|
@@ -175,4 +171,4 @@ const UploadHandler = createClientUploadHandler({ handler: async (args) => {
|
|
|
175
171
|
|
|
176
172
|
//#endregion
|
|
177
173
|
export { UploadHandler };
|
|
178
|
-
//# sourceMappingURL=upload-handler.
|
|
174
|
+
//# sourceMappingURL=upload-handler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-handler.mjs","names":["filename","uploadArgs: UploadArgs"],"sources":["../../../src/components/upload-handler/upload-handler.tsx"],"sourcesContent":["'use client'\n\nimport * as upchunk from '@mux/upchunk'\nimport * as tus from 'tus-js-client'\n\nimport { toast } from '@payloadcms/ui'\nimport { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client'\n\nimport { MediaCloudErrors } from '../../types/errors'\nimport { useMediaCloudEmitter } from '../../hooks/useMediaCloudEmitter'\nimport { useErrorHandler } from '../../hooks/useErrorHandler'\nimport { isVideo, getFileType, sanitizeFilename } from '../../utils/file'\n\ninterface UploadArgs {\n serverURL: string\n apiRoute: string\n file: File\n mimeType: string\n updateFilename: (filename: string) => void\n}\n\ninterface UploadResult {\n filename: string\n mimeType: string\n storage: 'mux' | 's3'\n}\n\ninterface MuxCreateUploadResponse {\n url: string\n uploadId: string\n filename: string\n}\n\nconst { logError, throwError } = useErrorHandler()\nconst emitter = useMediaCloudEmitter()\n\nconst MUX_CHUNK_SIZE = 30720\nconst TUS_CHUNK_SIZE = 1024 * 1024\nconst TUS_RETRY_DELAYS = [0, 1000, 2000, 5000]\n\n/**\n * Utility function to parse upload ID from URL\n * @param uploadUrl - The upload URL to parse\n * @returns The extracted upload ID or empty string if parsing fails\n */\nfunction parseFilename(uploadUrl?: string | null): string {\n if (!uploadUrl) {\n logError(MediaCloudErrors.UPLOAD_NO_URL)\n return ''\n }\n const url = new URL(uploadUrl)\n return url.pathname.split('/').pop() || ''\n}\n\n/**\n * Handles Mux video upload with progress tracking\n * @param args - The upload arguments including file, server URL, and callbacks\n * @returns Promise that resolves to upload result or null if upload fails\n */\nasync function muxUpload(args: UploadArgs): Promise<UploadResult | null> {\n const { file, serverURL, apiRoute, mimeType, updateFilename } = args\n\n const filename = sanitizeFilename(file.name)\n const getUploadUrlEndpoint = `${serverURL}${apiRoute}/mux/upload`\n const getAssetEndpoint = `${serverURL}${apiRoute}/mux/asset`\n\n updateFilename(filename)\n\n try {\n // Request upload URL from Mux\n const response = await fetch(getUploadUrlEndpoint, {\n body: JSON.stringify({ filename, mimeType }),\n credentials: 'include',\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n\n const { url, uploadId } = (await response.json()) as MuxCreateUploadResponse\n\n // Create upchunk uploader\n const uploader = await upchunk.createUpload({\n endpoint: url,\n file,\n chunkSize: MUX_CHUNK_SIZE,\n })\n\n // Add upload to tracker\n emitter.emit('addUpload', {\n filename,\n uploadId,\n polling: false,\n pollingUrl: getAssetEndpoint,\n })\n\n // Set up event handlers\n uploader.on('error', function () {\n logError(MediaCloudErrors.MUX_UPLOAD_ERROR)\n toast.error('Video upload failed')\n emitter.emit('removeUpload', { uploadId })\n })\n\n uploader.on('progress', function (progress) {\n emitter.emit('updateUpload', {\n filename,\n progress: progress.detail,\n })\n })\n\n uploader.on('success', function () {\n emitter.emit('uploadComplete', { filename })\n })\n\n return {\n filename,\n mimeType,\n storage: 'mux',\n }\n } catch (_error) {\n logError(MediaCloudErrors.MUX_DIRECT_UPLOAD_ERROR)\n toast.error('Video upload failed')\n return null\n }\n}\n\n/**\n * Handles TUS file upload with resumable capabilities\n * @param args - The upload arguments including file, server URL, and callbacks\n * @returns Promise that resolves to upload result or null if upload fails\n */\nasync function tusUpload(args: UploadArgs): Promise<UploadResult | null> {\n const { apiRoute, serverURL, file, mimeType, updateFilename } = args\n\n const filename = file.name\n const filetype = file.type\n const filesize = file.size.toString()\n\n return new Promise((resolve) => {\n const upload = new tus.Upload(file, {\n endpoint: `${serverURL}${apiRoute}/uploads`,\n retryDelays: TUS_RETRY_DELAYS,\n chunkSize: TUS_CHUNK_SIZE,\n metadata: {\n filename,\n filetype,\n filesize,\n contentType: filetype,\n contentDisposition: 'inline',\n contentLength: filesize,\n },\n onError: function () {\n logError(MediaCloudErrors.TUS_UPLOAD_ERROR)\n toast.error('File upload failed')\n resolve(null)\n },\n onProgress: function (bytesUploaded, bytesTotal) {\n const percentage = Math.round((bytesUploaded / bytesTotal) * 100)\n const filename = parseFilename(upload?.url)\n emitter.emit('updateUpload', {\n filename,\n progress: percentage,\n })\n },\n onSuccess: function () {\n const filename = parseFilename(upload?.url)\n emitter.emit('uploadComplete', { filename })\n\n // Trigger post upload processing\n fetch(`${serverURL}${apiRoute}/uploads/${filename}/process`)\n },\n onUploadUrlAvailable: function () {\n const filename = parseFilename(upload?.url)\n updateFilename(filename)\n emitter.emit('addUpload', { filename })\n resolve({\n filename,\n mimeType,\n storage: 's3',\n })\n },\n })\n\n upload.start()\n })\n}\n\nexport const UploadHandler = createClientUploadHandler({\n handler: async function (args) {\n const { serverURL, apiRoute, file, updateFilename } = args\n\n try {\n const mimeType = await getFileType(file)\n\n if (!mimeType) {\n throwError(MediaCloudErrors.FILE_TYPE_UNKNOWN)\n return null\n }\n\n const isVideoFile = await isVideo(file)\n const uploadArgs: UploadArgs = {\n file,\n serverURL,\n apiRoute,\n mimeType,\n updateFilename,\n }\n\n if (isVideoFile) {\n return await muxUpload(uploadArgs)\n } else {\n return await tusUpload(uploadArgs)\n }\n } catch (_error) {\n logError(MediaCloudErrors.UPLOAD_HANDLER_ERROR)\n toast.error('Upload failed')\n return null\n }\n },\n})\n"],"mappings":"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"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { MediaCloudEmitterEvents } from "../../types/index.mjs";
|
|
1
2
|
import React from "react";
|
|
2
3
|
import "./upload-manager.css";
|
|
3
4
|
|
|
4
5
|
//#region src/components/upload-manager/upload-manager.d.ts
|
|
5
6
|
interface Upload {
|
|
6
|
-
id: string;
|
|
7
7
|
filename: string;
|
|
8
8
|
progress: number;
|
|
9
|
+
uploadId?: string;
|
|
9
10
|
error?: string;
|
|
10
11
|
polling?: boolean;
|
|
11
12
|
pollingUrl?: string;
|
|
@@ -14,23 +15,12 @@ interface Upload {
|
|
|
14
15
|
interface UploadManagerContextType {
|
|
15
16
|
showUploadManager?: boolean;
|
|
16
17
|
activeUploads: Upload[];
|
|
17
|
-
addUpload: (args:
|
|
18
|
-
updateUpload: (args:
|
|
18
|
+
addUpload: (args: MediaCloudEmitterEvents['addUpload']) => void;
|
|
19
|
+
updateUpload: (args: MediaCloudEmitterEvents['updateUpload']) => void;
|
|
19
20
|
}
|
|
20
21
|
interface UploadManagerProviderArgs {
|
|
21
22
|
children: React.ReactNode;
|
|
22
23
|
}
|
|
23
|
-
interface AddUploadArgs {
|
|
24
|
-
id: string;
|
|
25
|
-
filename: string;
|
|
26
|
-
polling?: boolean;
|
|
27
|
-
pollingUrl?: string;
|
|
28
|
-
}
|
|
29
|
-
interface UpdateUploadArgs {
|
|
30
|
-
id: string;
|
|
31
|
-
progress: number;
|
|
32
|
-
polling?: boolean;
|
|
33
|
-
}
|
|
34
24
|
/**
|
|
35
25
|
* Provider component for upload management context
|
|
36
26
|
* @param args - Arguments including children to wrap
|
|
@@ -40,4 +30,4 @@ declare function UploadManagerProvider(args: UploadManagerProviderArgs): React.J
|
|
|
40
30
|
declare const useUploadManagerContext: () => UploadManagerContextType;
|
|
41
31
|
//#endregion
|
|
42
32
|
export { UploadManagerProvider, useUploadManagerContext };
|
|
43
|
-
//# sourceMappingURL=upload-manager.d.
|
|
33
|
+
//# sourceMappingURL=upload-manager.d.mts.map
|