@maas/payload-plugin-media-cloud 0.0.10 → 0.0.14
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.mjs +31 -24
- package/dist/adapter/handleDelete.mjs.map +1 -1
- package/dist/adapter/handleUpload.mjs +1 -1
- package/dist/adapter/handleUpload.mjs.map +1 -1
- package/dist/collections/mediaCollection.d.mts +1 -0
- package/dist/collections/mediaCollection.mjs +8 -2
- package/dist/collections/mediaCollection.mjs.map +1 -1
- package/dist/components/upload-handler/upload-handler.mjs +31 -33
- package/dist/components/upload-handler/upload-handler.mjs.map +1 -1
- package/dist/components/upload-manager/upload-manager.d.mts +4 -14
- package/dist/components/upload-manager/upload-manager.mjs +35 -36
- package/dist/components/upload-manager/upload-manager.mjs.map +1 -1
- package/dist/endpoints/muxAssetHandler.mjs +13 -9
- package/dist/endpoints/muxAssetHandler.mjs.map +1 -1
- package/dist/endpoints/muxCreateUploadHandler.mjs +1 -1
- package/dist/endpoints/muxCreateUploadHandler.mjs.map +1 -1
- package/dist/endpoints/muxWebhookHandler.mjs +46 -20
- package/dist/endpoints/muxWebhookHandler.mjs.map +1 -1
- package/dist/endpoints/tusPostProcessorHandler.mjs +7 -9
- package/dist/endpoints/tusPostProcessorHandler.mjs.map +1 -1
- package/dist/error-handler/dist/index.mjs +84 -64
- package/dist/error-handler/dist/index.mjs.map +1 -1
- package/dist/hooks/useErrorHandler.d.mts +2 -172
- package/dist/hooks/useErrorHandler.mjs +4 -9
- package/dist/hooks/useErrorHandler.mjs.map +1 -1
- package/dist/hooks/useMediaCloudEmitter.d.mts +26 -0
- package/dist/hooks/{useEmitter.mjs → useMediaCloudEmitter.mjs} +4 -4
- package/dist/hooks/useMediaCloudEmitter.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/plugin.d.mts +2 -3
- package/dist/plugin.mjs +25 -172
- package/dist/plugin.mjs.map +1 -1
- package/dist/tus/stores/s3/index.d.mts +15 -0
- package/dist/tus/stores/s3/index.mjs +30 -0
- package/dist/tus/stores/s3/index.mjs.map +1 -0
- package/dist/tus/stores/s3/parts-manager.mjs +1 -1
- package/dist/tus/stores/s3/parts-manager.mjs.map +1 -1
- package/dist/tus/stores/s3/s3-store.mjs +1 -1
- package/dist/tus/stores/s3/s3-store.mjs.map +1 -1
- package/dist/types/errors.d.mts +24 -44
- package/dist/types/errors.mjs +25 -16
- package/dist/types/errors.mjs.map +1 -1
- package/dist/types/index.d.mts +30 -2
- package/dist/utils/file.mjs +2 -2
- package/dist/utils/file.mjs.map +1 -1
- package/dist/utils/mux.d.mts +39 -0
- package/dist/utils/mux.mjs +56 -0
- package/dist/utils/mux.mjs.map +1 -0
- package/dist/utils/tus.d.mts +56 -0
- package/dist/utils/tus.mjs +85 -0
- package/dist/utils/tus.mjs.map +1 -0
- package/package.json +20 -15
- package/dist/hooks/useEmitter.d.mts +0 -47
- package/dist/hooks/useEmitter.mjs.map +0 -1
|
@@ -1,177 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UseMagicErrorReturn } from "@maas/error-handler";
|
|
2
2
|
|
|
3
3
|
//#region src/hooks/useErrorHandler.d.ts
|
|
4
|
-
declare function useErrorHandler():
|
|
5
|
-
logError: (errorEntry: {
|
|
6
|
-
readonly message: "Mux configuration (tokenId and tokenSecret) must be provided in pluginOptions to use Mux";
|
|
7
|
-
readonly errorCode: 400;
|
|
8
|
-
} | {
|
|
9
|
-
readonly message: "Mux configuration is missing. Mux features will not be available";
|
|
10
|
-
readonly errorCode: 400;
|
|
11
|
-
} | {
|
|
12
|
-
readonly message: "No upload-id found for upload";
|
|
13
|
-
readonly errorCode: 400;
|
|
14
|
-
} | {
|
|
15
|
-
readonly message: "Error deleting Mux asset";
|
|
16
|
-
readonly errorCode: 500;
|
|
17
|
-
} | {
|
|
18
|
-
readonly message: "Mux video upload failed";
|
|
19
|
-
readonly errorCode: 500;
|
|
20
|
-
} | {
|
|
21
|
-
readonly message: "Mux direct upload failed";
|
|
22
|
-
readonly errorCode: 500;
|
|
23
|
-
} | {
|
|
24
|
-
readonly message: "Error in Mux create upload handler";
|
|
25
|
-
readonly errorCode: 500;
|
|
26
|
-
} | {
|
|
27
|
-
readonly message: "Request does not support json() method";
|
|
28
|
-
readonly errorCode: 400;
|
|
29
|
-
} | {
|
|
30
|
-
readonly message: "S3 configuration (bucket, region, accessKeyId, secretAccessKey) must be provided in pluginOptions";
|
|
31
|
-
readonly errorCode: 400;
|
|
32
|
-
} | {
|
|
33
|
-
readonly message: "Error deleting file from S3";
|
|
34
|
-
readonly errorCode: 500;
|
|
35
|
-
} | {
|
|
36
|
-
readonly message: "Could not find a unique file name after maximum tries";
|
|
37
|
-
readonly errorCode: 500;
|
|
38
|
-
} | {
|
|
39
|
-
readonly message: "TUS file upload error occurred";
|
|
40
|
-
readonly errorCode: 500;
|
|
41
|
-
} | {
|
|
42
|
-
readonly message: "Unable to determine file type";
|
|
43
|
-
readonly errorCode: 400;
|
|
44
|
-
} | {
|
|
45
|
-
readonly message: "Error determining file type";
|
|
46
|
-
readonly errorCode: 500;
|
|
47
|
-
} | {
|
|
48
|
-
readonly message: "Error sanitizing filename";
|
|
49
|
-
readonly errorCode: 500;
|
|
50
|
-
} | {
|
|
51
|
-
readonly message: "Filename is missing, cannot parse file";
|
|
52
|
-
readonly errorCode: 500;
|
|
53
|
-
} | {
|
|
54
|
-
readonly message: "File not found";
|
|
55
|
-
readonly errorCode: 404;
|
|
56
|
-
} | {
|
|
57
|
-
readonly message: "Error setting media dimensions";
|
|
58
|
-
readonly errorCode: 500;
|
|
59
|
-
} | {
|
|
60
|
-
readonly message: "No upload URL provided, cannot parse upload ID";
|
|
61
|
-
readonly errorCode: 400;
|
|
62
|
-
} | {
|
|
63
|
-
readonly message: "Upload handler error occurred";
|
|
64
|
-
readonly errorCode: 500;
|
|
65
|
-
} | {
|
|
66
|
-
readonly message: "Polling error for upload";
|
|
67
|
-
readonly errorCode: 500;
|
|
68
|
-
} | {
|
|
69
|
-
readonly message: "Payload Media Cloud plugin is not configured";
|
|
70
|
-
readonly errorCode: 500;
|
|
71
|
-
} | {
|
|
72
|
-
readonly message: "Error in namingFunction";
|
|
73
|
-
readonly errorCode: 500;
|
|
74
|
-
}, overrideLevel?: LogLevel) => void;
|
|
75
|
-
throwError: (errorEntry: {
|
|
76
|
-
readonly message: "Mux configuration (tokenId and tokenSecret) must be provided in pluginOptions to use Mux";
|
|
77
|
-
readonly errorCode: 400;
|
|
78
|
-
} | {
|
|
79
|
-
readonly message: "Mux configuration is missing. Mux features will not be available";
|
|
80
|
-
readonly errorCode: 400;
|
|
81
|
-
} | {
|
|
82
|
-
readonly message: "No upload-id found for upload";
|
|
83
|
-
readonly errorCode: 400;
|
|
84
|
-
} | {
|
|
85
|
-
readonly message: "Error deleting Mux asset";
|
|
86
|
-
readonly errorCode: 500;
|
|
87
|
-
} | {
|
|
88
|
-
readonly message: "Mux video upload failed";
|
|
89
|
-
readonly errorCode: 500;
|
|
90
|
-
} | {
|
|
91
|
-
readonly message: "Mux direct upload failed";
|
|
92
|
-
readonly errorCode: 500;
|
|
93
|
-
} | {
|
|
94
|
-
readonly message: "Error in Mux create upload handler";
|
|
95
|
-
readonly errorCode: 500;
|
|
96
|
-
} | {
|
|
97
|
-
readonly message: "Request does not support json() method";
|
|
98
|
-
readonly errorCode: 400;
|
|
99
|
-
} | {
|
|
100
|
-
readonly message: "S3 configuration (bucket, region, accessKeyId, secretAccessKey) must be provided in pluginOptions";
|
|
101
|
-
readonly errorCode: 400;
|
|
102
|
-
} | {
|
|
103
|
-
readonly message: "Error deleting file from S3";
|
|
104
|
-
readonly errorCode: 500;
|
|
105
|
-
} | {
|
|
106
|
-
readonly message: "Could not find a unique file name after maximum tries";
|
|
107
|
-
readonly errorCode: 500;
|
|
108
|
-
} | {
|
|
109
|
-
readonly message: "TUS file upload error occurred";
|
|
110
|
-
readonly errorCode: 500;
|
|
111
|
-
} | {
|
|
112
|
-
readonly message: "Unable to determine file type";
|
|
113
|
-
readonly errorCode: 400;
|
|
114
|
-
} | {
|
|
115
|
-
readonly message: "Error determining file type";
|
|
116
|
-
readonly errorCode: 500;
|
|
117
|
-
} | {
|
|
118
|
-
readonly message: "Error sanitizing filename";
|
|
119
|
-
readonly errorCode: 500;
|
|
120
|
-
} | {
|
|
121
|
-
readonly message: "Filename is missing, cannot parse file";
|
|
122
|
-
readonly errorCode: 500;
|
|
123
|
-
} | {
|
|
124
|
-
readonly message: "File not found";
|
|
125
|
-
readonly errorCode: 404;
|
|
126
|
-
} | {
|
|
127
|
-
readonly message: "Error setting media dimensions";
|
|
128
|
-
readonly errorCode: 500;
|
|
129
|
-
} | {
|
|
130
|
-
readonly message: "No upload URL provided, cannot parse upload ID";
|
|
131
|
-
readonly errorCode: 400;
|
|
132
|
-
} | {
|
|
133
|
-
readonly message: "Upload handler error occurred";
|
|
134
|
-
readonly errorCode: 500;
|
|
135
|
-
} | {
|
|
136
|
-
readonly message: "Polling error for upload";
|
|
137
|
-
readonly errorCode: 500;
|
|
138
|
-
} | {
|
|
139
|
-
readonly message: "Payload Media Cloud plugin is not configured";
|
|
140
|
-
readonly errorCode: 500;
|
|
141
|
-
} | {
|
|
142
|
-
readonly message: "Error in namingFunction";
|
|
143
|
-
readonly errorCode: 500;
|
|
144
|
-
}) => never;
|
|
145
|
-
log: (logEntry: {
|
|
146
|
-
readonly message: "Initializing multipart upload";
|
|
147
|
-
} | {
|
|
148
|
-
readonly message: "Multipart upload created";
|
|
149
|
-
} | {
|
|
150
|
-
readonly message: "Failed to finish upload";
|
|
151
|
-
} | {
|
|
152
|
-
readonly message: "Attempting to read file from S3";
|
|
153
|
-
} | {
|
|
154
|
-
readonly message: "Successfully read file from S3";
|
|
155
|
-
} | {
|
|
156
|
-
readonly message: "Failed to read file, retries left";
|
|
157
|
-
} | {
|
|
158
|
-
readonly message: "Failed to read file after all retries";
|
|
159
|
-
} | {
|
|
160
|
-
readonly message: "No file found";
|
|
161
|
-
} | {
|
|
162
|
-
readonly message: "Error retrieving parts";
|
|
163
|
-
} | {
|
|
164
|
-
readonly message: "Saving metadata";
|
|
165
|
-
} | {
|
|
166
|
-
readonly message: "Metadata file saved";
|
|
167
|
-
} | {
|
|
168
|
-
readonly message: "Removing cached data";
|
|
169
|
-
} | {
|
|
170
|
-
readonly message: "Finished uploading incomplete part";
|
|
171
|
-
} | {
|
|
172
|
-
readonly message: "Failed to remove chunk";
|
|
173
|
-
}) => void;
|
|
174
|
-
};
|
|
4
|
+
declare function useErrorHandler(): Omit<UseMagicErrorReturn, 'assert' | 'MagicError'>;
|
|
175
5
|
//#endregion
|
|
176
6
|
export { useErrorHandler };
|
|
177
7
|
//# sourceMappingURL=useErrorHandler.d.mts.map
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LogLevel, createLogger } from "../error-handler/dist/index.mjs";
|
|
1
|
+
import { useMagicError } from "../error-handler/dist/index.mjs";
|
|
3
2
|
|
|
4
3
|
//#region src/hooks/useErrorHandler.ts
|
|
5
4
|
function useErrorHandler() {
|
|
6
|
-
const { logError, throwError,
|
|
7
|
-
prefix: "PLUGIN-MEDIA-CLOUD",
|
|
8
|
-
level: LogLevel.ERROR,
|
|
9
|
-
errors: MediaCloudErrors,
|
|
10
|
-
logs: MediaCloudLogs
|
|
11
|
-
});
|
|
5
|
+
const { log, logError, throwError, logWarning } = useMagicError({ prefix: "PLUGIN-MEDIA-CLOUD" });
|
|
12
6
|
return {
|
|
7
|
+
log,
|
|
13
8
|
logError,
|
|
14
9
|
throwError,
|
|
15
|
-
|
|
10
|
+
logWarning
|
|
16
11
|
};
|
|
17
12
|
}
|
|
18
13
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useErrorHandler.mjs","names":[],"sources":["../../src/hooks/useErrorHandler.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useErrorHandler.mjs","names":[],"sources":["../../src/hooks/useErrorHandler.ts"],"sourcesContent":["import { useMagicError, type UseMagicErrorReturn } from '@maas/error-handler'\n\nexport function useErrorHandler(): Omit<\n UseMagicErrorReturn,\n 'assert' | 'MagicError'\n> {\n const { log, logError, throwError, logWarning } = useMagicError({\n prefix: 'PLUGIN-MEDIA-CLOUD',\n })\n\n return {\n log,\n logError,\n throwError,\n logWarning,\n }\n}\n"],"mappings":";;;AAEA,SAAgB,kBAGd;CACA,MAAM,EAAE,KAAK,UAAU,YAAY,eAAe,cAAc,EAC9D,QAAQ,sBACT,CAAC;AAEF,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MediaCloudEmitterEvents } from "../types/index.mjs";
|
|
2
|
+
import * as mitt0 from "mitt";
|
|
3
|
+
|
|
4
|
+
//#region src/hooks/useMediaCloudEmitter.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hook to access the global event emitter for upload management
|
|
8
|
+
* @returns An object with emitter methods (on, off, emit)
|
|
9
|
+
*/
|
|
10
|
+
declare function useMediaCloudEmitter(): {
|
|
11
|
+
on: {
|
|
12
|
+
<Key extends keyof MediaCloudEmitterEvents>(type: Key, handler: mitt0.Handler<MediaCloudEmitterEvents[Key]>): void;
|
|
13
|
+
(type: "*", handler: mitt0.WildcardHandler<MediaCloudEmitterEvents>): void;
|
|
14
|
+
};
|
|
15
|
+
off: {
|
|
16
|
+
<Key extends keyof MediaCloudEmitterEvents>(type: Key, handler?: mitt0.Handler<MediaCloudEmitterEvents[Key]> | undefined): void;
|
|
17
|
+
(type: "*", handler: mitt0.WildcardHandler<MediaCloudEmitterEvents>): void;
|
|
18
|
+
};
|
|
19
|
+
emit: {
|
|
20
|
+
<Key extends keyof MediaCloudEmitterEvents>(type: Key, event: MediaCloudEmitterEvents[Key]): void;
|
|
21
|
+
<Key extends keyof MediaCloudEmitterEvents>(type: undefined extends MediaCloudEmitterEvents[Key] ? Key : never): void;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { useMediaCloudEmitter };
|
|
26
|
+
//# sourceMappingURL=useMediaCloudEmitter.d.mts.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import mitt from "mitt";
|
|
2
2
|
|
|
3
|
-
//#region src/hooks/
|
|
3
|
+
//#region src/hooks/useMediaCloudEmitter.ts
|
|
4
4
|
const emitter = mitt();
|
|
5
5
|
/**
|
|
6
6
|
* Hook to access the global event emitter for upload management
|
|
7
7
|
* @returns An object with emitter methods (on, off, emit)
|
|
8
8
|
*/
|
|
9
|
-
function
|
|
9
|
+
function useMediaCloudEmitter() {
|
|
10
10
|
return {
|
|
11
11
|
on: emitter.on,
|
|
12
12
|
off: emitter.off,
|
|
@@ -15,5 +15,5 @@ function useEmitter() {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
|
-
export {
|
|
19
|
-
//# sourceMappingURL=
|
|
18
|
+
export { useMediaCloudEmitter };
|
|
19
|
+
//# sourceMappingURL=useMediaCloudEmitter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMediaCloudEmitter.mjs","names":[],"sources":["../../src/hooks/useMediaCloudEmitter.ts"],"sourcesContent":["import mitt from 'mitt'\nimport type { MediaCloudEmitterEvents } from '../types'\n\nconst emitter = mitt<MediaCloudEmitterEvents>()\n\n/**\n * Hook to access the global event emitter for upload management\n * @returns An object with emitter methods (on, off, emit)\n */\nfunction useMediaCloudEmitter() {\n return {\n on: emitter.on,\n off: emitter.off,\n emit: emitter.emit,\n }\n}\n\nexport { useMediaCloudEmitter }\n"],"mappings":";;;AAGA,MAAM,UAAU,MAA+B;;;;;AAM/C,SAAS,uBAAuB;AAC9B,QAAO;EACL,IAAI,QAAQ;EACZ,KAAK,QAAQ;EACb,MAAM,QAAQ;EACf"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { MediaCloudPluginOptions } from "./types/index.mjs";
|
|
1
|
+
import { MediaCloudEmitterEvents, MediaCloudPluginOptions } from "./types/index.mjs";
|
|
2
2
|
import { mediaCloudPlugin } from "./plugin.mjs";
|
|
3
|
-
export { type MediaCloudPluginOptions, mediaCloudPlugin };
|
|
3
|
+
export { type MediaCloudEmitterEvents, type MediaCloudPluginOptions, mediaCloudPlugin };
|
package/dist/plugin.d.mts
CHANGED
|
@@ -5,9 +5,8 @@ import { Config } from "payload";
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Media Cloud Plugin for Payload CMS
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
10
|
-
* @returns A function that configures the Payload config
|
|
8
|
+
* @param pluginOptions Configuration options
|
|
9
|
+
* @returns Payload config function
|
|
11
10
|
*/
|
|
12
11
|
declare function mediaCloudPlugin(pluginOptions: MediaCloudPluginOptions): (config: Config) => Config;
|
|
13
12
|
//#endregion
|
package/dist/plugin.mjs
CHANGED
|
@@ -2,184 +2,30 @@ import { MediaCloudErrors } from "./types/errors.mjs";
|
|
|
2
2
|
import { useErrorHandler } from "./hooks/useErrorHandler.mjs";
|
|
3
3
|
import { getStorageAdapter } from "./adapter/storageAdapter.mjs";
|
|
4
4
|
import { getMediaCollection } from "./collections/mediaCollection.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { getTusPostProcessorHandler } from "./endpoints/tusPostProcessorHandler.mjs";
|
|
9
|
-
import { S3Store } from "./tus/stores/s3/s3-store.mjs";
|
|
10
|
-
import { generateUniqueFilename } from "./utils/file.mjs";
|
|
11
|
-
import Mux from "@mux/mux-node";
|
|
5
|
+
import { createS3Store } from "./tus/stores/s3/index.mjs";
|
|
6
|
+
import { createMuxClient, createMuxEndpoints, validateMuxConfig } from "./utils/mux.mjs";
|
|
7
|
+
import { createTusEndpoints, createTusServer } from "./utils/tus.mjs";
|
|
12
8
|
import { cloudStoragePlugin } from "@payloadcms/plugin-cloud-storage";
|
|
13
9
|
import { initClientUploads } from "@payloadcms/plugin-cloud-storage/utilities";
|
|
14
|
-
import { getPayload, sanitizeConfig } from "payload";
|
|
15
|
-
import { Server } from "@tus/server";
|
|
16
10
|
|
|
17
11
|
//#region src/plugin.ts
|
|
18
|
-
const { logError
|
|
12
|
+
const { logError } = useErrorHandler();
|
|
19
13
|
let muxClient = null;
|
|
20
14
|
/**
|
|
21
|
-
* Validates Mux configuration options
|
|
22
|
-
* @param muxConfig - The Mux configuration to validate
|
|
23
|
-
* @throws {Error} When required Mux configuration is missing
|
|
24
|
-
*/
|
|
25
|
-
function validateMuxConfig(muxConfig) {
|
|
26
|
-
if (!muxConfig?.tokenId || !muxConfig?.tokenSecret) throwError(MediaCloudErrors.MUX_CONFIG_MISSING);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Creates a new Mux client instance
|
|
30
|
-
* @param muxConfig - The Mux configuration options
|
|
31
|
-
* @returns A configured Mux client
|
|
32
|
-
*/
|
|
33
|
-
function createMuxClient(muxConfig) {
|
|
34
|
-
return new Mux({
|
|
35
|
-
tokenId: muxConfig.tokenId,
|
|
36
|
-
tokenSecret: muxConfig.tokenSecret,
|
|
37
|
-
webhookSecret: muxConfig.webhookSecret
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Creates and configures an S3Store instance
|
|
42
|
-
* @param s3Config - The S3 configuration options
|
|
43
|
-
* @returns A configured S3Store instance
|
|
44
|
-
* @throws {Error} When required S3 configuration is missing
|
|
45
|
-
*/
|
|
46
|
-
function createS3Store(s3Config) {
|
|
47
|
-
if (!s3Config?.bucket || !s3Config?.region || !s3Config?.accessKeyId || !s3Config?.secretAccessKey) throwError(MediaCloudErrors.S3_CONFIG_MISSING);
|
|
48
|
-
return new S3Store({ s3ClientConfig: {
|
|
49
|
-
acl: "public-read",
|
|
50
|
-
bucket: s3Config.bucket,
|
|
51
|
-
credentials: {
|
|
52
|
-
accessKeyId: s3Config.accessKeyId,
|
|
53
|
-
secretAccessKey: s3Config.secretAccessKey
|
|
54
|
-
},
|
|
55
|
-
endpoint: s3Config.endpoint,
|
|
56
|
-
forcePathStyle: true,
|
|
57
|
-
region: s3Config.region
|
|
58
|
-
} });
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Creates a TUS server instance with S3 storage
|
|
62
|
-
* @param args - The arguments for creating the TUS server
|
|
63
|
-
* @returns A configured TusServer instance
|
|
64
|
-
*/
|
|
65
|
-
function createTusServer(args) {
|
|
66
|
-
const { config, s3Store, pluginOptions } = args;
|
|
67
|
-
return new Server({
|
|
68
|
-
datastore: s3Store,
|
|
69
|
-
namingFunction: async (req, metadata) => {
|
|
70
|
-
try {
|
|
71
|
-
const { docs } = await (await getPayload({ config: sanitizeConfig(config) })).find({
|
|
72
|
-
collection: "media",
|
|
73
|
-
where: { filename: { equals: metadata?.filename || "" } }
|
|
74
|
-
});
|
|
75
|
-
if (docs.length > 0) return generateUniqueFilename(metadata?.filename ?? "");
|
|
76
|
-
else return metadata?.filename || generateUniqueFilename("");
|
|
77
|
-
} catch (_error) {
|
|
78
|
-
logError(MediaCloudErrors.NAMING_FUNCTION_ERROR);
|
|
79
|
-
return metadata?.filename || generateUniqueFilename("");
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
path: "/api/uploads",
|
|
83
|
-
respectForwardedHeaders: pluginOptions.s3.respectForwardedHeaders ?? true
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Creates TUS upload endpoints for file handling
|
|
88
|
-
* @param tusServer - The TUS server instance
|
|
89
|
-
* @returns An array of endpoint configurations
|
|
90
|
-
*/
|
|
91
|
-
function createTusEndpoints(args) {
|
|
92
|
-
const { tusServer, s3Store } = args;
|
|
93
|
-
/**
|
|
94
|
-
* Handles TUS requests through the server
|
|
95
|
-
* @param req - The payload request object
|
|
96
|
-
* @returns The server response
|
|
97
|
-
*/
|
|
98
|
-
function tusHandler(req) {
|
|
99
|
-
return tusServer.handleWeb(req);
|
|
100
|
-
}
|
|
101
|
-
return [
|
|
102
|
-
{
|
|
103
|
-
handler: tusHandler,
|
|
104
|
-
method: "options",
|
|
105
|
-
path: "/uploads"
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
handler: tusHandler,
|
|
109
|
-
method: "post",
|
|
110
|
-
path: "/uploads"
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
handler: tusHandler,
|
|
114
|
-
method: "get",
|
|
115
|
-
path: "/uploads/:id"
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
handler: tusHandler,
|
|
119
|
-
method: "put",
|
|
120
|
-
path: "/uploads/:id"
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
handler: tusHandler,
|
|
124
|
-
method: "patch",
|
|
125
|
-
path: "/uploads/:id"
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
handler: tusHandler,
|
|
129
|
-
method: "delete",
|
|
130
|
-
path: "/uploads/:id"
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
handler: getTusPostProcessorHandler({ s3Store }),
|
|
134
|
-
method: "get",
|
|
135
|
-
path: "/uploads/:filename/process"
|
|
136
|
-
}
|
|
137
|
-
];
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Creates Mux-related endpoints for asset handling
|
|
141
|
-
* @param args - The arguments for creating Mux endpoints
|
|
142
|
-
* @returns An array of Mux endpoint configurations
|
|
143
|
-
*/
|
|
144
|
-
function createMuxEndpoints(args) {
|
|
145
|
-
const { getMuxClient, pluginOptions } = args;
|
|
146
|
-
return [
|
|
147
|
-
{
|
|
148
|
-
handler: getMuxWebhookHandler({ getMuxClient }),
|
|
149
|
-
method: "get",
|
|
150
|
-
path: "/mux/webhook"
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
handler: getMuxCreateUploadHandler({
|
|
154
|
-
getMuxClient,
|
|
155
|
-
pluginOptions
|
|
156
|
-
}),
|
|
157
|
-
method: "post",
|
|
158
|
-
path: "/mux/upload"
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
handler: getMuxAssetHandler({ getMuxClient }),
|
|
162
|
-
method: "get",
|
|
163
|
-
path: "/mux/asset"
|
|
164
|
-
}
|
|
165
|
-
];
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
15
|
* Media Cloud Plugin for Payload CMS
|
|
169
|
-
*
|
|
170
|
-
* @
|
|
171
|
-
* @returns A function that configures the Payload config
|
|
16
|
+
* @param pluginOptions Configuration options
|
|
17
|
+
* @returns Payload config function
|
|
172
18
|
*/
|
|
173
19
|
function mediaCloudPlugin(pluginOptions) {
|
|
174
20
|
return function(config) {
|
|
175
21
|
if (!pluginOptions) {
|
|
176
|
-
logError(MediaCloudErrors.PLUGIN_NOT_CONFIGURED);
|
|
22
|
+
logError(MediaCloudErrors.PLUGIN_NOT_CONFIGURED.message);
|
|
177
23
|
return config;
|
|
178
24
|
}
|
|
179
|
-
|
|
25
|
+
if (pluginOptions.enabled === false) return config;
|
|
180
26
|
/**
|
|
181
|
-
*
|
|
182
|
-
* @returns
|
|
27
|
+
* Helper function to get or create Mux client instance
|
|
28
|
+
* @returns Mux client instance
|
|
183
29
|
*/
|
|
184
30
|
function getMuxClient() {
|
|
185
31
|
if (muxClient) return muxClient;
|
|
@@ -189,7 +35,7 @@ function mediaCloudPlugin(pluginOptions) {
|
|
|
189
35
|
validateMuxConfig(pluginOptions.mux);
|
|
190
36
|
muxClient = getMuxClient();
|
|
191
37
|
} else {
|
|
192
|
-
logError(MediaCloudErrors.MUX_CONFIG_INCOMPLETE);
|
|
38
|
+
logError(MediaCloudErrors.MUX_CONFIG_INCOMPLETE.message);
|
|
193
39
|
muxClient = null;
|
|
194
40
|
}
|
|
195
41
|
const s3Store = createS3Store(pluginOptions.s3);
|
|
@@ -198,8 +44,15 @@ function mediaCloudPlugin(pluginOptions) {
|
|
|
198
44
|
s3Store,
|
|
199
45
|
pluginOptions
|
|
200
46
|
});
|
|
201
|
-
const
|
|
202
|
-
|
|
47
|
+
const baseCollection = config.collections?.find(({ slug }) => slug === pluginOptions.collection);
|
|
48
|
+
const mediaCollection = getMediaCollection({
|
|
49
|
+
s3Store,
|
|
50
|
+
baseCollection
|
|
51
|
+
});
|
|
52
|
+
if (baseCollection) config = {
|
|
53
|
+
...config,
|
|
54
|
+
collections: config.collections?.filter(({ slug }) => slug !== baseCollection?.slug) || []
|
|
55
|
+
};
|
|
203
56
|
initClientUploads({
|
|
204
57
|
clientHandler: "@maas/payload-plugin-media-cloud/components#UploadHandler",
|
|
205
58
|
collections: { media: {
|
|
@@ -222,13 +75,13 @@ function mediaCloudPlugin(pluginOptions) {
|
|
|
222
75
|
clientUploads: true,
|
|
223
76
|
disableLocalStorage: true
|
|
224
77
|
} } };
|
|
225
|
-
const
|
|
78
|
+
const mergedConfig = {
|
|
226
79
|
...config,
|
|
227
80
|
admin: {
|
|
228
|
-
...config.admin
|
|
81
|
+
...config.admin,
|
|
229
82
|
components: {
|
|
230
|
-
...config.admin?.components
|
|
231
|
-
providers: ["@maas/payload-plugin-media-cloud/components#UploadManagerProvider"
|
|
83
|
+
...config.admin?.components,
|
|
84
|
+
providers: [...config.admin?.components?.providers ?? [], "@maas/payload-plugin-media-cloud/components#UploadManagerProvider"]
|
|
232
85
|
}
|
|
233
86
|
},
|
|
234
87
|
collections: [...config.collections ?? [], mediaCollection],
|
|
@@ -244,7 +97,7 @@ function mediaCloudPlugin(pluginOptions) {
|
|
|
244
97
|
})
|
|
245
98
|
]
|
|
246
99
|
};
|
|
247
|
-
return cloudStoragePlugin(cloudStorageConfig)(
|
|
100
|
+
return cloudStoragePlugin(cloudStorageConfig)(mergedConfig);
|
|
248
101
|
};
|
|
249
102
|
}
|
|
250
103
|
|
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":["muxClient: Mux | null","TusServer","mappedConfig: Config"],"sources":["../src/plugin.ts"],"sourcesContent":["import Mux from '@mux/mux-node'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\nimport { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { getPayload, sanitizeConfig } from 'payload'\nimport { Server as TusServer, type DataStore } from '@tus/server'\n\nimport { MediaCloudErrors } from './types/errors'\nimport { useErrorHandler } from './hooks/useErrorHandler'\nimport { getStorageAdapter } from './adapter/storageAdapter'\nimport { getMediaCollection } from './collections/mediaCollection'\nimport { getMuxAssetHandler } from './endpoints/muxAssetHandler'\nimport { getMuxCreateUploadHandler } from './endpoints/muxCreateUploadHandler'\nimport { getMuxWebhookHandler } from './endpoints/muxWebhookHandler'\nimport { getTusPostProcessorHandler } from './endpoints/tusPostProcessorHandler'\n\nimport { S3Store } from './tus/stores/s3/s3-store'\nimport { generateUniqueFilename } from './utils/file'\n\nimport type { Config, PayloadRequest } from 'payload'\nimport type { MediaCloudPluginOptions } from './types'\n\ninterface CreateTusServerArgs {\n config: Config\n s3Store: DataStore\n pluginOptions: MediaCloudPluginOptions\n}\n\ninterface CreateMuxEndpointsArgs {\n getMuxClient: () => Mux\n pluginOptions: MediaCloudPluginOptions\n}\n\ninterface CreateTusEndpointsArgs {\n tusServer: TusServer\n s3Store: S3Store\n}\n\nconst { logError, throwError } = useErrorHandler()\n\nlet muxClient: Mux | null = null\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 */\nfunction validateMuxConfig(muxConfig: MediaCloudPluginOptions['mux']): void {\n if (!muxConfig?.tokenId || !muxConfig?.tokenSecret) {\n throwError(MediaCloudErrors.MUX_CONFIG_MISSING)\n }\n}\n\n/**\n * Creates a new Mux client instance\n * @param muxConfig - The Mux configuration options\n * @returns A configured Mux client\n */\nfunction createMuxClient(muxConfig: MediaCloudPluginOptions['mux']): Mux {\n // Create and return Mux client instance\n return new Mux({\n tokenId: muxConfig.tokenId,\n tokenSecret: muxConfig.tokenSecret,\n webhookSecret: muxConfig.webhookSecret,\n })\n}\n\n/**\n * Creates and configures an S3Store instance\n * @param s3Config - The S3 configuration options\n * @returns A configured S3Store instance\n * @throws {Error} When required S3 configuration is missing\n */\nfunction createS3Store(s3Config: MediaCloudPluginOptions['s3']): S3Store {\n // Validate S3 configuration\n if (\n !s3Config?.bucket ||\n !s3Config?.region ||\n !s3Config?.accessKeyId ||\n !s3Config?.secretAccessKey\n ) {\n throwError(MediaCloudErrors.S3_CONFIG_MISSING)\n }\n\n // Create and return S3Store instance\n return new S3Store({\n s3ClientConfig: {\n acl: 'public-read',\n bucket: s3Config.bucket,\n credentials: {\n accessKeyId: s3Config.accessKeyId,\n secretAccessKey: s3Config.secretAccessKey,\n },\n endpoint: s3Config.endpoint,\n forcePathStyle: true,\n region: s3Config.region,\n },\n })\n}\n\n/**\n * Creates a TUS server instance with S3 storage\n * @param args - The arguments for creating the TUS server\n * @returns A configured TusServer instance\n */\nfunction createTusServer(args: CreateTusServerArgs): TusServer {\n const { config, s3Store, pluginOptions } = args\n\n return new TusServer({\n datastore: s3Store,\n namingFunction: async (req, metadata) => {\n try {\n // Get Payload instance\n const payload = await getPayload({\n config: sanitizeConfig(config),\n })\n\n // Check if a file with the same name already exists in the media collection\n const { docs } = await payload.find({\n collection: 'media',\n where: {\n filename: {\n equals: metadata?.filename || '',\n },\n },\n })\n\n // If a file with the same name exists, generate a unique filename\n if (docs.length > 0) {\n return generateUniqueFilename(metadata?.filename ?? '')\n } else {\n // If no file with the same name exists, return the original filename\n return metadata?.filename || generateUniqueFilename('')\n }\n } catch (_error) {\n // If an error occurs, log it and return the original filename\n logError(MediaCloudErrors.NAMING_FUNCTION_ERROR)\n return metadata?.filename || generateUniqueFilename('')\n }\n },\n path: '/api/uploads',\n respectForwardedHeaders: pluginOptions.s3.respectForwardedHeaders ?? true,\n })\n}\n\n/**\n * Creates TUS upload endpoints for file handling\n * @param tusServer - The TUS server instance\n * @returns An array of endpoint configurations\n */\nfunction createTusEndpoints(args: CreateTusEndpointsArgs) {\n const { tusServer, s3Store } = args\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 tusServer.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({ s3Store }),\n method: 'get' as const,\n path: '/uploads/:filename/process',\n },\n ]\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 */\nfunction createMuxEndpoints(args: CreateMuxEndpointsArgs) {\n const { getMuxClient, pluginOptions } = args\n return [\n {\n handler: getMuxWebhookHandler({ getMuxClient }),\n method: 'get' 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 }),\n method: 'get' as const,\n path: '/mux/asset',\n },\n ]\n}\n\n/**\n * Media Cloud Plugin for Payload CMS\n * Provides file upload capabilities using S3 storage and Mux video processing\n * @param pluginOptions - Configuration options for the plugin\n * @returns A function that configures the Payload config\n */\nexport function mediaCloudPlugin(pluginOptions: MediaCloudPluginOptions) {\n return function (config: Config): Config {\n if (!pluginOptions) {\n logError(MediaCloudErrors.PLUGIN_NOT_CONFIGURED)\n return config\n }\n\n const isPluginDisabled = pluginOptions.enabled === false\n\n /**\n * Gets or creates a Mux client instance\n * @returns The Mux client instance\n */\n function getMuxClient(): Mux {\n // Return existing Mux client if already created\n if (muxClient) {\n return muxClient\n }\n // Create and return a new Mux client\n return createMuxClient(pluginOptions.mux)\n }\n\n // Validate Mux configuration\n if (pluginOptions.mux) {\n validateMuxConfig(pluginOptions.mux)\n muxClient = getMuxClient()\n } else {\n logError(MediaCloudErrors.MUX_CONFIG_INCOMPLETE)\n muxClient = null\n }\n\n const s3Store = createS3Store(pluginOptions.s3)\n const tusServer = createTusServer({ config, s3Store, pluginOptions })\n const mediaCollection = getMediaCollection({ s3Store })\n\n if (isPluginDisabled) {\n return config\n }\n\n // Initialize client uploads\n initClientUploads({\n clientHandler:\n '@maas/payload-plugin-media-cloud/components#UploadHandler',\n collections: {\n media: {\n clientUploads: true,\n disableLocalStorage: true,\n },\n },\n config,\n enabled: true,\n serverHandler: () => {\n return Response.json(\n { message: 'Server handler is not implemented' },\n { status: 501 }\n )\n },\n serverHandlerPath: '/media-cloud/upload',\n })\n\n const cloudStorageConfig = {\n collections: {\n media: {\n adapter: getStorageAdapter({ getMuxClient, pluginOptions, s3Store }),\n clientUploads: true,\n disableLocalStorage: true,\n },\n },\n }\n\n const mappedConfig: Config = {\n ...config,\n admin: {\n ...(config.admin ?? {}),\n components: {\n ...(config.admin?.components ?? {}),\n providers: [\n '@maas/payload-plugin-media-cloud/components#UploadManagerProvider',\n ...(config.admin?.components?.providers ?? []),\n ],\n },\n },\n collections: [...(config.collections ?? []), mediaCollection],\n endpoints: [\n ...(config.endpoints ?? []),\n ...createTusEndpoints({ tusServer, s3Store }),\n ...createMuxEndpoints({ getMuxClient, pluginOptions }),\n ],\n }\n\n return cloudStoragePlugin(cloudStorageConfig)(mappedConfig)\n }\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":["muxClient: Mux | null","mergedConfig: Config"],"sources":["../src/plugin.ts"],"sourcesContent":["import Mux from '@mux/mux-node'\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\nimport { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities'\n\nimport { MediaCloudErrors } from './types/errors'\nimport { getStorageAdapter } from './adapter/storageAdapter'\nimport { getMediaCollection } from './collections/mediaCollection'\nimport { useErrorHandler } from './hooks/useErrorHandler'\nimport { createS3Store } from './tus/stores/s3'\nimport {\n createMuxClient,\n createMuxEndpoints,\n validateMuxConfig,\n} from './utils/mux'\nimport { createTusEndpoints, createTusServer } from './utils/tus'\n\nimport type { Config } from 'payload'\nimport type { MediaCloudPluginOptions } from './types'\n\nconst { logError } = useErrorHandler()\n\nlet muxClient: Mux | null = null\n\n/**\n * Media Cloud Plugin for Payload CMS\n * @param pluginOptions Configuration options\n * @returns Payload config function\n */\nexport function mediaCloudPlugin(pluginOptions: MediaCloudPluginOptions) {\n return function (config: Config): Config {\n // Early returns for invalid or disabled plugin configuration\n if (!pluginOptions) {\n logError(MediaCloudErrors.PLUGIN_NOT_CONFIGURED.message)\n return config\n }\n\n if (pluginOptions.enabled === false) {\n return config\n }\n\n /**\n * Helper function to get or create Mux client instance\n * @returns Mux client instance\n */\n function getMuxClient(): Mux {\n if (muxClient) {\n return muxClient\n }\n return createMuxClient(pluginOptions.mux)\n }\n\n // Initialize Mux client if configuration is provided\n if (pluginOptions.mux) {\n validateMuxConfig(pluginOptions.mux)\n muxClient = getMuxClient()\n } else {\n logError(MediaCloudErrors.MUX_CONFIG_INCOMPLETE.message)\n muxClient = null\n }\n\n const s3Store = createS3Store(pluginOptions.s3)\n const tusServer = createTusServer({ config, s3Store, pluginOptions })\n\n // Handle collection extension - replace base collection if it exists\n const baseCollection = config.collections?.find(\n ({ slug }) => slug === pluginOptions.collection\n )\n\n const mediaCollection = getMediaCollection({\n s3Store,\n baseCollection,\n })\n\n if (baseCollection) {\n config = {\n ...config,\n collections:\n config.collections?.filter(\n ({ slug }) => slug !== baseCollection?.slug\n ) || [],\n }\n }\n\n initClientUploads({\n clientHandler:\n '@maas/payload-plugin-media-cloud/components#UploadHandler',\n collections: {\n media: {\n clientUploads: true,\n disableLocalStorage: true,\n },\n },\n config,\n enabled: true,\n serverHandler: () => {\n return Response.json(\n { message: 'Server handler is not implemented' },\n { status: 501 }\n )\n },\n serverHandlerPath: '/media-cloud/upload',\n })\n\n const cloudStorageConfig = {\n collections: {\n media: {\n adapter: getStorageAdapter({ getMuxClient, pluginOptions, s3Store }),\n clientUploads: true,\n disableLocalStorage: true,\n },\n },\n }\n\n const mergedConfig: Config = {\n ...config,\n admin: {\n ...config.admin,\n components: {\n ...config.admin?.components,\n providers: [\n ...(config.admin?.components?.providers ?? []),\n '@maas/payload-plugin-media-cloud/components#UploadManagerProvider',\n ],\n },\n },\n collections: [...(config.collections ?? []), mediaCollection],\n endpoints: [\n ...(config.endpoints ?? []),\n ...createTusEndpoints({ tusServer, s3Store }),\n ...createMuxEndpoints({ getMuxClient, pluginOptions }),\n ],\n }\n\n return cloudStoragePlugin(cloudStorageConfig)(mergedConfig)\n }\n}\n"],"mappings":";;;;;;;;;;;AAmBA,MAAM,EAAE,aAAa,iBAAiB;AAEtC,IAAIA,YAAwB;;;;;;AAO5B,SAAgB,iBAAiB,eAAwC;AACvE,QAAO,SAAU,QAAwB;AAEvC,MAAI,CAAC,eAAe;AAClB,YAAS,iBAAiB,sBAAsB,QAAQ;AACxD,UAAO;;AAGT,MAAI,cAAc,YAAY,MAC5B,QAAO;;;;;EAOT,SAAS,eAAoB;AAC3B,OAAI,UACF,QAAO;AAET,UAAO,gBAAgB,cAAc,IAAI;;AAI3C,MAAI,cAAc,KAAK;AACrB,qBAAkB,cAAc,IAAI;AACpC,eAAY,cAAc;SACrB;AACL,YAAS,iBAAiB,sBAAsB,QAAQ;AACxD,eAAY;;EAGd,MAAM,UAAU,cAAc,cAAc,GAAG;EAC/C,MAAM,YAAY,gBAAgB;GAAE;GAAQ;GAAS;GAAe,CAAC;EAGrE,MAAM,iBAAiB,OAAO,aAAa,MACxC,EAAE,WAAW,SAAS,cAAc,WACtC;EAED,MAAM,kBAAkB,mBAAmB;GACzC;GACA;GACD,CAAC;AAEF,MAAI,eACF,UAAS;GACP,GAAG;GACH,aACE,OAAO,aAAa,QACjB,EAAE,WAAW,SAAS,gBAAgB,KACxC,IAAI,EAAE;GACV;AAGH,oBAAkB;GAChB,eACE;GACF,aAAa,EACX,OAAO;IACL,eAAe;IACf,qBAAqB;IACtB,EACF;GACD;GACA,SAAS;GACT,qBAAqB;AACnB,WAAO,SAAS,KACd,EAAE,SAAS,qCAAqC,EAChD,EAAE,QAAQ,KAAK,CAChB;;GAEH,mBAAmB;GACpB,CAAC;EAEF,MAAM,qBAAqB,EACzB,aAAa,EACX,OAAO;GACL,SAAS,kBAAkB;IAAE;IAAc;IAAe;IAAS,CAAC;GACpE,eAAe;GACf,qBAAqB;GACtB,EACF,EACF;EAED,MAAMC,eAAuB;GAC3B,GAAG;GACH,OAAO;IACL,GAAG,OAAO;IACV,YAAY;KACV,GAAG,OAAO,OAAO;KACjB,WAAW,CACT,GAAI,OAAO,OAAO,YAAY,aAAa,EAAE,EAC7C,oEACD;KACF;IACF;GACD,aAAa,CAAC,GAAI,OAAO,eAAe,EAAE,EAAG,gBAAgB;GAC7D,WAAW;IACT,GAAI,OAAO,aAAa,EAAE;IAC1B,GAAG,mBAAmB;KAAE;KAAW;KAAS,CAAC;IAC7C,GAAG,mBAAmB;KAAE;KAAc;KAAe,CAAC;IACvD;GACF;AAED,SAAO,mBAAmB,mBAAmB,CAAC,aAAa"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MediaCloudPluginOptions } from "../../../types/index.mjs";
|
|
2
|
+
import { S3Store } from "./s3-store.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/tus/stores/s3/index.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates and configures an S3Store instance
|
|
8
|
+
* @param s3Config - The S3 configuration options
|
|
9
|
+
* @returns A configured S3Store instance
|
|
10
|
+
* @throws {Error} When required S3 configuration is missing
|
|
11
|
+
*/
|
|
12
|
+
declare function createS3Store(s3Config: MediaCloudPluginOptions['s3']): S3Store;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { createS3Store };
|
|
15
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MediaCloudErrors } from "../../../types/errors.mjs";
|
|
2
|
+
import { useErrorHandler } from "../../../hooks/useErrorHandler.mjs";
|
|
3
|
+
import { S3Store } from "./s3-store.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/tus/stores/s3/index.ts
|
|
6
|
+
const { throwError } = useErrorHandler();
|
|
7
|
+
/**
|
|
8
|
+
* Creates and configures an S3Store instance
|
|
9
|
+
* @param s3Config - The S3 configuration options
|
|
10
|
+
* @returns A configured S3Store instance
|
|
11
|
+
* @throws {Error} When required S3 configuration is missing
|
|
12
|
+
*/
|
|
13
|
+
function createS3Store(s3Config) {
|
|
14
|
+
if (!s3Config?.bucket || !s3Config?.region || !s3Config?.accessKeyId || !s3Config?.secretAccessKey) throwError(MediaCloudErrors.S3_CONFIG_MISSING);
|
|
15
|
+
return new S3Store({ s3ClientConfig: {
|
|
16
|
+
acl: "public-read",
|
|
17
|
+
bucket: s3Config.bucket,
|
|
18
|
+
credentials: {
|
|
19
|
+
accessKeyId: s3Config.accessKeyId,
|
|
20
|
+
secretAccessKey: s3Config.secretAccessKey
|
|
21
|
+
},
|
|
22
|
+
endpoint: s3Config.endpoint,
|
|
23
|
+
forcePathStyle: true,
|
|
24
|
+
region: s3Config.region
|
|
25
|
+
} });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createS3Store };
|
|
30
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/tus/stores/s3/index.ts"],"sourcesContent":["import { MediaCloudErrors } from '../../../types/errors'\nimport { S3Store } from './s3-store'\nimport { useErrorHandler } from '../../../hooks/useErrorHandler'\n\nimport type { MediaCloudPluginOptions } from '../../../types'\n\nconst { throwError } = useErrorHandler()\n\n/**\n * Creates and configures an S3Store instance\n * @param s3Config - The S3 configuration options\n * @returns A configured S3Store instance\n * @throws {Error} When required S3 configuration is missing\n */\nexport function createS3Store(\n s3Config: MediaCloudPluginOptions['s3']\n): S3Store {\n // Validate S3 configuration\n if (\n !s3Config?.bucket ||\n !s3Config?.region ||\n !s3Config?.accessKeyId ||\n !s3Config?.secretAccessKey\n ) {\n throwError(MediaCloudErrors.S3_CONFIG_MISSING)\n }\n\n // Create and return S3Store instance\n return new S3Store({\n s3ClientConfig: {\n acl: 'public-read',\n bucket: s3Config.bucket,\n credentials: {\n accessKeyId: s3Config.accessKeyId,\n secretAccessKey: s3Config.secretAccessKey,\n },\n endpoint: s3Config.endpoint,\n forcePathStyle: true,\n region: s3Config.region,\n },\n })\n}\n"],"mappings":";;;;;AAMA,MAAM,EAAE,eAAe,iBAAiB;;;;;;;AAQxC,SAAgB,cACd,UACS;AAET,KACE,CAAC,UAAU,UACX,CAAC,UAAU,UACX,CAAC,UAAU,eACX,CAAC,UAAU,gBAEX,YAAW,iBAAiB,kBAAkB;AAIhD,QAAO,IAAI,QAAQ,EACjB,gBAAgB;EACd,KAAK;EACL,QAAQ,SAAS;EACjB,aAAa;GACX,aAAa,SAAS;GACtB,iBAAiB,SAAS;GAC3B;EACD,UAAU,SAAS;EACnB,gBAAgB;EAChB,QAAQ,SAAS;EAClB,EACF,CAAC"}
|
|
@@ -7,7 +7,7 @@ import fs from "node:fs";
|
|
|
7
7
|
import os from "node:os";
|
|
8
8
|
|
|
9
9
|
//#region src/tus/stores/s3/parts-manager.ts
|
|
10
|
-
const {
|
|
10
|
+
const { log, throwError } = useErrorHandler();
|
|
11
11
|
var S3PartsManager = class {
|
|
12
12
|
constructor(client, bucket, minPartSize, partUploadSemaphore, metadataManager, fileOperations, generateCompleteTag) {
|
|
13
13
|
this.client = client;
|