@maas/payload-plugin-media-cloud 0.0.0
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/LICENSE +8 -0
- package/dist/adapter/handleDelete.d.ts +20 -0
- package/dist/adapter/handleDelete.js +70 -0
- package/dist/adapter/handleDelete.js.map +1 -0
- package/dist/adapter/handleUpload.d.ts +12 -0
- package/dist/adapter/handleUpload.js +29 -0
- package/dist/adapter/handleUpload.js.map +1 -0
- package/dist/adapter/staticHandler.d.ts +17 -0
- package/dist/adapter/staticHandler.js +64 -0
- package/dist/adapter/staticHandler.js.map +1 -0
- package/dist/adapter/storageAdapter.d.ts +23 -0
- package/dist/adapter/storageAdapter.js +30 -0
- package/dist/adapter/storageAdapter.js.map +1 -0
- package/dist/collections/mediaCollection.d.ts +16 -0
- package/dist/collections/mediaCollection.js +139 -0
- package/dist/collections/mediaCollection.js.map +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +5 -0
- package/dist/components/mux-preview/index.d.ts +2 -0
- package/dist/components/mux-preview/index.js +3 -0
- package/dist/components/mux-preview/mux-preview.d.ts +14 -0
- package/dist/components/mux-preview/mux-preview.js +38 -0
- package/dist/components/mux-preview/mux-preview.js.map +1 -0
- package/dist/components/upload-handler/index.d.ts +2 -0
- package/dist/components/upload-handler/index.js +3 -0
- package/dist/components/upload-handler/upload-handler.d.ts +22 -0
- package/dist/components/upload-handler/upload-handler.js +178 -0
- package/dist/components/upload-handler/upload-handler.js.map +1 -0
- package/dist/components/upload-manager/index.d.ts +2 -0
- package/dist/components/upload-manager/index.js +3 -0
- package/dist/components/upload-manager/upload-manager-DN4RrmYB.css +204 -0
- package/dist/components/upload-manager/upload-manager-DN4RrmYB.css.map +1 -0
- package/dist/components/upload-manager/upload-manager.css +201 -0
- package/dist/components/upload-manager/upload-manager.d.ts +42 -0
- package/dist/components/upload-manager/upload-manager.js +315 -0
- package/dist/components/upload-manager/upload-manager.js.map +1 -0
- package/dist/components/upload-manager/upload-manager2.js +0 -0
- package/dist/endpoints/muxAssetHandler.d.ts +11 -0
- package/dist/endpoints/muxAssetHandler.js +59 -0
- package/dist/endpoints/muxAssetHandler.js.map +1 -0
- package/dist/endpoints/muxCreateUploadHandler.d.ts +13 -0
- package/dist/endpoints/muxCreateUploadHandler.js +40 -0
- package/dist/endpoints/muxCreateUploadHandler.js.map +1 -0
- package/dist/endpoints/muxWebhookHandler.d.ts +11 -0
- package/dist/endpoints/muxWebhookHandler.js +49 -0
- package/dist/endpoints/muxWebhookHandler.js.map +1 -0
- package/dist/hooks/useEmitter.d.ts +48 -0
- package/dist/hooks/useEmitter.js +19 -0
- package/dist/hooks/useEmitter.js.map +1 -0
- package/dist/hooks/useErrorHandler.d.ts +11 -0
- package/dist/hooks/useErrorHandler.js +19 -0
- package/dist/hooks/useErrorHandler.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/plugin.d.ts +15 -0
- package/dist/plugin.js +242 -0
- package/dist/plugin.js.map +1 -0
- package/dist/tus/stores/s3/expiration-manager.d.ts +36 -0
- package/dist/tus/stores/s3/expiration-manager.js +76 -0
- package/dist/tus/stores/s3/expiration-manager.js.map +1 -0
- package/dist/tus/stores/s3/file-operations.d.ts +66 -0
- package/dist/tus/stores/s3/file-operations.js +90 -0
- package/dist/tus/stores/s3/file-operations.js.map +1 -0
- package/dist/tus/stores/s3/log.d.ts +5 -0
- package/dist/tus/stores/s3/log.js +8 -0
- package/dist/tus/stores/s3/log.js.map +1 -0
- package/dist/tus/stores/s3/metadata-manager.d.ts +85 -0
- package/dist/tus/stores/s3/metadata-manager.js +135 -0
- package/dist/tus/stores/s3/metadata-manager.js.map +1 -0
- package/dist/tus/stores/s3/parts-manager.d.ts +130 -0
- package/dist/tus/stores/s3/parts-manager.js +328 -0
- package/dist/tus/stores/s3/parts-manager.js.map +1 -0
- package/dist/tus/stores/s3/s3-store.d.ts +110 -0
- package/dist/tus/stores/s3/s3-store.js +342 -0
- package/dist/tus/stores/s3/s3-store.js.map +1 -0
- package/dist/tus/stores/s3/semaphore.d.ts +16 -0
- package/dist/tus/stores/s3/semaphore.js +32 -0
- package/dist/tus/stores/s3/semaphore.js.map +1 -0
- package/dist/types/errors.d.ts +26 -0
- package/dist/types/errors.js +28 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/index.d.ts +73 -0
- package/dist/types/index.js +0 -0
- package/dist/utils/file.d.ts +30 -0
- package/dist/utils/file.js +84 -0
- package/dist/utils/file.js.map +1 -0
- package/package.json +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { S3Store } from "../tus/stores/s3/s3-store.js";
|
|
2
|
+
import { Mux as Mux$1 } from "@mux/mux-node";
|
|
3
|
+
import { HandleDelete } from "@payloadcms/plugin-cloud-storage/types";
|
|
4
|
+
|
|
5
|
+
//#region src/adapter/handleDelete.d.ts
|
|
6
|
+
interface HandleDeleteArgs {
|
|
7
|
+
s3Store: S3Store;
|
|
8
|
+
getMuxClient: () => Mux$1;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates a handle delete function for processing file deletions from both Mux and S3 storage
|
|
12
|
+
* @param args - The arguments for creating the delete handler
|
|
13
|
+
* @param args.s3Store - The S3Store instance for S3 file operations
|
|
14
|
+
* @param args.getMuxClient - Function that returns a Mux client instance
|
|
15
|
+
* @returns A HandleDelete function that processes deletion requests based on storage type
|
|
16
|
+
*/
|
|
17
|
+
declare function getHandleDelete(args: HandleDeleteArgs): HandleDelete;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { getHandleDelete };
|
|
20
|
+
//# sourceMappingURL=handleDelete.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { MediaCloudError } from "../types/errors.js";
|
|
2
|
+
import { useErrorHandler } from "../hooks/useErrorHandler.js";
|
|
3
|
+
|
|
4
|
+
//#region src/adapter/handleDelete.ts
|
|
5
|
+
const { logError } = useErrorHandler();
|
|
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
|
+
* Deletes a Mux asset by upload ID
|
|
30
|
+
* @param args - The arguments for deleting the Mux asset
|
|
31
|
+
* @param args.getMuxClient - Function that returns a Mux client instance
|
|
32
|
+
* @param args.uploadId - The upload ID of the Mux asset to delete
|
|
33
|
+
* @returns Promise that resolves when the asset is deleted or rejects on error
|
|
34
|
+
*/
|
|
35
|
+
async function deleteMuxAsset(args) {
|
|
36
|
+
const { getMuxClient, uploadId } = args;
|
|
37
|
+
try {
|
|
38
|
+
const mux = getMuxClient();
|
|
39
|
+
const assets = await mux.video.assets.list({ upload_id: uploadId });
|
|
40
|
+
if (assets.data.length > 0) {
|
|
41
|
+
const asset = assets.data[0];
|
|
42
|
+
await mux.video.assets.delete(asset.id);
|
|
43
|
+
}
|
|
44
|
+
} catch (_error) {
|
|
45
|
+
logError(MediaCloudError.MUX_ASSET_DELETE_ERROR);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Deletes a file from S3 storage including its metadata info file
|
|
50
|
+
* @param args - The arguments for deleting the S3 file
|
|
51
|
+
* @param args.s3Store - The S3Store instance for S3 operations
|
|
52
|
+
* @param args.filename - The filename of the file to delete from S3
|
|
53
|
+
* @returns Promise that resolves when the file is deleted or rejects on error
|
|
54
|
+
*/
|
|
55
|
+
async function deleteS3File(args) {
|
|
56
|
+
const { s3Store, filename } = args;
|
|
57
|
+
try {
|
|
58
|
+
const { client, bucket } = s3Store;
|
|
59
|
+
await client.deleteObjects({
|
|
60
|
+
Bucket: bucket,
|
|
61
|
+
Delete: { Objects: [{ Key: filename }, { Key: `${filename}.info` }] }
|
|
62
|
+
});
|
|
63
|
+
} catch (_error) {
|
|
64
|
+
logError(MediaCloudError.S3_DELETE_ERROR);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { getHandleDelete };
|
|
70
|
+
//# sourceMappingURL=handleDelete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleDelete.js","names":["args: HandleDeleteArgs","args: DeleteMuxAssetArgs","args: DeleteS3FileArgs"],"sources":["../../src/adapter/handleDelete.ts"],"sourcesContent":["import { useErrorHandler } from '../hooks/useErrorHandler'\nimport { MediaCloudError } 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 * 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 if (media?.storage === 'mux' && media.mux?.uploadId) {\n await deleteMuxAsset({ getMuxClient, uploadId: media.mux.uploadId })\n } else if (media.filename) {\n await deleteS3File({ s3Store, filename: media.filename })\n }\n }\n}\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(MediaCloudError.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(MediaCloudError.S3_DELETE_ERROR)\n }\n}\n"],"mappings":";;;;AAuBA,MAAM,EAAE,UAAU,GAAG,iBAAiB;;;;;;;;AAStC,SAAgB,gBAAgBA,MAAsC;CACpE,MAAM,EAAE,SAAS,cAAc,GAAG;AAClC,QAAO,OAAO,EAAE,KAAK,KAAK,KAAK;AAC7B,MAAI,KAAK,WAAW,YAAY,CAAC,IAC/B;EAGF,MAAM,QAAQ;AAEd,MAAI,OAAO,YAAY,SAAS,MAAM,KAAK,UACzC,MAAM,eAAe;GAAE;GAAc,UAAU,MAAM,IAAI;EAAU,EAAC;WAC3D,MAAM,UACf,MAAM,aAAa;GAAE;GAAS,UAAU,MAAM;EAAU,EAAC;CAE5D;AACF;;;;;;;;AASD,eAAe,eAAeC,MAAyC;CACrE,MAAM,EAAE,cAAc,UAAU,GAAG;AAEnC,KAAI;EACF,MAAM,MAAM,cAAc;EAC1B,MAAM,SAAS,MAAM,IAAI,MAAM,OAAO,KAAK,EAAE,WAAW,SAAU,EAAC;AACnE,MAAI,OAAO,KAAK,SAAS,GAAG;GAC1B,MAAM,QAAQ,OAAO,KAAK;GAC1B,MAAM,IAAI,MAAM,OAAO,OAAO,MAAM,GAAG;EACxC;CACF,SAAQ,QAAQ;EACf,SAAS,gBAAgB,uBAAuB;CACjD;AACF;;;;;;;;AASD,eAAe,aAAaC,MAAuC;CACjE,MAAM,EAAE,SAAS,UAAU,GAAG;AAE9B,KAAI;EACF,MAAM,EAAE,QAAQ,QAAQ,GAAG;EAC3B,MAAM,OAAO,cAAc;GACzB,QAAQ;GACR,QAAQ,EACN,SAAS,CAAC,EAAE,KAAK,SAAU,GAAE,EAAE,KAAK,GAAG,SAAS,KAAK,CAAC,CAAE,CAAC,EAC1D;EACF,EAAC;CACH,SAAQ,QAAQ;EACf,SAAS,gBAAgB,gBAAgB;CAC1C;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HandleUpload } from "@payloadcms/plugin-cloud-storage/types";
|
|
2
|
+
|
|
3
|
+
//#region src/adapter/handleUpload.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a handle upload function for processing file uploads to both Mux and S3 storage
|
|
7
|
+
* @returns A HandleUpload function that processes client upload context and updates document data
|
|
8
|
+
*/
|
|
9
|
+
declare function getHandleUpload(): HandleUpload;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { getHandleUpload };
|
|
12
|
+
//# sourceMappingURL=handleUpload.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/adapter/handleUpload.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a handle upload function for processing file uploads to both Mux and S3 storage
|
|
4
|
+
* @returns A HandleUpload function that processes client upload context and updates document data
|
|
5
|
+
*/
|
|
6
|
+
function getHandleUpload() {
|
|
7
|
+
return async function({ clientUploadContext, data }) {
|
|
8
|
+
if (!clientUploadContext) return data;
|
|
9
|
+
const ctx = clientUploadContext;
|
|
10
|
+
data.mimeType = ctx.mimeType;
|
|
11
|
+
switch (ctx.storage) {
|
|
12
|
+
case "mux":
|
|
13
|
+
data.storage = "mux";
|
|
14
|
+
data.mux = {
|
|
15
|
+
uploadId: ctx.uploadId || "",
|
|
16
|
+
status: "preparing"
|
|
17
|
+
};
|
|
18
|
+
break;
|
|
19
|
+
default:
|
|
20
|
+
data.storage = "s3";
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
return data;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { getHandleUpload };
|
|
29
|
+
//# sourceMappingURL=handleUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleUpload.js","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,MAAM,EAAE;AACpD,MAAI,CAAC,oBACH,QAAO;EAGT,MAAM,MAAM;EACZ,KAAK,WAAW,IAAI;AAEpB,UAAQ,IAAI,SAAZ;GACE,KAAK;IACH,KAAK,UAAU;IACf,KAAK,MAAM;KACT,UAAU,IAAI,YAAY;KAC1B,QAAQ;IACT;AACD;GACF;IACE,KAAK,UAAU;AACf;EACH;AAED,SAAO;CACR;AACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { S3Store } from "../tus/stores/s3/s3-store.js";
|
|
2
|
+
import { StaticHandler } from "@payloadcms/plugin-cloud-storage/types";
|
|
3
|
+
|
|
4
|
+
//#region src/adapter/staticHandler.d.ts
|
|
5
|
+
interface StaticHandlerArgs {
|
|
6
|
+
s3Store: S3Store;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates a static handler that serves files from S3 or returns empty responses for Mux assets
|
|
10
|
+
* @param args - The arguments for creating the static handler
|
|
11
|
+
* @param args.s3Store - The S3Store instance used for file operations
|
|
12
|
+
* @returns A StaticHandler function that serves files or empty responses based on storage type
|
|
13
|
+
*/
|
|
14
|
+
declare function getStaticHandler(args: StaticHandlerArgs): StaticHandler;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { getStaticHandler };
|
|
17
|
+
//# sourceMappingURL=staticHandler.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
|
|
3
|
+
//#region src/adapter/staticHandler.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a static handler that serves files from S3 or returns empty responses for Mux assets
|
|
6
|
+
* @param args - The arguments for creating the static handler
|
|
7
|
+
* @param args.s3Store - The S3Store instance used for file operations
|
|
8
|
+
* @returns A StaticHandler function that serves files or empty responses based on storage type
|
|
9
|
+
*/
|
|
10
|
+
function getStaticHandler(args) {
|
|
11
|
+
const { s3Store } = args;
|
|
12
|
+
return async (req, { params }) => {
|
|
13
|
+
const { payload } = req;
|
|
14
|
+
const filename = params.filename;
|
|
15
|
+
const { docs } = await payload.find({
|
|
16
|
+
collection: "media",
|
|
17
|
+
where: { filename: { equals: filename } }
|
|
18
|
+
});
|
|
19
|
+
const doc = docs[0];
|
|
20
|
+
if (!doc) return createEmptyResponse();
|
|
21
|
+
if (doc.storage === "mux") return createEmptyResponse({ mimeType: doc.mimeType });
|
|
22
|
+
return await serveS3File({
|
|
23
|
+
s3Store,
|
|
24
|
+
doc
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates an empty response with appropriate headers
|
|
30
|
+
* @param args - Optional arguments for the empty response
|
|
31
|
+
* @param args.mimeType - The MIME type to set in the Content-Type header
|
|
32
|
+
* @returns A Response object with empty content and appropriate headers
|
|
33
|
+
*/
|
|
34
|
+
function createEmptyResponse(args) {
|
|
35
|
+
const { mimeType = "application/octet-stream" } = args ?? {};
|
|
36
|
+
return new Response(new Uint8Array(0), {
|
|
37
|
+
status: 200,
|
|
38
|
+
headers: {
|
|
39
|
+
"Content-Type": mimeType,
|
|
40
|
+
"Content-Length": "0"
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Serves a file from S3 storage
|
|
46
|
+
* @param args - The arguments for serving the S3 file
|
|
47
|
+
* @param args.s3Store - The S3Store instance to read the file from
|
|
48
|
+
* @param args.doc - The document containing file metadata
|
|
49
|
+
* @returns A Promise that resolves to a Response object containing the file stream or empty response on error
|
|
50
|
+
*/
|
|
51
|
+
async function serveS3File({ s3Store, doc }) {
|
|
52
|
+
try {
|
|
53
|
+
const stream$1 = await s3Store.read(doc.filename);
|
|
54
|
+
if (stream$1) {
|
|
55
|
+
const webStream = Readable.toWeb(stream$1);
|
|
56
|
+
return new Response(webStream);
|
|
57
|
+
}
|
|
58
|
+
} catch (_error) {}
|
|
59
|
+
return createEmptyResponse({});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { getStaticHandler };
|
|
64
|
+
//# sourceMappingURL=staticHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staticHandler.js","names":["args: StaticHandlerArgs","args?: CreateEmptyResponseArgs","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,iBAAiBA,MAAwC;CACvE,MAAM,EAAE,SAAS,GAAG;AACpB,QAAO,OAAO,KAAK,EAAE,QAAQ,KAAK;EAChC,MAAM,EAAE,SAAS,GAAG;EACpB,MAAM,WAAW,OAAO;EAExB,MAAM,EAAE,MAAM,GAAG,MAAM,QAAQ,KAAK;GAClC,YAAY;GACZ,OAAO,EAAE,UAAU,EAAE,QAAQ,SAAU,EAAE;EAC1C,EAAC;EAEF,MAAM,MAAM,KAAK;AAEjB,MAAI,CAAC,IACH,QAAO,qBAAqB;AAG9B,MAAI,IAAI,YAAY,MAClB,QAAO,oBAAoB,EAAE,UAAU,IAAI,SAAU,EAAC;AAGxD,SAAO,MAAM,YAAY;GAAE;GAAS;EAAK,EAAC;CAC3C;AACF;;;;;;;AAQD,SAAS,oBAAoBC,MAA0C;CACrE,MAAM,EAAE,WAAW,4BAA4B,GAAG,QAAQ,CAAE;AAC5D,QAAO,IAAI,SAAS,IAAI,WAAW,IAAI;EACrC,QAAQ;EACR,SAAS;GACP,gBAAgB;GAChB,kBAAkB;EACnB;CACF;AACF;;;;;;;;AASD,eAAe,YAAY,EACzB,SACA,KACgB,EAAqB;AACrC,KAAI;EACF,MAAMC,WAAS,MAAM,QAAQ,KAAK,IAAI,SAAS;AAE/C,MAAIA,UAAQ;GACV,MAAM,YAAY,SAAS,MAAMA,SAAO;AACxC,UAAO,IAAI,SAAS;EACrB;CACF,SAAQ,QAAQ,CAEhB;AAED,QAAO,oBAAoB,CAAE,EAAC;AAC/B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MediaCloudPluginOptions } from "../types/index.js";
|
|
2
|
+
import { S3Store } from "../tus/stores/s3/s3-store.js";
|
|
3
|
+
import { Mux as Mux$1 } from "@mux/mux-node";
|
|
4
|
+
import { Adapter } from "@payloadcms/plugin-cloud-storage/types";
|
|
5
|
+
|
|
6
|
+
//#region src/adapter/storageAdapter.d.ts
|
|
7
|
+
interface StorageAdapterArgs {
|
|
8
|
+
pluginOptions: MediaCloudPluginOptions;
|
|
9
|
+
s3Store: S3Store;
|
|
10
|
+
getMuxClient: () => Mux$1;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates the storage adapter for media cloud plugin
|
|
14
|
+
* @param args - The arguments for creating the storage adapter
|
|
15
|
+
* @param args.pluginOptions - The media cloud plugin options
|
|
16
|
+
* @param args.s3Store - The S3Store instance for file operations
|
|
17
|
+
* @param args.getMuxClient - Function that returns a Mux client instance
|
|
18
|
+
* @returns An Adapter function that returns a GeneratedAdapter configuration
|
|
19
|
+
*/
|
|
20
|
+
declare function getStorageAdapter(args: StorageAdapterArgs): Adapter;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { getStorageAdapter };
|
|
23
|
+
//# sourceMappingURL=storageAdapter.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getHandleUpload } from "./handleUpload.js";
|
|
2
|
+
import { getHandleDelete } from "./handleDelete.js";
|
|
3
|
+
import { getStaticHandler } from "./staticHandler.js";
|
|
4
|
+
|
|
5
|
+
//#region src/adapter/storageAdapter.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates the storage adapter for media cloud plugin
|
|
8
|
+
* @param args - The arguments for creating the storage adapter
|
|
9
|
+
* @param args.pluginOptions - The media cloud plugin options
|
|
10
|
+
* @param args.s3Store - The S3Store instance for file operations
|
|
11
|
+
* @param args.getMuxClient - Function that returns a Mux client instance
|
|
12
|
+
* @returns An Adapter function that returns a GeneratedAdapter configuration
|
|
13
|
+
*/
|
|
14
|
+
function getStorageAdapter(args) {
|
|
15
|
+
const { s3Store, getMuxClient } = args;
|
|
16
|
+
return () => ({
|
|
17
|
+
name: "media-cloud",
|
|
18
|
+
clientUploads: true,
|
|
19
|
+
handleUpload: getHandleUpload(),
|
|
20
|
+
handleDelete: getHandleDelete({
|
|
21
|
+
s3Store,
|
|
22
|
+
getMuxClient
|
|
23
|
+
}),
|
|
24
|
+
staticHandler: getStaticHandler({ s3Store })
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { getStorageAdapter };
|
|
30
|
+
//# sourceMappingURL=storageAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storageAdapter.js","names":["args: StorageAdapterArgs"],"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,kBAAkBA,MAAmC;CACnE,MAAM,EAAE,SAAS,cAAc,GAAG;AAElC,QAAO,OAAyB;EAC9B,MAAM;EACN,eAAe;EACf,cAAc,iBAAiB;EAC/B,cAAc,gBAAgB;GAAE;GAAS;EAAc,EAAC;EACxD,eAAe,iBAAiB,EAAE,QAAS,EAAC;CAC7C;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { S3Store } from "../tus/stores/s3/s3-store.js";
|
|
2
|
+
import { CollectionConfig } from "payload";
|
|
3
|
+
|
|
4
|
+
//#region src/collections/mediaCollection.d.ts
|
|
5
|
+
interface GetMediaCollectionArgs {
|
|
6
|
+
s3Store: S3Store;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates a media collection configuration for Payload CMS
|
|
10
|
+
* @param args - Arguments including the S3Store instance
|
|
11
|
+
* @returns A configured Payload collection for media files
|
|
12
|
+
*/
|
|
13
|
+
declare function getMediaCollection(args: GetMediaCollectionArgs): CollectionConfig;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getMediaCollection };
|
|
16
|
+
//# sourceMappingURL=mediaCollection.d.ts.map
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
//#region src/collections/mediaCollection.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a media collection configuration for Payload CMS
|
|
4
|
+
* @param args - Arguments including the S3Store instance
|
|
5
|
+
* @returns A configured Payload collection for media files
|
|
6
|
+
*/
|
|
7
|
+
function getMediaCollection(args) {
|
|
8
|
+
const { s3Store } = args;
|
|
9
|
+
return {
|
|
10
|
+
slug: "media",
|
|
11
|
+
access: {
|
|
12
|
+
read: () => true,
|
|
13
|
+
delete: () => true
|
|
14
|
+
},
|
|
15
|
+
admin: {
|
|
16
|
+
group: "Media Cloud",
|
|
17
|
+
pagination: { defaultLimit: 50 }
|
|
18
|
+
},
|
|
19
|
+
upload: {
|
|
20
|
+
crop: false,
|
|
21
|
+
displayPreview: true,
|
|
22
|
+
hideRemoveFile: true,
|
|
23
|
+
adminThumbnail({ doc }) {
|
|
24
|
+
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
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
fields: [
|
|
33
|
+
{
|
|
34
|
+
name: "alt",
|
|
35
|
+
label: "Alternative Text",
|
|
36
|
+
type: "text"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "caption",
|
|
40
|
+
label: "Caption",
|
|
41
|
+
type: "text"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "copyright",
|
|
45
|
+
label: "Copyright",
|
|
46
|
+
type: "text"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "storage",
|
|
50
|
+
label: "Storage",
|
|
51
|
+
type: "select",
|
|
52
|
+
options: [{
|
|
53
|
+
label: "Mux",
|
|
54
|
+
value: "mux"
|
|
55
|
+
}, {
|
|
56
|
+
label: "S3",
|
|
57
|
+
value: "s3"
|
|
58
|
+
}],
|
|
59
|
+
admin: { readOnly: true }
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "mux",
|
|
63
|
+
label: "Mux",
|
|
64
|
+
type: "group",
|
|
65
|
+
admin: {
|
|
66
|
+
disableListColumn: true,
|
|
67
|
+
disableBulkEdit: true,
|
|
68
|
+
disableListFilter: true,
|
|
69
|
+
readOnly: true,
|
|
70
|
+
condition: (data) => {
|
|
71
|
+
return data.storage === "mux";
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
fields: [
|
|
75
|
+
{
|
|
76
|
+
name: "preview",
|
|
77
|
+
type: "ui",
|
|
78
|
+
admin: {
|
|
79
|
+
condition: (data) => {
|
|
80
|
+
return data.storage === "mux";
|
|
81
|
+
},
|
|
82
|
+
disableListColumn: true,
|
|
83
|
+
components: { Field: "@maas/payload-plugin-media-cloud/components#MuxPreview" }
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "status",
|
|
88
|
+
label: "Status",
|
|
89
|
+
type: "text"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "uploadId",
|
|
93
|
+
label: "Upload ID",
|
|
94
|
+
type: "text"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "assetId",
|
|
98
|
+
label: "Asset ID",
|
|
99
|
+
type: "text"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "playbackId",
|
|
103
|
+
label: "Playback ID",
|
|
104
|
+
type: "text"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "aspectRatio",
|
|
108
|
+
label: "Aspect Ratio",
|
|
109
|
+
type: "text"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "duration",
|
|
113
|
+
label: "Duration",
|
|
114
|
+
type: "number"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "maxResolutionTier",
|
|
118
|
+
label: "Max Resolution Tier",
|
|
119
|
+
type: "text"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "videoQuality",
|
|
123
|
+
label: "Video Quality",
|
|
124
|
+
type: "text"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: "staticRenditions",
|
|
128
|
+
label: "Static Renditions",
|
|
129
|
+
type: "json"
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
export { getMediaCollection };
|
|
139
|
+
//# sourceMappingURL=mediaCollection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediaCollection.js","names":["args: GetMediaCollectionArgs"],"sources":["../../src/collections/mediaCollection.ts"],"sourcesContent":["import 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}\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 } = args\n\n return {\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 CDN to resize images on the fly like imgix or wsrv let use wesrv for now since its free for all\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 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: '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"],"mappings":";;;;;;AAaA,SAAgB,mBACdA,MACkB;CAClB,MAAM,EAAE,SAAS,GAAG;AAEpB,QAAO;EACL,MAAM;EACN,QAAQ;GACN,MAAM,MAAM;GACZ,QAAQ,MAAM;EACf;EACD,OAAO;GACL,OAAO;GACP,YAAY,EACV,cAAc,GACf;EACF;EACD,QAAQ;GACN,MAAM;GACN,gBAAgB;GAChB,gBAAgB;GAChB,eAAe,EAAE,KAAwB,EAAE;AACzC,QAAI,KAAK,YAAY,SAAS,KAAK,KAAK,WACtC,QAAO,CAAC,sBAAsB,EAAE,IAAI,IAAI,WAAW,gDAAgD,CAAC;aAC3F,KAAK,YAAY,MAAM;KAEhC,MAAM,MAAM,QAAQ,OAAO,IAAI,SAAS;AACxC,YAAO,CAAC,qBAAqB,EAAE,IAAI,+BAA+B,CAAC;IACpE;AACD,WAAO;GACR;EACF;EACD,QAAQ;GACN;IACE,MAAM;IACN,OAAO;IACP,MAAM;GACP;GACD;IACE,MAAM;IACN,OAAO;IACP,MAAM;GACP;GACD;IACE,MAAM;IACN,OAAO;IACP,MAAM;GACP;GACD;IACE,MAAM;IACN,OAAO;IACP,MAAM;IACN,SAAS,CACP;KACE,OAAO;KACP,OAAO;IACR,GACD;KACE,OAAO;KACP,OAAO;IACR,CACF;IACD,OAAO,EACL,UAAU,KACX;GACF;GACD;IACE,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;KACL,mBAAmB;KACnB,iBAAiB;KACjB,mBAAmB;KACnB,UAAU;KACV,WAAW,CAAC,SAAS;AACnB,aAAO,KAAK,YAAY;KACzB;IACF;IACD,QAAQ;KACN;MACE,MAAM;MACN,MAAM;MACN,OAAO;OACL,WAAW,CAAC,SAAS;AACnB,eAAO,KAAK,YAAY;OACzB;OACD,mBAAmB;OACnB,YAAY,EACV,OAAO,yDACR;MACF;KACF;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;KACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;KACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;KACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;KACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;KACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;KACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;KACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;KACP;KACD;MACE,MAAM;MACN,OAAO;MACP,MAAM;KACP;IACF;GACF;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MuxPreview } from "./mux-preview/mux-preview.js";
|
|
2
|
+
import { UploadHandler } from "./upload-handler/upload-handler.js";
|
|
3
|
+
import { UploadManagerProvider, useUploadManagerContext } from "./upload-manager/upload-manager.js";
|
|
4
|
+
export { MuxPreview, UploadHandler, UploadManagerProvider, useUploadManagerContext };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MuxPreview } from "./mux-preview/mux-preview.js";
|
|
2
|
+
import { UploadHandler } from "./upload-handler/upload-handler.js";
|
|
3
|
+
import { UploadManagerProvider, useUploadManagerContext } from "./upload-manager/upload-manager.js";
|
|
4
|
+
|
|
5
|
+
export { MuxPreview, UploadHandler, UploadManagerProvider, useUploadManagerContext };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { UIFieldClientProps } from "payload";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/components/mux-preview/mux-preview.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* React component for previewing Mux video assets
|
|
8
|
+
* @param props - The UI field client props containing field data
|
|
9
|
+
* @returns JSX element for Mux video preview
|
|
10
|
+
*/
|
|
11
|
+
declare function MuxPreview(props: UIFieldClientProps): React.JSX.Element | null;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { MuxPreview };
|
|
14
|
+
//# sourceMappingURL=mux-preview.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import MuxPlayer from "@mux/mux-player-react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
|
|
8
|
+
//#region src/components/mux-preview/mux-preview.tsx
|
|
9
|
+
/**
|
|
10
|
+
* React component for previewing Mux video assets
|
|
11
|
+
* @param props - The UI field client props containing field data
|
|
12
|
+
* @returns JSX element for Mux video preview
|
|
13
|
+
*/
|
|
14
|
+
function MuxPreview(props) {
|
|
15
|
+
const [playbackId, setPlaybackId] = useState(null);
|
|
16
|
+
const [isClient, setIsClient] = useState(false);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setIsClient(true);
|
|
19
|
+
}, []);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!isClient) return;
|
|
22
|
+
const collection = props.schemaPath?.split(".")[0];
|
|
23
|
+
const docId = window.location.pathname.split("/").pop();
|
|
24
|
+
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
|
+
}, [props.schemaPath, isClient]);
|
|
26
|
+
return isClient && playbackId ? /* @__PURE__ */ jsx(MuxPlayer, {
|
|
27
|
+
playbackId,
|
|
28
|
+
streamType: "on-demand",
|
|
29
|
+
disableTracking: true,
|
|
30
|
+
style: { height: "60vh" },
|
|
31
|
+
nohotkeys: true,
|
|
32
|
+
preload: "metadata"
|
|
33
|
+
}) : null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { MuxPreview };
|
|
38
|
+
//# sourceMappingURL=mux-preview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mux-preview.js","names":["props: UIFieldClientProps"],"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,WAAWA,OAA2B;CACpD,MAAM,CAAC,YAAY,cAAc,GAAG,SAAwB,KAAK;CACjE,MAAM,CAAC,UAAU,YAAY,GAAG,SAAS,MAAM;CAG/C,UAAU,MAAM;EACd,YAAY,KAAK;CAClB,GAAE,CAAE,EAAC;CAEN,UAAU,MAAM;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,SACzD,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE,OAAO,CAAC,CACjC,KAAK,CAAC,QAAQ,IAAI,MAAM,CAAC,CACzB,KAAK,CAAC,SAAS,cAAc,KAAK,KAAK,cAAc,KAAK,CAAC,CAC3D,MAAM,MAAM,cAAc,KAAK,CAAC;CAEtC,GAAE,CAAC,MAAM,YAAY,QAAS,EAAC;AAGhC,QAAO,YAAY,iCAChB;EACa;EACZ,YAAW;EACX,iBAAiB;EACjB,OAAO,EAAE,QAAQ,OAAQ;EACzB,WAAW;EACX,SAAQ;GACR,GACA;AACL"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as payload0 from "payload";
|
|
2
|
+
import * as react0 from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/components/upload-handler/upload-handler.d.ts
|
|
5
|
+
declare const UploadHandler: ({
|
|
6
|
+
children,
|
|
7
|
+
collectionSlug,
|
|
8
|
+
enabled,
|
|
9
|
+
extra,
|
|
10
|
+
prefix,
|
|
11
|
+
serverHandlerPath
|
|
12
|
+
}: {
|
|
13
|
+
children: react0.ReactNode;
|
|
14
|
+
collectionSlug: payload0.UploadCollectionSlug;
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
extra: Record<string, unknown>;
|
|
17
|
+
prefix?: string;
|
|
18
|
+
serverHandlerPath: string;
|
|
19
|
+
}) => react0.JSX.Element;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { UploadHandler };
|
|
22
|
+
//# sourceMappingURL=upload-handler.d.ts.map
|