@maas/payload-plugin-media-cloud 0.0.34 → 0.0.36
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/storageAdapter.mjs +10 -2
- package/dist/adapter/storageAdapter.mjs.map +1 -1
- package/dist/collectionHooks/afterChange.mjs +1 -1
- package/dist/collectionHooks/afterChange.mjs.map +1 -1
- package/dist/components/folderFileCard/folderFileCard.mjs +13 -1
- package/dist/components/folderFileCard/folderFileCard.mjs.map +1 -1
- package/dist/components/gridContext/gridContext.mjs +52 -51
- package/dist/components/gridContext/gridContext.mjs.map +1 -1
- package/dist/components/gridView/gridView.mjs +96 -13
- package/dist/components/gridView/gridView.mjs.map +1 -1
- package/dist/components/itemCardGrid/itemCardGrid.mjs +15 -5
- package/dist/components/itemCardGrid/itemCardGrid.mjs.map +1 -1
- package/dist/components/muxPreview/muxPreview.mjs +9 -1
- package/dist/components/muxPreview/muxPreview.mjs.map +1 -1
- package/dist/components/uploadHandler/uploadHandler.mjs.map +1 -1
- package/dist/components/uploadManager/uploadManager.mjs +101 -5
- package/dist/components/uploadManager/uploadManager.mjs.map +1 -1
- package/dist/fields/path.mjs +5 -1
- package/dist/fields/path.mjs.map +1 -1
- package/dist/types/index.d.mts +3 -0
- package/dist/utils/buildThumbnailURL.mjs +1 -1
- package/dist/utils/buildThumbnailURL.mjs.map +1 -1
- package/dist/utils/defaultOptions.mjs +2 -1
- package/dist/utils/defaultOptions.mjs.map +1 -1
- package/dist/utils/file.d.mts +2 -2
- package/dist/utils/file.mjs.map +1 -1
- package/dist/utils/mux.d.mts +3 -3
- package/dist/utils/mux.mjs.map +1 -1
- package/dist/utils/tus.d.mts +3 -3
- package/dist/utils/tus.mjs.map +1 -1
- package/package.json +3 -1
package/dist/fields/path.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.mjs","names":["pathField: TextField"],"sources":["../../src/fields/path.ts"],"sourcesContent":["import type { TextField } from 'payload'\n\nexport const pathField: TextField = {\n type: 'text',\n name: 'path',\n unique: true,\n admin: {\n hidden: true,\n readOnly: true,\n },\n}\n"],"mappings":";AAEA,MAAaA,YAAuB;CAClC,MAAM;CACN,MAAM;CACN,QAAQ;CACR,OAAO;EACL,QAAQ;EACR,UAAU;
|
|
1
|
+
{"version":3,"file":"path.mjs","names":["pathField: TextField"],"sources":["../../src/fields/path.ts"],"sourcesContent":["import type { TextField } from 'payload'\n\nexport const pathField: TextField = {\n type: 'text',\n name: 'path',\n unique: true,\n admin: {\n hidden: true,\n readOnly: true,\n disableListColumn: true,\n disableListFilter: true,\n disableBulkEdit: true,\n disableGroupBy: true,\n },\n}\n"],"mappings":";AAEA,MAAaA,YAAuB;CAClC,MAAM;CACN,MAAM;CACN,QAAQ;CACR,OAAO;EACL,QAAQ;EACR,UAAU;EACV,mBAAmB;EACnB,mBAAmB;EACnB,iBAAiB;EACjB,gBAAgB;EACjB;CACF"}
|
package/dist/types/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/utils/buildThumbnailURL.ts
|
|
2
2
|
function buildThumbnailURL(args) {
|
|
3
3
|
const { storage, s3Store, playbackId, s3Key } = args;
|
|
4
|
-
if (storage === "mux" && playbackId) return `https://image.mux.com/${playbackId}/thumbnail.jpg?width=
|
|
4
|
+
if (storage === "mux" && playbackId) return `https://image.mux.com/${playbackId}/thumbnail.jpg?width=400&height=400&fit_mode=pad`;
|
|
5
5
|
if (storage === "s3" && s3Key) return `https://wsrv.nl/?url=${s3Store?.getUrl(s3Key)}?width=512&height=512&default=1&q=80`;
|
|
6
6
|
}
|
|
7
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildThumbnailURL.mjs","names":[],"sources":["../../src/utils/buildThumbnailURL.ts"],"sourcesContent":["import type { S3Store } from '../tus/stores/s3/s3Store'\nimport type { Storage } from '../types'\n\ninterface BuildThumbnailURLArgs {\n storage: Storage\n playbackId?: string\n s3Key?: string\n s3Store?: S3Store | null\n}\n\nexport function buildThumbnailURL(args: BuildThumbnailURLArgs) {\n const { storage, s3Store, playbackId, s3Key } = args\n\n if (storage === 'mux' && playbackId) {\n return `https://image.mux.com/${playbackId}/thumbnail.jpg?width=
|
|
1
|
+
{"version":3,"file":"buildThumbnailURL.mjs","names":[],"sources":["../../src/utils/buildThumbnailURL.ts"],"sourcesContent":["import type { S3Store } from '../tus/stores/s3/s3Store'\nimport type { Storage } from '../types'\n\ninterface BuildThumbnailURLArgs {\n storage: Storage\n playbackId?: string\n s3Key?: string\n s3Store?: S3Store | null\n}\n\nexport function buildThumbnailURL(args: BuildThumbnailURLArgs) {\n const { storage, s3Store, playbackId, s3Key } = args\n\n if (storage === 'mux' && playbackId) {\n return `https://image.mux.com/${playbackId}/thumbnail.jpg?width=400&height=400&fit_mode=pad`\n }\n\n if (storage === 's3' && s3Key) {\n const url = s3Store?.getUrl(s3Key)\n return `https://wsrv.nl/?url=${url}?width=512&height=512&default=1&q=80`\n }\n}\n"],"mappings":";AAUA,SAAgB,kBAAkB,MAA6B;CAC7D,MAAM,EAAE,SAAS,SAAS,YAAY,UAAU;AAEhD,KAAI,YAAY,SAAS,WACvB,QAAO,yBAAyB,WAAW;AAG7C,KAAI,YAAY,QAAQ,MAEtB,QAAO,wBADK,SAAS,OAAO,MAAM,CACC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultOptions.mjs","names":["defaultOptions: MediaCloudDefaultPluginOptions"],"sources":["../../src/utils/defaultOptions.ts"],"sourcesContent":["import { MediaCloudDefaultPluginOptions } from '../types'\n\nexport const defaultOptions: MediaCloudDefaultPluginOptions = {\n enabled: true,\n collection: 'media',\n view: 'grid',\n folders: true,\n storage: {\n 'video/*': 'mux',\n },\n}\n"],"mappings":";AAEA,MAAaA,iBAAiD;CAC5D,SAAS;CACT,YAAY;CACZ,MAAM;CACN,SAAS;CACT,SAAS,EACP,WAAW,OACZ;CACF"}
|
|
1
|
+
{"version":3,"file":"defaultOptions.mjs","names":["defaultOptions: MediaCloudDefaultPluginOptions"],"sources":["../../src/utils/defaultOptions.ts"],"sourcesContent":["import { MediaCloudDefaultPluginOptions } from '../types'\n\nexport const defaultOptions: MediaCloudDefaultPluginOptions = {\n enabled: true,\n collection: 'media',\n view: 'grid',\n folders: true,\n storage: {\n 'video/*': 'mux',\n },\n limits: {\n mimeTypes: ['image/*', 'video/*'],\n },\n}\n"],"mappings":";AAEA,MAAaA,iBAAiD;CAC5D,SAAS;CACT,YAAY;CACZ,MAAM;CACN,SAAS;CACT,SAAS,EACP,WAAW,OACZ;CACD,QAAQ,EACN,WAAW,CAAC,WAAW,UAAU,EAClC;CACF"}
|
package/dist/utils/file.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MediaCloudPluginOptions, MimeType } from "../types/index.mjs";
|
|
2
2
|
import { S3Store } from "../tus/stores/s3/s3Store.mjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as payload1 from "payload";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/file.d.ts
|
|
6
6
|
|
|
@@ -35,7 +35,7 @@ interface CreateFileEndpointsArgs {
|
|
|
35
35
|
pluginOptions: MediaCloudPluginOptions;
|
|
36
36
|
}
|
|
37
37
|
declare function createFileEndpoints(args: CreateFileEndpointsArgs): {
|
|
38
|
-
handler:
|
|
38
|
+
handler: payload1.PayloadHandler;
|
|
39
39
|
method: "get";
|
|
40
40
|
path: string;
|
|
41
41
|
}[];
|
package/dist/utils/file.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.mjs","names":["magicError: UseMagicErrorReturn"],"sources":["../../src/utils/file.ts"],"sourcesContent":["import { fileTypeFromBuffer } from 'file-type'\nimport { parse } from 'pathe'\n\nimport { getFileExistsHandler } from '../endpoints/fileExistsHandler'\nimport {
|
|
1
|
+
{"version":3,"file":"file.mjs","names":["magicError: UseMagicErrorReturn"],"sources":["../../src/utils/file.ts"],"sourcesContent":["import { fileTypeFromBuffer } from 'file-type'\nimport { parse } from 'pathe'\n\nimport { getFileExistsHandler } from '../endpoints/fileExistsHandler'\n\nimport { useMagicError, type UseMagicErrorReturn } from '@maas/error-handler'\nimport { MediaCloudErrors } from '../types/errors'\n\nimport type { S3Store } from '../tus/stores/s3/s3Store'\nimport type { MediaCloudPluginOptions, MimeType } from '../types'\n\nconst magicError: UseMagicErrorReturn = useMagicError({\n prefix: 'PLUGIN-MEDIA-CLOUD',\n})\n\nconst { logError, throwError } = magicError\n\nconst MUX_SUPPORTED_VIDEO_FORMATS = new Set([\n 'application/mxf',\n 'video/3gpp',\n 'video/3gpp2',\n 'video/mp2t',\n 'video/mp4',\n 'video/mpeg',\n 'video/quicktime',\n 'video/webm',\n 'video/x-f4v',\n 'video/x-flv',\n 'video/x-matroska',\n 'video/x-ms-asf',\n 'video/x-ms-wmv',\n 'video/x-msvideo',\n 'video/x-mxf',\n])\n\n/**\n * Checks if a file is a video file supported by Mux\n * @param file - The file to check\n * @returns Promise that resolves to true if the file is a supported video format, false otherwise\n */\nexport async function isVideo(file: File): Promise<boolean> {\n try {\n const buffer = new Uint8Array(await file.arrayBuffer())\n const fileType = await fileTypeFromBuffer(buffer)\n\n return fileType?.mime\n ? MUX_SUPPORTED_VIDEO_FORMATS.has(fileType.mime)\n : false\n } catch {\n return false\n }\n}\n\nconst allowedMimeTypes = new Set<MimeType>([\n 'application/mxf',\n 'video/3gpp',\n 'video/3gpp2',\n 'video/mp2t',\n 'video/mp4',\n 'video/mpeg',\n 'video/quicktime',\n 'video/webm',\n 'video/x-f4v',\n 'video/x-flv',\n 'video/x-matroska',\n 'video/x-ms-asf',\n 'video/x-ms-wmv',\n 'video/x-msvideo',\n 'video/x-mxf',\n 'image/apng',\n 'image/avif',\n 'image/gif',\n 'image/jpeg',\n 'image/png',\n 'image/svg+xml',\n 'image/webp',\n])\n\n/**\n * Check the mime type against allowed mime types\n * @param mimeType - The file to check\n */\nfunction validateMimeType(mimeType: string) {\n if (!allowedMimeTypes.has(mimeType as MimeType)) {\n throwError(MediaCloudErrors.FILE_TYPE_UNSUPPORTED_ERROR)\n }\n}\n\n/**\n * Gets the MIME type of a file using file-type library\n * @param file - The file to check\n * @returns Promise that resolves to the MIME type of the file or undefined if it cannot be determined\n */\nexport async function getMimeType(file: File): Promise<MimeType | undefined> {\n try {\n const buffer = new Uint8Array(await file.arrayBuffer())\n const fileType = await fileTypeFromBuffer(buffer)\n\n if (!fileType?.mime) {\n logError(MediaCloudErrors.FILE_TYPE_ERROR.message)\n return undefined\n }\n\n validateMimeType(fileType.mime)\n return fileType.mime as MimeType\n } catch (_error) {\n logError(MediaCloudErrors.FILE_TYPE_ERROR.message)\n return undefined\n }\n}\n\n/**\n * Generates a unique filename by appending a random suffix if needed\n * @param originalFilename - The original filename\n * @returns A unique filename with a random suffix appended before the extension\n */\nexport function generateUniqueFilename(originalFilename: string): string {\n const timestamp = Date.now().toString(36)\n // Parse name and extension\n const { name, ext } = parse(originalFilename)\n\n // Sanitize name\n const sanitizedName = sanitizeFilename(name)\n\n return `${sanitizedName}-${timestamp}${ext}`\n}\n\n/**\n * Sanitizes a filename by removing/replacing invalid characters and handling edge cases\n * Converts all non-alphanumeric characters (except dots for extensions) to underscores\n * @param filename - The filename to sanitize\n * @returns A sanitized filename safe for all operating systems\n * @throws {TypeError} When filename is not a string\n */\nexport function sanitizeFilename(filename: string): string {\n try {\n const parsed = parse(filename)\n const sanitized = parsed.name\n .replace(/[^a-zA-Z0-9_.-]/g, '_')\n .replace(/_{2,}/g, '_')\n .replace(/^_|_$/g, '')\n return `${sanitized}${parsed.ext}`\n } catch (_error) {\n logError(MediaCloudErrors.FILENAME_SANITIZE_ERROR.message)\n return filename\n }\n}\n\ninterface CreateFileEndpointsArgs {\n getS3Store: () => S3Store\n pluginOptions: MediaCloudPluginOptions\n}\n\nexport function createFileEndpoints(args: CreateFileEndpointsArgs) {\n const { getS3Store, pluginOptions } = args\n\n const collection = pluginOptions.collection\n magicError.assert(collection, MediaCloudErrors.COLLECTION_REQUIRED)\n\n return [\n {\n handler: getFileExistsHandler({ getS3Store, collection }),\n method: 'get' as const,\n path: '/uploads/:filename/exists',\n },\n ]\n}\n"],"mappings":";;;;;;;AAWA,MAAMA,aAAkC,cAAc,EACpD,QAAQ,sBACT,CAAC;AAEF,MAAM,EAAE,UAAU,eAAe;AAEjC,MAAM,8BAA8B,IAAI,IAAI;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;AAOF,eAAsB,QAAQ,MAA8B;AAC1D,KAAI;EAEF,MAAM,WAAW,MAAM,mBADR,IAAI,WAAW,MAAM,KAAK,aAAa,CAAC,CACN;AAEjD,SAAO,UAAU,OACb,4BAA4B,IAAI,SAAS,KAAK,GAC9C;SACE;AACN,SAAO;;;AAIX,MAAM,mBAAmB,IAAI,IAAc;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;AAMF,SAAS,iBAAiB,UAAkB;AAC1C,KAAI,CAAC,iBAAiB,IAAI,SAAqB,CAC7C,YAAW,iBAAiB,4BAA4B;;;;;;;AAS5D,eAAsB,YAAY,MAA2C;AAC3E,KAAI;EAEF,MAAM,WAAW,MAAM,mBADR,IAAI,WAAW,MAAM,KAAK,aAAa,CAAC,CACN;AAEjD,MAAI,CAAC,UAAU,MAAM;AACnB,YAAS,iBAAiB,gBAAgB,QAAQ;AAClD;;AAGF,mBAAiB,SAAS,KAAK;AAC/B,SAAO,SAAS;UACT,QAAQ;AACf,WAAS,iBAAiB,gBAAgB,QAAQ;AAClD;;;;;;;;AASJ,SAAgB,uBAAuB,kBAAkC;CACvE,MAAM,YAAY,KAAK,KAAK,CAAC,SAAS,GAAG;CAEzC,MAAM,EAAE,MAAM,QAAQ,MAAM,iBAAiB;AAK7C,QAAO,GAFe,iBAAiB,KAAK,CAEpB,GAAG,YAAY;;;;;;;;;AAUzC,SAAgB,iBAAiB,UAA0B;AACzD,KAAI;EACF,MAAM,SAAS,MAAM,SAAS;AAK9B,SAAO,GAJW,OAAO,KACtB,QAAQ,oBAAoB,IAAI,CAChC,QAAQ,UAAU,IAAI,CACtB,QAAQ,UAAU,GAAG,GACF,OAAO;UACtB,QAAQ;AACf,WAAS,iBAAiB,wBAAwB,QAAQ;AAC1D,SAAO;;;AASX,SAAgB,oBAAoB,MAA+B;CACjE,MAAM,EAAE,YAAY,kBAAkB;CAEtC,MAAM,aAAa,cAAc;AACjC,YAAW,OAAO,YAAY,iBAAiB,oBAAoB;AAEnE,QAAO,CACL;EACE,SAAS,qBAAqB;GAAE;GAAY;GAAY,CAAC;EACzD,QAAQ;EACR,MAAM;EACP,CACF"}
|
package/dist/utils/mux.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MediaCloudPluginOptions } from "../types/index.mjs";
|
|
2
2
|
import Mux from "@mux/mux-node";
|
|
3
|
-
import * as
|
|
3
|
+
import * as payload0 from "payload";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/mux.d.ts
|
|
6
6
|
|
|
@@ -14,11 +14,11 @@ interface CreateMuxEndpointsArgs {
|
|
|
14
14
|
pluginOptions: MediaCloudPluginOptions;
|
|
15
15
|
}
|
|
16
16
|
declare function createMuxEndpoints(args: CreateMuxEndpointsArgs): ({
|
|
17
|
-
handler:
|
|
17
|
+
handler: payload0.PayloadHandler;
|
|
18
18
|
method: "post";
|
|
19
19
|
path: string;
|
|
20
20
|
} | {
|
|
21
|
-
handler:
|
|
21
|
+
handler: payload0.PayloadHandler;
|
|
22
22
|
method: "get";
|
|
23
23
|
path: string;
|
|
24
24
|
})[];
|
package/dist/utils/mux.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mux.mjs","names":["magicError: UseMagicErrorReturn"],"sources":["../../src/utils/mux.ts"],"sourcesContent":["import Mux from '@mux/mux-node'\n\nimport {
|
|
1
|
+
{"version":3,"file":"mux.mjs","names":["magicError: UseMagicErrorReturn"],"sources":["../../src/utils/mux.ts"],"sourcesContent":["import Mux from '@mux/mux-node'\n\nimport { getMuxAssetHandler } from '../endpoints/muxAssetHandler'\nimport { getMuxCreateUploadHandler } from '../endpoints/muxCreateUploadHandler'\nimport { getMuxWebhookHandler } from '../endpoints/muxWebhookHandler'\n\nimport { useMagicError, type UseMagicErrorReturn } from '@maas/error-handler'\nimport { MediaCloudErrors } from '../types/errors'\n\nimport type { MediaCloudPluginOptions } from '../types'\n\nconst magicError: UseMagicErrorReturn = useMagicError({\n prefix: 'PLUGIN-MEDIA-CLOUD',\n})\n\n/**\n * Creates Mux-related endpoints for asset handling\n * @param args - The arguments for creating Mux endpoints\n * @returns An array of Mux endpoint configurations\n */\ninterface CreateMuxEndpointsArgs {\n getMuxClient: () => Mux\n pluginOptions: MediaCloudPluginOptions\n}\n\nexport function createMuxEndpoints(args: CreateMuxEndpointsArgs) {\n const { getMuxClient, pluginOptions } = args\n\n const collection = pluginOptions.collection\n magicError.assert(collection, MediaCloudErrors.COLLECTION_REQUIRED)\n\n return [\n {\n handler: getMuxWebhookHandler({ getMuxClient, collection }),\n method: 'post' as const,\n path: '/mux/webhook',\n },\n {\n handler: getMuxCreateUploadHandler({ getMuxClient, pluginOptions }),\n method: 'post' as const,\n path: '/mux/upload',\n },\n {\n handler: getMuxAssetHandler({ getMuxClient, collection }),\n method: 'get' as const,\n path: '/mux/asset',\n },\n ]\n}\n\n/**\n * Validates Mux configuration options\n * @param muxConfig - The Mux configuration to validate\n * @throws {Error} When required Mux configuration is missing\n */\nexport function validateMuxConfig(\n muxConfig: MediaCloudPluginOptions['mux']\n): void {\n magicError.assert(muxConfig, MediaCloudErrors.MUX_CONFIG_INCOMPLETE)\n magicError.assert(muxConfig?.tokenId, MediaCloudErrors.MUX_CONFIG_MISSING)\n magicError.assert(muxConfig?.tokenSecret, MediaCloudErrors.MUX_CONFIG_MISSING)\n}\n\n/**\n * Creates a new Mux client instance\n * @param muxConfig - The Mux configuration options\n * @returns A configured Mux client\n */\nexport function createMuxClient(\n muxConfig: MediaCloudPluginOptions['mux']\n): Mux {\n validateMuxConfig(muxConfig)\n\n return new Mux({\n tokenId: muxConfig?.tokenId,\n tokenSecret: muxConfig?.tokenSecret,\n webhookSecret: muxConfig?.webhookSecret,\n })\n}\n"],"mappings":";;;;;;;;AAWA,MAAMA,aAAkC,cAAc,EACpD,QAAQ,sBACT,CAAC;AAYF,SAAgB,mBAAmB,MAA8B;CAC/D,MAAM,EAAE,cAAc,kBAAkB;CAExC,MAAM,aAAa,cAAc;AACjC,YAAW,OAAO,YAAY,iBAAiB,oBAAoB;AAEnE,QAAO;EACL;GACE,SAAS,qBAAqB;IAAE;IAAc;IAAY,CAAC;GAC3D,QAAQ;GACR,MAAM;GACP;EACD;GACE,SAAS,0BAA0B;IAAE;IAAc;IAAe,CAAC;GACnE,QAAQ;GACR,MAAM;GACP;EACD;GACE,SAAS,mBAAmB;IAAE;IAAc;IAAY,CAAC;GACzD,QAAQ;GACR,MAAM;GACP;EACF;;;;;;;AAQH,SAAgB,kBACd,WACM;AACN,YAAW,OAAO,WAAW,iBAAiB,sBAAsB;AACpE,YAAW,OAAO,WAAW,SAAS,iBAAiB,mBAAmB;AAC1E,YAAW,OAAO,WAAW,aAAa,iBAAiB,mBAAmB;;;;;;;AAQhF,SAAgB,gBACd,WACK;AACL,mBAAkB,UAAU;AAE5B,QAAO,IAAI,IAAI;EACb,SAAS,WAAW;EACpB,aAAa,WAAW;EACxB,eAAe,WAAW;EAC3B,CAAC"}
|
package/dist/utils/tus.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaCloudPluginOptions } from "../types/index.mjs";
|
|
2
2
|
import { S3Store } from "../tus/stores/s3/s3Store.mjs";
|
|
3
3
|
import { Server } from "@tus/server";
|
|
4
|
-
import * as
|
|
4
|
+
import * as payload2 from "payload";
|
|
5
5
|
import { PayloadRequest } from "payload";
|
|
6
6
|
|
|
7
7
|
//#region src/utils/tus.d.ts
|
|
@@ -45,11 +45,11 @@ declare function createTusEndpoints(args: CreateTusEndpointsArgs): ({
|
|
|
45
45
|
method: "delete";
|
|
46
46
|
path: string;
|
|
47
47
|
} | {
|
|
48
|
-
handler:
|
|
48
|
+
handler: payload2.PayloadHandler;
|
|
49
49
|
method: "get";
|
|
50
50
|
path: string;
|
|
51
51
|
} | {
|
|
52
|
-
handler:
|
|
52
|
+
handler: payload2.PayloadHandler;
|
|
53
53
|
method: "post";
|
|
54
54
|
path: string;
|
|
55
55
|
})[];
|
package/dist/utils/tus.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tus.mjs","names":["magicError: UseMagicErrorReturn","TusServer"],"sources":["../../src/utils/tus.ts"],"sourcesContent":["import { Server as TusServer } from '@tus/server'\n\nimport { getTusPostProcessorHandler } from '../endpoints/tusPostProcessorHandler'\nimport { getTusFolderHandler } from '../endpoints/tusFolderHandler'\nimport { getTusCleanupHandler } from '../endpoints/tusCleanupHandler'\
|
|
1
|
+
{"version":3,"file":"tus.mjs","names":["magicError: UseMagicErrorReturn","TusServer"],"sources":["../../src/utils/tus.ts"],"sourcesContent":["import { Server as TusServer } from '@tus/server'\n\nimport { getTusPostProcessorHandler } from '../endpoints/tusPostProcessorHandler'\nimport { getTusFolderHandler } from '../endpoints/tusFolderHandler'\nimport { getTusCleanupHandler } from '../endpoints/tusCleanupHandler'\nimport { generateUniqueFilename } from './file'\n\nimport { useMagicError, type UseMagicErrorReturn } from '@maas/error-handler'\nimport { MediaCloudErrors } from '../types/errors'\n\nimport type { PayloadRequest } from 'payload'\nimport type { S3Store } from '../tus/stores/s3/s3Store'\nimport type { MediaCloudPluginOptions } from '../types'\n\nconst magicError: UseMagicErrorReturn = useMagicError({\n prefix: 'PLUGIN-MEDIA-CLOUD',\n})\n\n/**\n * Creates a TUS server instance with S3 storage\n * @param args.getS3Store - Function that returns an S3 client instance\n * @param args.pluginOptions - Media cloud plugin options\n * @returns A configured TusServer instance\n */\ninterface CreateTusServerArgs {\n getS3Store: () => S3Store\n pluginOptions: MediaCloudPluginOptions\n}\n\nexport function createTusServer(args: CreateTusServerArgs): TusServer {\n const { getS3Store, pluginOptions } = args\n\n const s3Store = getS3Store()\n\n return new TusServer({\n datastore: s3Store,\n path: '/api/uploads',\n respectForwardedHeaders: pluginOptions.s3?.respectForwardedHeaders ?? true,\n namingFunction: async (_req, metadata) => {\n return metadata?.filename ?? generateUniqueFilename('')\n },\n onUploadFinish: async (_req, upload) => {\n // Clean up .part and .info files\n const filename = upload.metadata?.filename ?? ''\n await s3Store.cleanup(filename)\n\n // Prevent type error\n return Promise.resolve({})\n },\n })\n}\n\n/**\n * Creates TUS upload endpoints for file handling\n * @param args.getTusServer - Function that returns a TUS server instance\n * @param args.getS3Store - Function that returns an S3 client instance\n * @returns An array of endpoint configurations\n */\ninterface CreateTusEndpointsArgs {\n getTusServer: () => TusServer\n getS3Store: () => S3Store\n pluginOptions: MediaCloudPluginOptions\n}\n\nexport function createTusEndpoints(args: CreateTusEndpointsArgs) {\n const { getTusServer, getS3Store, pluginOptions } = args\n\n const collection = pluginOptions.collection\n magicError.assert(collection, MediaCloudErrors.COLLECTION_REQUIRED)\n\n /**\n * Handles TUS requests through the server\n * @param req - The payload request object\n * @returns The server response\n */\n function tusHandler(req: PayloadRequest) {\n return getTusServer().handleWeb(req as Request)\n }\n\n return [\n { handler: tusHandler, method: 'options' as const, path: '/uploads' },\n { handler: tusHandler, method: 'post' as const, path: '/uploads' },\n { handler: tusHandler, method: 'get' as const, path: '/uploads/:id' },\n { handler: tusHandler, method: 'put' as const, path: '/uploads/:id' },\n { handler: tusHandler, method: 'patch' as const, path: '/uploads/:id' },\n { handler: tusHandler, method: 'delete' as const, path: '/uploads/:id' },\n {\n handler: getTusPostProcessorHandler({ getS3Store, collection }),\n method: 'get' as const,\n path: '/uploads/:filename/process',\n },\n {\n handler: getTusFolderHandler({ getS3Store, collection }),\n method: 'get' as const,\n path: '/uploads/:filename/folder',\n },\n {\n handler: getTusCleanupHandler({ getS3Store, collection }),\n method: 'post' as const,\n path: '/uploads/cleanup',\n },\n ]\n}\n"],"mappings":";;;;;;;;;AAcA,MAAMA,aAAkC,cAAc,EACpD,QAAQ,sBACT,CAAC;AAaF,SAAgB,gBAAgB,MAAsC;CACpE,MAAM,EAAE,YAAY,kBAAkB;CAEtC,MAAM,UAAU,YAAY;AAE5B,QAAO,IAAIC,OAAU;EACnB,WAAW;EACX,MAAM;EACN,yBAAyB,cAAc,IAAI,2BAA2B;EACtE,gBAAgB,OAAO,MAAM,aAAa;AACxC,UAAO,UAAU,YAAY,uBAAuB,GAAG;;EAEzD,gBAAgB,OAAO,MAAM,WAAW;GAEtC,MAAM,WAAW,OAAO,UAAU,YAAY;AAC9C,SAAM,QAAQ,QAAQ,SAAS;AAG/B,UAAO,QAAQ,QAAQ,EAAE,CAAC;;EAE7B,CAAC;;AAeJ,SAAgB,mBAAmB,MAA8B;CAC/D,MAAM,EAAE,cAAc,YAAY,kBAAkB;CAEpD,MAAM,aAAa,cAAc;AACjC,YAAW,OAAO,YAAY,iBAAiB,oBAAoB;;;;;;CAOnE,SAAS,WAAW,KAAqB;AACvC,SAAO,cAAc,CAAC,UAAU,IAAe;;AAGjD,QAAO;EACL;GAAE,SAAS;GAAY,QAAQ;GAAoB,MAAM;GAAY;EACrE;GAAE,SAAS;GAAY,QAAQ;GAAiB,MAAM;GAAY;EAClE;GAAE,SAAS;GAAY,QAAQ;GAAgB,MAAM;GAAgB;EACrE;GAAE,SAAS;GAAY,QAAQ;GAAgB,MAAM;GAAgB;EACrE;GAAE,SAAS;GAAY,QAAQ;GAAkB,MAAM;GAAgB;EACvE;GAAE,SAAS;GAAY,QAAQ;GAAmB,MAAM;GAAgB;EACxE;GACE,SAAS,2BAA2B;IAAE;IAAY;IAAY,CAAC;GAC/D,QAAQ;GACR,MAAM;GACP;EACD;GACE,SAAS,oBAAoB;IAAE;IAAY;IAAY,CAAC;GACxD,QAAQ;GACR,MAAM;GACP;EACD;GACE,SAAS,qBAAqB;IAAE;IAAY;IAAY,CAAC;GACzD,QAAQ;GACR,MAAM;GACP;EACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maas/payload-plugin-media-cloud",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.36",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
@@ -67,6 +67,8 @@
|
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
+
"@babel/preset-react": "^7.28.5",
|
|
71
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
70
72
|
"@mux/mux-player-react": "^3.9.2",
|
|
71
73
|
"@payloadcms/plugin-cloud-storage": "3.75.0",
|
|
72
74
|
"@payloadcms/translations": "3.75.0",
|