@maas/payload-plugin-media-cloud 0.0.31 → 0.0.32
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.mts +3 -3
- package/dist/adapter/handleDelete.mjs +6 -6
- package/dist/adapter/handleDelete.mjs.map +1 -1
- package/dist/adapter/staticHandler.d.mts +5 -3
- package/dist/adapter/staticHandler.mjs +8 -7
- package/dist/adapter/staticHandler.mjs.map +1 -1
- package/dist/adapter/storageAdapter.d.mts +3 -3
- package/dist/adapter/storageAdapter.mjs +4 -4
- package/dist/adapter/storageAdapter.mjs.map +1 -1
- package/dist/collectionHooks/afterChange.d.mts +7 -0
- package/dist/collectionHooks/afterChange.mjs +39 -0
- package/dist/collectionHooks/afterChange.mjs.map +1 -0
- package/dist/collectionHooks/beforeChange.d.mts +7 -0
- package/dist/collectionHooks/beforeChange.mjs +33 -0
- package/dist/collectionHooks/beforeChange.mjs.map +1 -0
- package/dist/collections/mediaCollection.d.mts +3 -2
- package/dist/collections/mediaCollection.mjs +36 -187
- package/dist/collections/mediaCollection.mjs.map +1 -1
- package/dist/components/folderFileCard/folderFileCard.d.mts +13 -0
- package/dist/components/folderFileCard/folderFileCard.mjs +30 -0
- package/dist/components/folderFileCard/folderFileCard.mjs.map +1 -0
- package/dist/components/gridContext/gridContext.d.mts +51 -0
- package/dist/components/gridContext/gridContext.mjs +227 -0
- package/dist/components/gridContext/gridContext.mjs.map +1 -0
- package/dist/components/gridView/gridView.css +50 -0
- package/dist/components/gridView/gridView.d.mts +16 -0
- package/dist/components/gridView/gridView.mjs +124 -0
- package/dist/components/gridView/gridView.mjs.map +1 -0
- package/dist/components/gridView/index.d.mts +2 -0
- package/dist/components/gridView/index.mjs +3 -0
- package/dist/components/index.d.mts +9 -7
- package/dist/components/index.mjs +5 -4
- package/dist/components/itemCardGrid/itemCardGrid.css +12 -0
- package/dist/components/itemCardGrid/itemCardGrid.d.mts +18 -0
- package/dist/components/itemCardGrid/itemCardGrid.mjs +22 -0
- package/dist/components/itemCardGrid/itemCardGrid.mjs.map +1 -0
- package/dist/components/muxPreview/index.d.mts +2 -0
- package/dist/components/muxPreview/index.mjs +3 -0
- package/dist/components/{mux-preview/mux-preview.d.mts → muxPreview/muxPreview.d.mts} +2 -2
- package/dist/components/{mux-preview/mux-preview.mjs → muxPreview/muxPreview.mjs} +2 -2
- package/dist/components/muxPreview/muxPreview.mjs.map +1 -0
- package/dist/components/uploadHandler/index.d.mts +2 -0
- package/dist/components/uploadHandler/index.mjs +3 -0
- package/dist/components/uploadHandler/uploadHandler.d.mts +20 -0
- package/dist/components/{upload-handler/upload-handler.mjs → uploadHandler/uploadHandler.mjs} +82 -52
- package/dist/components/uploadHandler/uploadHandler.mjs.map +1 -0
- package/dist/components/uploadManager/index.d.mts +2 -0
- package/dist/components/uploadManager/index.mjs +3 -0
- package/dist/components/{upload-manager/upload-manager.d.mts → uploadManager/uploadManager.d.mts} +3 -3
- package/dist/components/{upload-manager/upload-manager.mjs → uploadManager/uploadManager.mjs} +3 -3
- package/dist/components/uploadManager/uploadManager.mjs.map +1 -0
- package/dist/endpoints/fileExistsHandler.d.mts +12 -0
- package/dist/endpoints/{tusFileExistsHandler.mjs → fileExistsHandler.mjs} +7 -7
- package/dist/endpoints/fileExistsHandler.mjs.map +1 -0
- package/dist/endpoints/muxAssetHandler.d.mts +1 -0
- package/dist/endpoints/muxAssetHandler.mjs +3 -3
- package/dist/endpoints/muxAssetHandler.mjs.map +1 -1
- package/dist/endpoints/muxWebhookHandler.d.mts +1 -0
- package/dist/endpoints/muxWebhookHandler.mjs +6 -5
- package/dist/endpoints/muxWebhookHandler.mjs.map +1 -1
- package/dist/endpoints/tusCleanupHandler.d.mts +3 -2
- package/dist/endpoints/tusCleanupHandler.mjs +4 -4
- package/dist/endpoints/tusCleanupHandler.mjs.map +1 -1
- package/dist/endpoints/tusFolderHandler.d.mts +12 -0
- package/dist/endpoints/tusFolderHandler.mjs +39 -0
- package/dist/endpoints/tusFolderHandler.mjs.map +1 -0
- package/dist/endpoints/tusPostProcessorHandler.d.mts +3 -2
- package/dist/endpoints/tusPostProcessorHandler.mjs +6 -5
- package/dist/endpoints/tusPostProcessorHandler.mjs.map +1 -1
- package/dist/fields/alt.d.mts +7 -0
- package/dist/fields/alt.mjs +10 -0
- package/dist/fields/alt.mjs.map +1 -0
- package/dist/fields/filename.d.mts +7 -0
- package/dist/fields/filename.mjs +14 -0
- package/dist/fields/filename.mjs.map +1 -0
- package/dist/fields/height.d.mts +7 -0
- package/dist/fields/height.mjs +15 -0
- package/dist/fields/height.mjs.map +1 -0
- package/dist/fields/mux.d.mts +7 -0
- package/dist/fields/mux.mjs +149 -0
- package/dist/fields/mux.mjs.map +1 -0
- package/dist/fields/path.d.mts +7 -0
- package/dist/fields/path.mjs +14 -0
- package/dist/fields/path.mjs.map +1 -0
- package/dist/fields/storage.d.mts +7 -0
- package/dist/fields/storage.mjs +18 -0
- package/dist/fields/storage.mjs.map +1 -0
- package/dist/fields/thumbnail.d.mts +7 -0
- package/dist/fields/thumbnail.mjs +17 -0
- package/dist/fields/thumbnail.mjs.map +1 -0
- package/dist/fields/width.d.mts +7 -0
- package/dist/fields/width.mjs +15 -0
- package/dist/fields/width.mjs.map +1 -0
- package/dist/hooks/useErrorHandler.d.mts +1 -1
- package/dist/hooks/useErrorHandler.mjs +4 -2
- package/dist/hooks/useErrorHandler.mjs.map +1 -1
- package/dist/plugin.d.mts +5 -4
- package/dist/plugin.mjs +53 -29
- package/dist/plugin.mjs.map +1 -1
- package/dist/tus/stores/s3/{expiration-manager.d.mts → expirationManager.d.mts} +4 -3
- package/dist/tus/stores/s3/{expiration-manager.mjs → expirationManager.mjs} +6 -3
- package/dist/tus/stores/s3/expirationManager.mjs.map +1 -0
- package/dist/tus/stores/s3/{file-operations.d.mts → fileOperations.d.mts} +2 -2
- package/dist/tus/stores/s3/{file-operations.mjs → fileOperations.mjs} +2 -2
- package/dist/tus/stores/s3/fileOperations.mjs.map +1 -0
- package/dist/tus/stores/s3/index.d.mts +1 -1
- package/dist/tus/stores/s3/index.mjs +20 -9
- package/dist/tus/stores/s3/index.mjs.map +1 -1
- package/dist/tus/stores/s3/{metadata-manager.d.mts → metadataManager.d.mts} +4 -2
- package/dist/tus/stores/s3/{metadata-manager.mjs → metadataManager.mjs} +6 -5
- package/dist/tus/stores/s3/metadataManager.mjs.map +1 -0
- package/dist/tus/stores/s3/{parts-manager.d.mts → partsManager.d.mts} +4 -4
- package/dist/tus/stores/s3/{parts-manager.mjs → partsManager.mjs} +67 -29
- package/dist/tus/stores/s3/partsManager.mjs.map +1 -0
- package/dist/tus/stores/s3/{s3-store.d.mts → s3Store.d.mts} +38 -32
- package/dist/tus/stores/s3/{s3-store.mjs → s3Store.mjs} +102 -57
- package/dist/tus/stores/s3/s3Store.mjs.map +1 -0
- package/dist/types/errors.d.mts +32 -0
- package/dist/types/errors.mjs +32 -0
- package/dist/types/errors.mjs.map +1 -1
- package/dist/types/index.d.mts +42 -4
- package/dist/utils/buildS3Path.d.mts +10 -0
- package/dist/utils/buildS3Path.mjs +16 -0
- package/dist/utils/buildS3Path.mjs.map +1 -0
- package/dist/utils/buildThumbnailURL.d.mts +14 -0
- package/dist/utils/buildThumbnailURL.mjs +10 -0
- package/dist/utils/buildThumbnailURL.mjs.map +1 -0
- package/dist/utils/defaultOptions.d.mts +7 -0
- package/dist/utils/defaultOptions.mjs +12 -0
- package/dist/utils/defaultOptions.mjs.map +1 -0
- package/dist/utils/file.d.mts +16 -2
- package/dist/utils/file.mjs +58 -6
- package/dist/utils/file.mjs.map +1 -1
- package/dist/utils/mux.d.mts +3 -3
- package/dist/utils/mux.mjs +19 -8
- package/dist/utils/mux.mjs.map +1 -1
- package/dist/utils/tus.d.mts +12 -9
- package/dist/utils/tus.mjs +31 -11
- package/dist/utils/tus.mjs.map +1 -1
- package/package.json +9 -4
- package/dist/components/mux-preview/index.d.mts +0 -2
- package/dist/components/mux-preview/index.mjs +0 -3
- package/dist/components/mux-preview/mux-preview.mjs.map +0 -1
- package/dist/components/upload-handler/index.d.mts +0 -2
- package/dist/components/upload-handler/index.mjs +0 -3
- package/dist/components/upload-handler/upload-handler.d.mts +0 -22
- package/dist/components/upload-handler/upload-handler.mjs.map +0 -1
- package/dist/components/upload-manager/index.d.mts +0 -2
- package/dist/components/upload-manager/index.mjs +0 -3
- package/dist/components/upload-manager/upload-manager.mjs.map +0 -1
- package/dist/endpoints/tusFileExistsHandler.d.mts +0 -11
- package/dist/endpoints/tusFileExistsHandler.mjs.map +0 -1
- package/dist/tus/stores/s3/expiration-manager.mjs.map +0 -1
- package/dist/tus/stores/s3/file-operations.mjs.map +0 -1
- package/dist/tus/stores/s3/metadata-manager.mjs.map +0 -1
- package/dist/tus/stores/s3/parts-manager.mjs.map +0 -1
- package/dist/tus/stores/s3/s3-store.mjs.map +0 -1
- /package/dist/components/{upload-manager/upload-manager.css → uploadManager/uploadManager.css} +0 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { S3Store } from "../tus/stores/s3/
|
|
1
|
+
import { S3Store } from "../tus/stores/s3/s3Store.mjs";
|
|
2
2
|
import { Mux as Mux$1 } from "@mux/mux-node";
|
|
3
3
|
import { HandleDelete } from "@payloadcms/plugin-cloud-storage/types";
|
|
4
4
|
|
|
5
5
|
//#region src/adapter/handleDelete.d.ts
|
|
6
6
|
interface HandleDeleteArgs {
|
|
7
|
-
|
|
7
|
+
getS3Store: () => S3Store;
|
|
8
8
|
getMuxClient: () => Mux$1;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Creates a handle delete function for processing file deletions from both Mux and S3 storage
|
|
12
12
|
* @param args - The arguments for creating the delete handler
|
|
13
|
-
* @param args.
|
|
13
|
+
* @param args.getS3Store - Function that returns an S3 client instance
|
|
14
14
|
* @param args.getMuxClient - Function that returns a Mux client instance
|
|
15
15
|
* @returns A HandleDelete function that processes deletion requests based on storage type
|
|
16
16
|
*/
|
|
@@ -26,14 +26,14 @@ async function deleteMuxAsset(args) {
|
|
|
26
26
|
/**
|
|
27
27
|
* Deletes a file from S3 storage including its metadata info file
|
|
28
28
|
* @param args - The arguments for deleting the S3 file
|
|
29
|
-
* @param args.
|
|
29
|
+
* @param args.getS3Store - Function that returns an S3 client instance
|
|
30
30
|
* @param args.filename - The filename of the file to delete from S3
|
|
31
31
|
* @returns Promise that resolves when the file is deleted or rejects on error
|
|
32
32
|
*/
|
|
33
33
|
async function deleteS3File(args) {
|
|
34
|
-
const {
|
|
34
|
+
const { getS3Store, filename } = args;
|
|
35
35
|
try {
|
|
36
|
-
const { client, bucket } =
|
|
36
|
+
const { client, bucket } = getS3Store();
|
|
37
37
|
await client.deleteObjects({
|
|
38
38
|
Bucket: bucket,
|
|
39
39
|
Delete: { Objects: [{ Key: filename }, { Key: `${filename}.info` }] }
|
|
@@ -45,12 +45,12 @@ async function deleteS3File(args) {
|
|
|
45
45
|
/**
|
|
46
46
|
* Creates a handle delete function for processing file deletions from both Mux and S3 storage
|
|
47
47
|
* @param args - The arguments for creating the delete handler
|
|
48
|
-
* @param args.
|
|
48
|
+
* @param args.getS3Store - Function that returns an S3 client instance
|
|
49
49
|
* @param args.getMuxClient - Function that returns a Mux client instance
|
|
50
50
|
* @returns A HandleDelete function that processes deletion requests based on storage type
|
|
51
51
|
*/
|
|
52
52
|
function getHandleDelete(args) {
|
|
53
|
-
const {
|
|
53
|
+
const { getS3Store, getMuxClient } = args;
|
|
54
54
|
return async ({ doc, req }) => {
|
|
55
55
|
if (req?.method !== "DELETE" || !doc) return;
|
|
56
56
|
const media = doc;
|
|
@@ -63,7 +63,7 @@ function getHandleDelete(args) {
|
|
|
63
63
|
break;
|
|
64
64
|
case "s3":
|
|
65
65
|
if (media.filename) await deleteS3File({
|
|
66
|
-
|
|
66
|
+
getS3Store,
|
|
67
67
|
filename: media.filename
|
|
68
68
|
});
|
|
69
69
|
break;
|
|
@@ -1 +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/
|
|
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/s3Store'\n\ninterface HandleDeleteArgs {\n getS3Store: () => S3Store\n getMuxClient: () => Mux\n}\n\ninterface DeleteMuxAssetArgs {\n getMuxClient: () => Mux\n uploadId: string\n}\n\ninterface DeleteS3FileArgs {\n getS3Store: () => 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.message)\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.getS3Store - Function that returns an S3 client instance\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 { getS3Store, filename } = args\n\n try {\n const { client, bucket } = getS3Store()\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.message)\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.getS3Store - Function that returns an S3 client instance\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 { getS3Store, 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({ getS3Store, filename: media.filename })\n }\n break\n default:\n logError(MediaCloudErrors.UNKNOWN_STORAGE_TYPE.message)\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,QAAQ;;;;;;;;;;AAW7D,eAAe,aAAa,MAAuC;CACjE,MAAM,EAAE,YAAY,aAAa;AAEjC,KAAI;EACF,MAAM,EAAE,QAAQ,WAAW,YAAY;AACvC,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,QAAQ;;;;;;;;;;AAWtD,SAAgB,gBAAgB,MAAsC;CACpE,MAAM,EAAE,YAAY,iBAAiB;AACrC,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;KAAY,UAAU,MAAM;KAAU,CAAC;AAE9D;GACF,QACE,UAAS,iBAAiB,qBAAqB,QAAQ"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { S3Store } from "../tus/stores/s3/
|
|
1
|
+
import { S3Store } from "../tus/stores/s3/s3Store.mjs";
|
|
2
2
|
import { StaticHandler } from "@payloadcms/plugin-cloud-storage/types";
|
|
3
3
|
|
|
4
4
|
//#region src/adapter/staticHandler.d.ts
|
|
5
5
|
interface StaticHandlerArgs {
|
|
6
|
-
|
|
6
|
+
getS3Store: () => S3Store;
|
|
7
|
+
collection: string;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* Creates a static handler that serves files from S3 or returns empty responses for Mux assets
|
|
10
11
|
* @param args - The arguments for creating the static handler
|
|
11
|
-
* @param args.
|
|
12
|
+
* @param args.getS3Store - Function that returns an S3 client instance
|
|
13
|
+
* @param args.collection - The name of the media collection in Payload
|
|
12
14
|
* @returns A StaticHandler function that serves files or empty responses based on storage type
|
|
13
15
|
*/
|
|
14
16
|
declare function getStaticHandler(args: StaticHandlerArgs): StaticHandler;
|
|
@@ -4,23 +4,24 @@ import { Readable } from "node:stream";
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates a static handler that serves files from S3 or returns empty responses for Mux assets
|
|
6
6
|
* @param args - The arguments for creating the static handler
|
|
7
|
-
* @param args.
|
|
7
|
+
* @param args.getS3Store - Function that returns an S3 client instance
|
|
8
|
+
* @param args.collection - The name of the media collection in Payload
|
|
8
9
|
* @returns A StaticHandler function that serves files or empty responses based on storage type
|
|
9
10
|
*/
|
|
10
11
|
function getStaticHandler(args) {
|
|
11
|
-
const {
|
|
12
|
+
const { getS3Store, collection } = args;
|
|
12
13
|
return async (req, { params }) => {
|
|
13
14
|
const { payload } = req;
|
|
14
15
|
const filename = params.filename;
|
|
15
16
|
const { docs } = await payload.find({
|
|
16
|
-
collection
|
|
17
|
+
collection,
|
|
17
18
|
where: { filename: { equals: filename } }
|
|
18
19
|
});
|
|
19
20
|
const doc = docs[0];
|
|
20
21
|
if (!doc) return createEmptyResponse();
|
|
21
22
|
if (doc.storage === "mux") return createEmptyResponse({ mimeType: doc.mimeType });
|
|
22
23
|
return await serveS3File({
|
|
23
|
-
|
|
24
|
+
getS3Store,
|
|
24
25
|
doc
|
|
25
26
|
});
|
|
26
27
|
};
|
|
@@ -44,13 +45,13 @@ function createEmptyResponse(args) {
|
|
|
44
45
|
/**
|
|
45
46
|
* Serves a file from S3 storage
|
|
46
47
|
* @param args - The arguments for serving the S3 file
|
|
47
|
-
* @param args.
|
|
48
|
+
* @param args.getS3Store - Function that returns an S3 client instance
|
|
48
49
|
* @param args.doc - The document containing file metadata
|
|
49
50
|
* @returns A Promise that resolves to a Response object containing the file stream or empty response on error
|
|
50
51
|
*/
|
|
51
|
-
async function serveS3File({
|
|
52
|
+
async function serveS3File({ getS3Store, doc }) {
|
|
52
53
|
try {
|
|
53
|
-
const stream$1 = await
|
|
54
|
+
const stream$1 = await getS3Store().read(doc.filename);
|
|
54
55
|
if (stream$1) {
|
|
55
56
|
const webStream = Readable.toWeb(stream$1);
|
|
56
57
|
return new Response(webStream);
|
|
@@ -1 +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/
|
|
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/s3Store'\n\ninterface StaticHandlerArgs {\n getS3Store: () => S3Store\n collection: string\n}\n\ninterface ServeS3FileArgs {\n getS3Store: () => 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.getS3Store - Function that returns an S3 client instance\n * @param args.collection - The name of the media collection in Payload\n * @returns A StaticHandler function that serves files or empty responses based on storage type\n */\nexport function getStaticHandler(args: StaticHandlerArgs): StaticHandler {\n const { getS3Store, collection } = args\n return async (req, { params }) => {\n const { payload } = req\n const filename = params.filename\n\n const { docs } = await payload.find({\n collection,\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({ getS3Store, 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.getS3Store - Function that returns an S3 client instance\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 getS3Store,\n doc,\n}: ServeS3FileArgs): Promise<Response> {\n try {\n const s3Store = getS3Store()\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":";;;;;;;;;;AA0BA,SAAgB,iBAAiB,MAAwC;CACvE,MAAM,EAAE,YAAY,eAAe;AACnC,QAAO,OAAO,KAAK,EAAE,aAAa;EAChC,MAAM,EAAE,YAAY;EACpB,MAAM,WAAW,OAAO;EAExB,MAAM,EAAE,SAAS,MAAM,QAAQ,KAAK;GAClC;GACA,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;GAAY;GAAK,CAAC;;;;;;;;;AAUjD,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,YACA,OACqC;AACrC,KAAI;EAEF,MAAMA,WAAS,MADC,YAAY,CACC,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,19 +1,19 @@
|
|
|
1
1
|
import { MediaCloudPluginOptions } from "../types/index.mjs";
|
|
2
|
-
import { S3Store } from "../tus/stores/s3/
|
|
2
|
+
import { S3Store } from "../tus/stores/s3/s3Store.mjs";
|
|
3
3
|
import { Mux as Mux$1 } from "@mux/mux-node";
|
|
4
4
|
import { Adapter } from "@payloadcms/plugin-cloud-storage/types";
|
|
5
5
|
|
|
6
6
|
//#region src/adapter/storageAdapter.d.ts
|
|
7
7
|
interface StorageAdapterArgs {
|
|
8
8
|
pluginOptions: MediaCloudPluginOptions;
|
|
9
|
-
|
|
9
|
+
getS3Store: () => S3Store;
|
|
10
10
|
getMuxClient: () => Mux$1;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Creates the storage adapter for media cloud plugin
|
|
14
14
|
* @param args - The arguments for creating the storage adapter
|
|
15
15
|
* @param args.pluginOptions - The media cloud plugin options
|
|
16
|
-
* @param args.
|
|
16
|
+
* @param args.getS3Store - Function that returns an S3 client instance
|
|
17
17
|
* @param args.getMuxClient - Function that returns a Mux client instance
|
|
18
18
|
* @returns An Adapter function that returns a GeneratedAdapter configuration
|
|
19
19
|
*/
|
|
@@ -7,21 +7,21 @@ import { getStaticHandler } from "./staticHandler.mjs";
|
|
|
7
7
|
* Creates the storage adapter for media cloud plugin
|
|
8
8
|
* @param args - The arguments for creating the storage adapter
|
|
9
9
|
* @param args.pluginOptions - The media cloud plugin options
|
|
10
|
-
* @param args.
|
|
10
|
+
* @param args.getS3Store - Function that returns an S3 client instance
|
|
11
11
|
* @param args.getMuxClient - Function that returns a Mux client instance
|
|
12
12
|
* @returns An Adapter function that returns a GeneratedAdapter configuration
|
|
13
13
|
*/
|
|
14
14
|
function getStorageAdapter(args) {
|
|
15
|
-
const {
|
|
15
|
+
const { getS3Store, getMuxClient } = args;
|
|
16
16
|
return () => ({
|
|
17
17
|
name: "media-cloud",
|
|
18
18
|
clientUploads: true,
|
|
19
19
|
handleUpload: getHandleUpload(),
|
|
20
20
|
handleDelete: getHandleDelete({
|
|
21
|
-
|
|
21
|
+
getS3Store,
|
|
22
22
|
getMuxClient
|
|
23
23
|
}),
|
|
24
|
-
staticHandler: getStaticHandler({
|
|
24
|
+
staticHandler: getStaticHandler({ getS3Store })
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -1 +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/
|
|
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/s3Store'\n\ninterface StorageAdapterArgs {\n pluginOptions: MediaCloudPluginOptions\n getS3Store: () => 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.getS3Store - Function that returns an S3 client instance\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 { getS3Store, getMuxClient } = args\n\n return (): GeneratedAdapter => ({\n name: 'media-cloud',\n clientUploads: true,\n handleUpload: getHandleUpload(),\n handleDelete: getHandleDelete({ getS3Store, getMuxClient }),\n staticHandler: getStaticHandler({ getS3Store }),\n })\n}\n"],"mappings":";;;;;;;;;;;;;AA0BA,SAAgB,kBAAkB,MAAmC;CACnE,MAAM,EAAE,YAAY,iBAAiB;AAErC,eAAgC;EAC9B,MAAM;EACN,eAAe;EACf,cAAc,iBAAiB;EAC/B,cAAc,gBAAgB;GAAE;GAAY;GAAc,CAAC;EAC3D,eAAe,iBAAiB,EAAE,YAAY,CAAC;EAChD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { MediaCloudErrors } from "../types/errors.mjs";
|
|
2
|
+
import { useErrorHandler } from "../hooks/useErrorHandler.mjs";
|
|
3
|
+
import { buildThumbnailURL } from "../utils/buildThumbnailURL.mjs";
|
|
4
|
+
import { s3Store } from "../plugin.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/collectionHooks/afterChange.ts
|
|
7
|
+
const afterChangeHook = async ({ collection, doc, previousDoc, req }) => {
|
|
8
|
+
const { throwError } = useErrorHandler();
|
|
9
|
+
if (doc.path !== previousDoc?.path) {
|
|
10
|
+
if (doc.storage === "s3" && s3Store) try {
|
|
11
|
+
const oldKey = previousDoc?.path ?? previousDoc?.filename;
|
|
12
|
+
const newKey = doc.path;
|
|
13
|
+
await s3Store.copy(oldKey, newKey);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
throwError({
|
|
16
|
+
...MediaCloudErrors.S3_MOVE_ERROR,
|
|
17
|
+
cause: error
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (!doc.thumbnail || previousDoc?.path !== doc.path) {
|
|
22
|
+
const thumbnail = buildThumbnailURL({
|
|
23
|
+
storage: doc.storage,
|
|
24
|
+
playbackId: doc.storage === "mux" ? doc.id : void 0,
|
|
25
|
+
s3Key: doc.storage === "s3" ? doc.path : void 0,
|
|
26
|
+
s3Store
|
|
27
|
+
});
|
|
28
|
+
req.payload.update({
|
|
29
|
+
collection: collection.slug,
|
|
30
|
+
id: doc.id,
|
|
31
|
+
data: { thumbnail }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return doc;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { afterChangeHook };
|
|
39
|
+
//# sourceMappingURL=afterChange.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"afterChange.mjs","names":["afterChangeHook: CollectionAfterChangeHook"],"sources":["../../src/collectionHooks/afterChange.ts"],"sourcesContent":["import { buildThumbnailURL } from '../utils/buildThumbnailURL'\nimport { s3Store } from '../plugin'\nimport { MediaCloudErrors } from '../types/errors'\nimport { useErrorHandler } from '../hooks/useErrorHandler'\n\nimport type { CollectionAfterChangeHook } from 'payload'\n\nexport const afterChangeHook: CollectionAfterChangeHook = async ({\n collection,\n doc,\n previousDoc,\n req,\n}) => {\n const { throwError } = useErrorHandler()\n\n // Move asset in S3 if path has changed\n if (doc.path !== previousDoc?.path) {\n if (doc.storage === 's3' && s3Store) {\n try {\n const oldKey = previousDoc?.path ?? previousDoc?.filename\n const newKey = doc.path\n\n await s3Store.copy(oldKey, newKey)\n } catch (error) {\n throwError({ ...MediaCloudErrors.S3_MOVE_ERROR, cause: error })\n }\n }\n }\n\n // Handle thumbnail\n if (!doc.thumbnail || previousDoc?.path !== doc.path) {\n const thumbnail = buildThumbnailURL({\n storage: doc.storage,\n playbackId: doc.storage === 'mux' ? doc.id : undefined,\n s3Key: doc.storage === 's3' ? doc.path : undefined,\n s3Store,\n })\n\n req.payload.update({\n collection: collection.slug,\n id: doc.id,\n data: { thumbnail },\n })\n }\n\n return doc\n}\n"],"mappings":";;;;;;AAOA,MAAaA,kBAA6C,OAAO,EAC/D,YACA,KACA,aACA,UACI;CACJ,MAAM,EAAE,eAAe,iBAAiB;AAGxC,KAAI,IAAI,SAAS,aAAa,MAC5B;MAAI,IAAI,YAAY,QAAQ,QAC1B,KAAI;GACF,MAAM,SAAS,aAAa,QAAQ,aAAa;GACjD,MAAM,SAAS,IAAI;AAEnB,SAAM,QAAQ,KAAK,QAAQ,OAAO;WAC3B,OAAO;AACd,cAAW;IAAE,GAAG,iBAAiB;IAAe,OAAO;IAAO,CAAC;;;AAMrE,KAAI,CAAC,IAAI,aAAa,aAAa,SAAS,IAAI,MAAM;EACpD,MAAM,YAAY,kBAAkB;GAClC,SAAS,IAAI;GACb,YAAY,IAAI,YAAY,QAAQ,IAAI,KAAK;GAC7C,OAAO,IAAI,YAAY,OAAO,IAAI,OAAO;GACzC;GACD,CAAC;AAEF,MAAI,QAAQ,OAAO;GACjB,YAAY,WAAW;GACvB,IAAI,IAAI;GACR,MAAM,EAAE,WAAW;GACpB,CAAC;;AAGJ,QAAO"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MediaCloudErrors } from "../types/errors.mjs";
|
|
2
|
+
import { useErrorHandler } from "../hooks/useErrorHandler.mjs";
|
|
3
|
+
import { buildS3Path } from "../utils/buildS3Path.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/collectionHooks/beforeChange.ts
|
|
6
|
+
const beforeChangeHook = async ({ data, originalDoc, req }) => {
|
|
7
|
+
const { throwError } = useErrorHandler();
|
|
8
|
+
if (data.filename && data.filename !== originalDoc?.filename || data.folder && data.folder !== originalDoc?.folder || !data.folder) {
|
|
9
|
+
let prefix = "";
|
|
10
|
+
if (data.folder) try {
|
|
11
|
+
const folder = await req.payload.findByID({
|
|
12
|
+
id: data.folder,
|
|
13
|
+
collection: "payload-folders",
|
|
14
|
+
select: {
|
|
15
|
+
name: true,
|
|
16
|
+
folder: true
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
if (folder) prefix = buildS3Path(folder);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throwError({
|
|
22
|
+
...MediaCloudErrors.FOLDER_FETCH_ERROR,
|
|
23
|
+
cause: error
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
data.path = prefix ? `${prefix}/${data.filename}` : data.filename;
|
|
27
|
+
}
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { beforeChangeHook };
|
|
33
|
+
//# sourceMappingURL=beforeChange.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beforeChange.mjs","names":["beforeChangeHook: CollectionBeforeChangeHook"],"sources":["../../src/collectionHooks/beforeChange.ts"],"sourcesContent":["import { useErrorHandler } from '../hooks/useErrorHandler'\nimport { MediaCloudErrors } from '../types/errors'\nimport { buildS3Path } from '../utils/buildS3Path'\nimport type { CollectionBeforeChangeHook } from 'payload'\n\nexport const beforeChangeHook: CollectionBeforeChangeHook = async ({\n data,\n originalDoc,\n req,\n}) => {\n const { throwError } = useErrorHandler()\n // Update path\n if (\n (data.filename && data.filename !== originalDoc?.filename) ||\n (data.folder && data.folder !== originalDoc?.folder) ||\n !data.folder\n ) {\n let prefix = ''\n\n if (data.folder) {\n try {\n const folder = await req.payload.findByID({\n id: data.folder,\n collection: 'payload-folders',\n select: { name: true, folder: true },\n })\n\n if (folder) {\n prefix = buildS3Path(folder)\n }\n } catch (error) {\n throwError({ ...MediaCloudErrors.FOLDER_FETCH_ERROR, cause: error })\n }\n }\n\n // Save path\n data.path = prefix ? `${prefix}/${data.filename}` : data.filename\n }\n\n return data\n}\n"],"mappings":";;;;;AAKA,MAAaA,mBAA+C,OAAO,EACjE,MACA,aACA,UACI;CACJ,MAAM,EAAE,eAAe,iBAAiB;AAExC,KACG,KAAK,YAAY,KAAK,aAAa,aAAa,YAChD,KAAK,UAAU,KAAK,WAAW,aAAa,UAC7C,CAAC,KAAK,QACN;EACA,IAAI,SAAS;AAEb,MAAI,KAAK,OACP,KAAI;GACF,MAAM,SAAS,MAAM,IAAI,QAAQ,SAAS;IACxC,IAAI,KAAK;IACT,YAAY;IACZ,QAAQ;KAAE,MAAM;KAAM,QAAQ;KAAM;IACrC,CAAC;AAEF,OAAI,OACF,UAAS,YAAY,OAAO;WAEvB,OAAO;AACd,cAAW;IAAE,GAAG,iBAAiB;IAAoB,OAAO;IAAO,CAAC;;AAKxE,OAAK,OAAO,SAAS,GAAG,OAAO,GAAG,KAAK,aAAa,KAAK;;AAG3D,QAAO"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MediaCloudPluginOptions } from "../types/index.mjs";
|
|
2
2
|
import { CollectionConfig } from "payload";
|
|
3
3
|
|
|
4
4
|
//#region src/collections/mediaCollection.d.ts
|
|
5
5
|
interface GetMediaCollectionArgs {
|
|
6
|
-
|
|
6
|
+
view: MediaCloudPluginOptions['view'];
|
|
7
|
+
folders: MediaCloudPluginOptions['folders'];
|
|
7
8
|
baseCollection?: CollectionConfig;
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import { thumbnailField } from "../fields/thumbnail.mjs";
|
|
2
|
+
import { pathField } from "../fields/path.mjs";
|
|
3
|
+
import { filenameField } from "../fields/filename.mjs";
|
|
4
|
+
import { altField } from "../fields/alt.mjs";
|
|
5
|
+
import { widthField } from "../fields/width.mjs";
|
|
6
|
+
import { heightField } from "../fields/height.mjs";
|
|
7
|
+
import { storageField } from "../fields/storage.mjs";
|
|
8
|
+
import { muxField } from "../fields/mux.mjs";
|
|
9
|
+
import { beforeChangeHook } from "../collectionHooks/beforeChange.mjs";
|
|
10
|
+
import { afterChangeHook } from "../collectionHooks/afterChange.mjs";
|
|
11
|
+
|
|
1
12
|
//#region src/collections/mediaCollection.ts
|
|
2
13
|
/**
|
|
3
14
|
* Creates a media collection configuration for Payload CMS
|
|
@@ -5,14 +16,16 @@
|
|
|
5
16
|
* @returns A configured Payload collection for media files
|
|
6
17
|
*/
|
|
7
18
|
function getMediaCollection(args) {
|
|
8
|
-
const {
|
|
19
|
+
const { baseCollection, view, folders } = args;
|
|
9
20
|
const config = {
|
|
10
21
|
slug: "media",
|
|
22
|
+
custom: { storage: "test" },
|
|
11
23
|
access: {
|
|
12
24
|
read: () => true,
|
|
13
25
|
delete: () => true
|
|
14
26
|
},
|
|
15
27
|
admin: {
|
|
28
|
+
components: view === "grid" ? { views: { list: { Component: "@maas/payload-plugin-media-cloud/components#GridView" } } } : void 0,
|
|
16
29
|
group: "Media Cloud",
|
|
17
30
|
pagination: { defaultLimit: 50 }
|
|
18
31
|
},
|
|
@@ -21,197 +34,24 @@ function getMediaCollection(args) {
|
|
|
21
34
|
displayPreview: true,
|
|
22
35
|
hideRemoveFile: true,
|
|
23
36
|
adminThumbnail({ doc }) {
|
|
24
|
-
|
|
25
|
-
else if (doc?.storage === "s3") return `https://wsrv.nl/?url=${s3Store.getUrl(doc.filename)}?width=200&height=200&default=1`;
|
|
26
|
-
return null;
|
|
37
|
+
return doc.thumbnail ?? null;
|
|
27
38
|
}
|
|
28
39
|
},
|
|
29
40
|
fields: [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
type: "text"
|
|
34
|
-
},
|
|
41
|
+
thumbnailField,
|
|
42
|
+
pathField,
|
|
43
|
+
altField,
|
|
35
44
|
{
|
|
36
45
|
type: "row",
|
|
37
|
-
fields: [
|
|
38
|
-
name: "width",
|
|
39
|
-
label: "Width",
|
|
40
|
-
type: "text",
|
|
41
|
-
admin: {
|
|
42
|
-
readOnly: true,
|
|
43
|
-
hidden: false,
|
|
44
|
-
width: "50%"
|
|
45
|
-
}
|
|
46
|
-
}, {
|
|
47
|
-
name: "height",
|
|
48
|
-
label: "Height",
|
|
49
|
-
type: "number",
|
|
50
|
-
admin: {
|
|
51
|
-
readOnly: true,
|
|
52
|
-
hidden: false,
|
|
53
|
-
width: "50%"
|
|
54
|
-
}
|
|
55
|
-
}]
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
name: "storage",
|
|
59
|
-
label: "Storage",
|
|
60
|
-
type: "select",
|
|
61
|
-
options: [{
|
|
62
|
-
label: "Mux",
|
|
63
|
-
value: "mux"
|
|
64
|
-
}, {
|
|
65
|
-
label: "S3",
|
|
66
|
-
value: "s3"
|
|
67
|
-
}],
|
|
68
|
-
admin: { readOnly: true }
|
|
46
|
+
fields: [widthField, heightField]
|
|
69
47
|
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
disableListFilter: true,
|
|
78
|
-
readOnly: true,
|
|
79
|
-
condition: (data) => {
|
|
80
|
-
return data.storage === "mux";
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
fields: [
|
|
84
|
-
{
|
|
85
|
-
name: "preview",
|
|
86
|
-
type: "ui",
|
|
87
|
-
admin: {
|
|
88
|
-
condition: (data) => {
|
|
89
|
-
return data.storage === "mux";
|
|
90
|
-
},
|
|
91
|
-
disableListColumn: true,
|
|
92
|
-
components: { Field: "@maas/payload-plugin-media-cloud/components#MuxPreview" }
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
name: "status",
|
|
97
|
-
label: "Status",
|
|
98
|
-
type: "text"
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
name: "uploadId",
|
|
102
|
-
label: "Upload ID",
|
|
103
|
-
type: "text"
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
name: "assetId",
|
|
107
|
-
label: "Asset ID",
|
|
108
|
-
type: "text"
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
name: "playbackId",
|
|
112
|
-
label: "Playback ID",
|
|
113
|
-
type: "text"
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
name: "aspectRatio",
|
|
117
|
-
label: "Aspect Ratio",
|
|
118
|
-
type: "text"
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
name: "duration",
|
|
122
|
-
label: "Duration",
|
|
123
|
-
type: "number"
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
name: "tracks",
|
|
127
|
-
label: "Tracks",
|
|
128
|
-
type: "json",
|
|
129
|
-
typescriptSchema: [({ jsonSchema }) => ({
|
|
130
|
-
...jsonSchema,
|
|
131
|
-
type: "array",
|
|
132
|
-
items: [{
|
|
133
|
-
type: "object",
|
|
134
|
-
properties: {
|
|
135
|
-
type: {
|
|
136
|
-
type: "string",
|
|
137
|
-
enum: ["audio", "video"]
|
|
138
|
-
},
|
|
139
|
-
id: { type: "string" },
|
|
140
|
-
duration: { type: "number" },
|
|
141
|
-
primary: { type: "boolean" },
|
|
142
|
-
max_channels: { type: "number" },
|
|
143
|
-
max_channel_layout: { type: "string" },
|
|
144
|
-
max_width: { type: "number" },
|
|
145
|
-
max_height: { type: "number" },
|
|
146
|
-
max_frame_rate: { type: "number" }
|
|
147
|
-
},
|
|
148
|
-
required: [
|
|
149
|
-
"type",
|
|
150
|
-
"id",
|
|
151
|
-
"duration",
|
|
152
|
-
"primary",
|
|
153
|
-
"max_channels",
|
|
154
|
-
"max_channel_layout",
|
|
155
|
-
"max_width",
|
|
156
|
-
"max_height",
|
|
157
|
-
"max_frame_rate"
|
|
158
|
-
]
|
|
159
|
-
}]
|
|
160
|
-
})]
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
name: "maxResolutionTier",
|
|
164
|
-
label: "Max Resolution Tier",
|
|
165
|
-
type: "text"
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
name: "videoQuality",
|
|
169
|
-
label: "Video Quality",
|
|
170
|
-
type: "text"
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
name: "staticRenditions",
|
|
174
|
-
label: "Static Renditions",
|
|
175
|
-
type: "json",
|
|
176
|
-
typescriptSchema: [({ jsonSchema }) => ({
|
|
177
|
-
...jsonSchema,
|
|
178
|
-
type: "object",
|
|
179
|
-
properties: { files: {
|
|
180
|
-
type: "array",
|
|
181
|
-
items: {
|
|
182
|
-
type: "object",
|
|
183
|
-
properties: {
|
|
184
|
-
type: { type: "string" },
|
|
185
|
-
status: { type: "string" },
|
|
186
|
-
resolution: { type: "string" },
|
|
187
|
-
name: { type: "string" },
|
|
188
|
-
id: { type: "string" },
|
|
189
|
-
ext: { type: "string" },
|
|
190
|
-
width: { type: "number" },
|
|
191
|
-
height: { type: "number" },
|
|
192
|
-
filesize: { type: "string" },
|
|
193
|
-
bitrate: { type: "number" }
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
required: [
|
|
197
|
-
"type",
|
|
198
|
-
"status",
|
|
199
|
-
"resolution",
|
|
200
|
-
"name",
|
|
201
|
-
"id",
|
|
202
|
-
"ext",
|
|
203
|
-
"width",
|
|
204
|
-
"height",
|
|
205
|
-
"filesize",
|
|
206
|
-
"bitrate"
|
|
207
|
-
]
|
|
208
|
-
} },
|
|
209
|
-
required: ["files"]
|
|
210
|
-
})]
|
|
211
|
-
}
|
|
212
|
-
]
|
|
213
|
-
}
|
|
214
|
-
]
|
|
48
|
+
storageField,
|
|
49
|
+
muxField
|
|
50
|
+
],
|
|
51
|
+
hooks: {
|
|
52
|
+
beforeChange: folders ? [beforeChangeHook] : [],
|
|
53
|
+
afterChange: folders ? [afterChangeHook] : []
|
|
54
|
+
}
|
|
215
55
|
};
|
|
216
56
|
if (!baseCollection) return config;
|
|
217
57
|
return {
|
|
@@ -226,7 +66,16 @@ function getMediaCollection(args) {
|
|
|
226
66
|
...baseCollection.access ?? {}
|
|
227
67
|
},
|
|
228
68
|
upload: config.upload,
|
|
229
|
-
fields: [
|
|
69
|
+
fields: [
|
|
70
|
+
...baseCollection.fields ?? [],
|
|
71
|
+
...config.fields,
|
|
72
|
+
filenameField
|
|
73
|
+
],
|
|
74
|
+
hooks: {
|
|
75
|
+
...baseCollection.hooks,
|
|
76
|
+
beforeChange: [...baseCollection.hooks?.beforeChange ?? [], ...config.hooks?.beforeChange ?? []],
|
|
77
|
+
afterChange: [...baseCollection.hooks?.afterChange ?? [], ...config.hooks?.afterChange ?? []]
|
|
78
|
+
}
|
|
230
79
|
};
|
|
231
80
|
}
|
|
232
81
|
|