@maas/payload-plugin-media-cloud 0.0.11 → 0.0.15
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 +3 -3
- package/dist/adapter/handleDelete.mjs.map +1 -1
- package/dist/collections/mediaCollection.mjs +9 -5
- package/dist/collections/mediaCollection.mjs.map +1 -1
- package/dist/components/upload-handler/upload-handler.mjs +13 -13
- package/dist/components/upload-handler/upload-handler.mjs.map +1 -1
- package/dist/components/upload-manager/upload-manager.mjs +2 -2
- package/dist/components/upload-manager/upload-manager.mjs.map +1 -1
- package/dist/endpoints/muxAssetHandler.d.mts +1 -1
- package/dist/endpoints/muxCreateUploadHandler.d.mts +1 -1
- package/dist/endpoints/muxCreateUploadHandler.mjs +1 -1
- package/dist/endpoints/muxCreateUploadHandler.mjs.map +1 -1
- package/dist/endpoints/muxWebhookHandler.d.mts +1 -1
- package/dist/endpoints/muxWebhookHandler.mjs +13 -3
- package/dist/endpoints/muxWebhookHandler.mjs.map +1 -1
- package/dist/endpoints/tusPostProcessorHandler.mjs +1 -1
- 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 -178
- package/dist/hooks/useErrorHandler.mjs +4 -9
- package/dist/hooks/useErrorHandler.mjs.map +1 -1
- package/dist/plugin.d.mts +2 -3
- package/dist/plugin.mjs +28 -20
- package/dist/plugin.mjs.map +1 -1
- package/dist/tus/stores/s3/parts-manager.mjs +1 -1
- package/dist/tus/stores/s3/parts-manager.mjs.map +1 -1
- package/dist/types/errors.d.mts +20 -44
- package/dist/types/errors.mjs +21 -16
- package/dist/types/errors.mjs.map +1 -1
- package/dist/types/index.d.mts +4 -0
- package/dist/utils/file.mjs +2 -2
- package/dist/utils/file.mjs.map +1 -1
- package/dist/utils/mux.d.mts +5 -5
- package/dist/utils/mux.mjs +1 -1
- package/dist/utils/mux.mjs.map +1 -1
- package/dist/utils/tus.d.mts +2 -2
- package/dist/utils/tus.mjs +1 -1
- package/dist/utils/tus.mjs.map +1 -1
- package/package.json +15 -15
|
@@ -1,79 +1,99 @@
|
|
|
1
1
|
//#region ../error-handler/dist/index.mjs
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
3
|
+
* @class MagicError
|
|
4
|
+
* @extends Error
|
|
5
|
+
* @description A custom error class that includes an error code, timestamp, and source.
|
|
6
|
+
*
|
|
7
|
+
* @property {string | number} errorCode - The error code.
|
|
8
|
+
* @property {number} timestamp - The timestamp when the error occurred.
|
|
9
|
+
* @property {string} source - The source of the error.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* throw new MagicError('An error occurred', 500, 'My-Component')
|
|
14
|
+
* ```
|
|
6
15
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
var MagicError = class MagicError$1 extends Error {
|
|
17
|
+
/**
|
|
18
|
+
* @constructor
|
|
19
|
+
* @param {string} message - The error message.
|
|
20
|
+
* @param {string | number} errorCode - The error code.
|
|
21
|
+
* @param {string} source - The source of the error.
|
|
22
|
+
* @param {ErrorOptions} [options] - The error options.
|
|
23
|
+
*/
|
|
24
|
+
constructor(message, errorCode, source, options) {
|
|
25
|
+
super(message, options);
|
|
26
|
+
this.name = "MagicError";
|
|
27
|
+
this.errorCode = errorCode;
|
|
28
|
+
this.timestamp = Date.now();
|
|
29
|
+
this.source = source;
|
|
30
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, MagicError$1);
|
|
21
31
|
}
|
|
22
|
-
|
|
23
|
-
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* @function useMagicError
|
|
35
|
+
* @description A hook to create a `MagicError` instance and throw it.
|
|
36
|
+
* @param {UseMagicErrorArgs} [args] - The arguments for the hook.
|
|
37
|
+
* @returns {UseMagicErrorReturn} - The return value of the hook.
|
|
38
|
+
*/
|
|
39
|
+
function useMagicError(args = {}) {
|
|
40
|
+
const { prefix = "MagicError", source = "payload-plugins" } = args;
|
|
41
|
+
/**
|
|
42
|
+
* @function log
|
|
43
|
+
* @description Logs a message to the console.
|
|
44
|
+
* @param {string} message - The message to log.
|
|
45
|
+
*/
|
|
46
|
+
function log(message) {
|
|
47
|
+
console.log(`[${prefix}]:`, message);
|
|
24
48
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
case "WARNING":
|
|
33
|
-
console.warn(formattedMessage);
|
|
34
|
-
break;
|
|
35
|
-
case "ERROR":
|
|
36
|
-
console.error(formattedMessage);
|
|
37
|
-
break;
|
|
38
|
-
default: console.error(formattedMessage);
|
|
39
|
-
}
|
|
49
|
+
/**
|
|
50
|
+
* @function logError
|
|
51
|
+
* @description Logs an error message to the console.
|
|
52
|
+
* @param {string} message - The message to log.
|
|
53
|
+
*/
|
|
54
|
+
function logError(message) {
|
|
55
|
+
console.error(`[${prefix}]:`, message);
|
|
40
56
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
console.
|
|
57
|
+
/**
|
|
58
|
+
* @function logWarning
|
|
59
|
+
* @description Logs a warning message to the console.
|
|
60
|
+
* @param {string} message - The message to log.
|
|
61
|
+
*/
|
|
62
|
+
function logWarning(message) {
|
|
63
|
+
console.warn(`[${prefix}]:`, message);
|
|
48
64
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
/**
|
|
66
|
+
* @function throwError
|
|
67
|
+
* @description Throws a `MagicError`.
|
|
68
|
+
* @param {ThrowErrorArgs} args - The arguments for the error.
|
|
69
|
+
* @throws {MagicError}
|
|
70
|
+
*/
|
|
71
|
+
function throwError(args$1) {
|
|
72
|
+
const { message, errorCode, cause } = args$1;
|
|
73
|
+
const error = new MagicError(`[${prefix}]: ${message}`, errorCode, source, { cause });
|
|
74
|
+
logError(message);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @function assert
|
|
79
|
+
* @description Asserts that a value is not null or undefined.
|
|
80
|
+
* @param {T} value - The value to assert.
|
|
81
|
+
* @param {ThrowErrorArgs} args - The arguments for the error to throw if the assertion fails.
|
|
82
|
+
* @throws {MagicError}
|
|
83
|
+
*/
|
|
84
|
+
function assert(value, args$1) {
|
|
85
|
+
if (value === void 0 || value === null) throwError(args$1);
|
|
61
86
|
}
|
|
62
87
|
return {
|
|
63
|
-
|
|
88
|
+
assert,
|
|
64
89
|
throwError,
|
|
65
|
-
log
|
|
90
|
+
log,
|
|
91
|
+
logError,
|
|
92
|
+
logWarning,
|
|
93
|
+
MagicError
|
|
66
94
|
};
|
|
67
95
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Log level enum for categorizing log/error severity
|
|
70
|
-
*/
|
|
71
|
-
let LogLevel = /* @__PURE__ */ function(LogLevel$1) {
|
|
72
|
-
LogLevel$1["WARNING"] = "WARNING";
|
|
73
|
-
LogLevel$1["ERROR"] = "ERROR";
|
|
74
|
-
return LogLevel$1;
|
|
75
|
-
}({});
|
|
76
96
|
|
|
77
97
|
//#endregion
|
|
78
|
-
export {
|
|
98
|
+
export { useMagicError };
|
|
79
99
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../error-handler/dist/index.mjs"],"sourcesContent":["//#region src/
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["MagicError"],"sources":["../../../../error-handler/dist/index.mjs"],"sourcesContent":["//#region src/class/MagicError.ts\n/**\n* @class MagicError\n* @extends Error\n* @description A custom error class that includes an error code, timestamp, and source.\n*\n* @property {string | number} errorCode - The error code.\n* @property {number} timestamp - The timestamp when the error occurred.\n* @property {string} source - The source of the error.\n*\n* @example\n* ```ts\n* throw new MagicError('An error occurred', 500, 'My-Component')\n* ```\n*/\nvar MagicError = class MagicError extends Error {\n\t/**\n\t* @constructor\n\t* @param {string} message - The error message.\n\t* @param {string | number} errorCode - The error code.\n\t* @param {string} source - The source of the error.\n\t* @param {ErrorOptions} [options] - The error options.\n\t*/\n\tconstructor(message, errorCode, source, options) {\n\t\tsuper(message, options);\n\t\tthis.name = \"MagicError\";\n\t\tthis.errorCode = errorCode;\n\t\tthis.timestamp = Date.now();\n\t\tthis.source = source;\n\t\tif (Error.captureStackTrace) Error.captureStackTrace(this, MagicError);\n\t}\n};\n\n//#endregion\n//#region src/hooks/useMagicError.ts\n/**\n* @function useMagicError\n* @description A hook to create a `MagicError` instance and throw it.\n* @param {UseMagicErrorArgs} [args] - The arguments for the hook.\n* @returns {UseMagicErrorReturn} - The return value of the hook.\n*/\nfunction useMagicError(args = {}) {\n\tconst { prefix = \"MagicError\", source = \"payload-plugins\" } = args;\n\t/**\n\t* @function log\n\t* @description Logs a message to the console.\n\t* @param {string} message - The message to log.\n\t*/\n\tfunction log(message) {\n\t\tconsole.log(`[${prefix}]:`, message);\n\t}\n\t/**\n\t* @function logError\n\t* @description Logs an error message to the console.\n\t* @param {string} message - The message to log.\n\t*/\n\tfunction logError(message) {\n\t\tconsole.error(`[${prefix}]:`, message);\n\t}\n\t/**\n\t* @function logWarning\n\t* @description Logs a warning message to the console.\n\t* @param {string} message - The message to log.\n\t*/\n\tfunction logWarning(message) {\n\t\tconsole.warn(`[${prefix}]:`, message);\n\t}\n\t/**\n\t* @function throwError\n\t* @description Throws a `MagicError`.\n\t* @param {ThrowErrorArgs} args - The arguments for the error.\n\t* @throws {MagicError}\n\t*/\n\tfunction throwError(args$1) {\n\t\tconst { message, errorCode, cause } = args$1;\n\t\tconst error = new MagicError(`[${prefix}]: ${message}`, errorCode, source, { cause });\n\t\tlogError(message);\n\t\tthrow error;\n\t}\n\t/**\n\t* @function assert\n\t* @description Asserts that a value is not null or undefined.\n\t* @param {T} value - The value to assert.\n\t* @param {ThrowErrorArgs} args - The arguments for the error to throw if the assertion fails.\n\t* @throws {MagicError}\n\t*/\n\tfunction assert(value, args$1) {\n\t\tif (value === void 0 || value === null) throwError(args$1);\n\t}\n\treturn {\n\t\tassert,\n\t\tthrowError,\n\t\tlog,\n\t\tlogError,\n\t\tlogWarning,\n\t\tMagicError\n\t};\n}\n\n//#endregion\nexport { MagicError, useMagicError };\n//# sourceMappingURL=index.mjs.map"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAI,aAAa,MAAMA,qBAAmB,MAAM;;;;;;;;CAQ/C,YAAY,SAAS,WAAW,QAAQ,SAAS;AAChD,QAAM,SAAS,QAAQ;AACvB,OAAK,OAAO;AACZ,OAAK,YAAY;AACjB,OAAK,YAAY,KAAK,KAAK;AAC3B,OAAK,SAAS;AACd,MAAI,MAAM,kBAAmB,OAAM,kBAAkB,MAAMA,aAAW;;;;;;;;;AAYxE,SAAS,cAAc,OAAO,EAAE,EAAE;CACjC,MAAM,EAAE,SAAS,cAAc,SAAS,sBAAsB;;;;;;CAM9D,SAAS,IAAI,SAAS;AACrB,UAAQ,IAAI,IAAI,OAAO,KAAK,QAAQ;;;;;;;CAOrC,SAAS,SAAS,SAAS;AAC1B,UAAQ,MAAM,IAAI,OAAO,KAAK,QAAQ;;;;;;;CAOvC,SAAS,WAAW,SAAS;AAC5B,UAAQ,KAAK,IAAI,OAAO,KAAK,QAAQ;;;;;;;;CAQtC,SAAS,WAAW,QAAQ;EAC3B,MAAM,EAAE,SAAS,WAAW,UAAU;EACtC,MAAM,QAAQ,IAAI,WAAW,IAAI,OAAO,KAAK,WAAW,WAAW,QAAQ,EAAE,OAAO,CAAC;AACrF,WAAS,QAAQ;AACjB,QAAM;;;;;;;;;CASP,SAAS,OAAO,OAAO,QAAQ;AAC9B,MAAI,UAAU,KAAK,KAAK,UAAU,KAAM,YAAW,OAAO;;AAE3D,QAAO;EACN;EACA;EACA;EACA;EACA;EACA;EACA"}
|
|
@@ -1,183 +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: "Unknown storage type for media";
|
|
43
|
-
readonly errorCode: 500;
|
|
44
|
-
} | {
|
|
45
|
-
readonly message: "Unable to determine file type";
|
|
46
|
-
readonly errorCode: 400;
|
|
47
|
-
} | {
|
|
48
|
-
readonly message: "Error determining file type";
|
|
49
|
-
readonly errorCode: 500;
|
|
50
|
-
} | {
|
|
51
|
-
readonly message: "Error sanitizing filename";
|
|
52
|
-
readonly errorCode: 500;
|
|
53
|
-
} | {
|
|
54
|
-
readonly message: "Filename is missing, cannot parse file";
|
|
55
|
-
readonly errorCode: 500;
|
|
56
|
-
} | {
|
|
57
|
-
readonly message: "File not found";
|
|
58
|
-
readonly errorCode: 404;
|
|
59
|
-
} | {
|
|
60
|
-
readonly message: "Error setting media dimensions";
|
|
61
|
-
readonly errorCode: 500;
|
|
62
|
-
} | {
|
|
63
|
-
readonly message: "No upload URL provided, cannot parse upload ID";
|
|
64
|
-
readonly errorCode: 400;
|
|
65
|
-
} | {
|
|
66
|
-
readonly message: "Upload handler error occurred";
|
|
67
|
-
readonly errorCode: 500;
|
|
68
|
-
} | {
|
|
69
|
-
readonly message: "Polling error for upload";
|
|
70
|
-
readonly errorCode: 500;
|
|
71
|
-
} | {
|
|
72
|
-
readonly message: "Payload Media Cloud plugin is not configured";
|
|
73
|
-
readonly errorCode: 500;
|
|
74
|
-
} | {
|
|
75
|
-
readonly message: "Error in namingFunction";
|
|
76
|
-
readonly errorCode: 500;
|
|
77
|
-
}, overrideLevel?: LogLevel) => void;
|
|
78
|
-
throwError: (errorEntry: {
|
|
79
|
-
readonly message: "Mux configuration (tokenId and tokenSecret) must be provided in pluginOptions to use Mux";
|
|
80
|
-
readonly errorCode: 400;
|
|
81
|
-
} | {
|
|
82
|
-
readonly message: "Mux configuration is missing. Mux features will not be available";
|
|
83
|
-
readonly errorCode: 400;
|
|
84
|
-
} | {
|
|
85
|
-
readonly message: "No upload-id found for upload";
|
|
86
|
-
readonly errorCode: 400;
|
|
87
|
-
} | {
|
|
88
|
-
readonly message: "Error deleting Mux asset";
|
|
89
|
-
readonly errorCode: 500;
|
|
90
|
-
} | {
|
|
91
|
-
readonly message: "Mux video upload failed";
|
|
92
|
-
readonly errorCode: 500;
|
|
93
|
-
} | {
|
|
94
|
-
readonly message: "Mux direct upload failed";
|
|
95
|
-
readonly errorCode: 500;
|
|
96
|
-
} | {
|
|
97
|
-
readonly message: "Error in Mux create upload handler";
|
|
98
|
-
readonly errorCode: 500;
|
|
99
|
-
} | {
|
|
100
|
-
readonly message: "Request does not support json() method";
|
|
101
|
-
readonly errorCode: 400;
|
|
102
|
-
} | {
|
|
103
|
-
readonly message: "S3 configuration (bucket, region, accessKeyId, secretAccessKey) must be provided in pluginOptions";
|
|
104
|
-
readonly errorCode: 400;
|
|
105
|
-
} | {
|
|
106
|
-
readonly message: "Error deleting file from S3";
|
|
107
|
-
readonly errorCode: 500;
|
|
108
|
-
} | {
|
|
109
|
-
readonly message: "Could not find a unique file name after maximum tries";
|
|
110
|
-
readonly errorCode: 500;
|
|
111
|
-
} | {
|
|
112
|
-
readonly message: "TUS file upload error occurred";
|
|
113
|
-
readonly errorCode: 500;
|
|
114
|
-
} | {
|
|
115
|
-
readonly message: "Unknown storage type for media";
|
|
116
|
-
readonly errorCode: 500;
|
|
117
|
-
} | {
|
|
118
|
-
readonly message: "Unable to determine file type";
|
|
119
|
-
readonly errorCode: 400;
|
|
120
|
-
} | {
|
|
121
|
-
readonly message: "Error determining file type";
|
|
122
|
-
readonly errorCode: 500;
|
|
123
|
-
} | {
|
|
124
|
-
readonly message: "Error sanitizing filename";
|
|
125
|
-
readonly errorCode: 500;
|
|
126
|
-
} | {
|
|
127
|
-
readonly message: "Filename is missing, cannot parse file";
|
|
128
|
-
readonly errorCode: 500;
|
|
129
|
-
} | {
|
|
130
|
-
readonly message: "File not found";
|
|
131
|
-
readonly errorCode: 404;
|
|
132
|
-
} | {
|
|
133
|
-
readonly message: "Error setting media dimensions";
|
|
134
|
-
readonly errorCode: 500;
|
|
135
|
-
} | {
|
|
136
|
-
readonly message: "No upload URL provided, cannot parse upload ID";
|
|
137
|
-
readonly errorCode: 400;
|
|
138
|
-
} | {
|
|
139
|
-
readonly message: "Upload handler error occurred";
|
|
140
|
-
readonly errorCode: 500;
|
|
141
|
-
} | {
|
|
142
|
-
readonly message: "Polling error for upload";
|
|
143
|
-
readonly errorCode: 500;
|
|
144
|
-
} | {
|
|
145
|
-
readonly message: "Payload Media Cloud plugin is not configured";
|
|
146
|
-
readonly errorCode: 500;
|
|
147
|
-
} | {
|
|
148
|
-
readonly message: "Error in namingFunction";
|
|
149
|
-
readonly errorCode: 500;
|
|
150
|
-
}) => never;
|
|
151
|
-
log: (logEntry: {
|
|
152
|
-
readonly message: "Initializing multipart upload";
|
|
153
|
-
} | {
|
|
154
|
-
readonly message: "Multipart upload created";
|
|
155
|
-
} | {
|
|
156
|
-
readonly message: "Failed to finish upload";
|
|
157
|
-
} | {
|
|
158
|
-
readonly message: "Attempting to read file from S3";
|
|
159
|
-
} | {
|
|
160
|
-
readonly message: "Successfully read file from S3";
|
|
161
|
-
} | {
|
|
162
|
-
readonly message: "Failed to read file, trying again";
|
|
163
|
-
} | {
|
|
164
|
-
readonly message: "Failed to read file";
|
|
165
|
-
} | {
|
|
166
|
-
readonly message: "No file found";
|
|
167
|
-
} | {
|
|
168
|
-
readonly message: "Error retrieving parts";
|
|
169
|
-
} | {
|
|
170
|
-
readonly message: "Saving metadata";
|
|
171
|
-
} | {
|
|
172
|
-
readonly message: "Metadata file saved";
|
|
173
|
-
} | {
|
|
174
|
-
readonly message: "Removing cached data";
|
|
175
|
-
} | {
|
|
176
|
-
readonly message: "Finished uploading incomplete part";
|
|
177
|
-
} | {
|
|
178
|
-
readonly message: "Failed to remove chunk";
|
|
179
|
-
}) => void;
|
|
180
|
-
};
|
|
4
|
+
declare function useErrorHandler(): Omit<UseMagicErrorReturn, 'assert' | 'MagicError'>;
|
|
181
5
|
//#endregion
|
|
182
6
|
export { useErrorHandler };
|
|
183
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"}
|
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,32 +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 { createTusEndpoints, createTusServer } from "./utils/tus.mjs";
|
|
6
5
|
import { createS3Store } from "./tus/stores/s3/index.mjs";
|
|
7
6
|
import { createMuxClient, createMuxEndpoints, validateMuxConfig } from "./utils/mux.mjs";
|
|
7
|
+
import { createTusEndpoints, createTusServer } from "./utils/tus.mjs";
|
|
8
8
|
import { cloudStoragePlugin } from "@payloadcms/plugin-cloud-storage";
|
|
9
9
|
import { initClientUploads } from "@payloadcms/plugin-cloud-storage/utilities";
|
|
10
|
-
import deepmerge from "@fastify/deepmerge";
|
|
11
10
|
|
|
12
11
|
//#region src/plugin.ts
|
|
13
12
|
const { logError } = useErrorHandler();
|
|
14
13
|
let muxClient = null;
|
|
15
14
|
/**
|
|
16
15
|
* Media Cloud Plugin for Payload CMS
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
19
|
-
* @returns A function that configures the Payload config
|
|
16
|
+
* @param pluginOptions Configuration options
|
|
17
|
+
* @returns Payload config function
|
|
20
18
|
*/
|
|
21
19
|
function mediaCloudPlugin(pluginOptions) {
|
|
22
20
|
return function(config) {
|
|
23
21
|
if (!pluginOptions) {
|
|
24
|
-
logError(MediaCloudErrors.PLUGIN_NOT_CONFIGURED);
|
|
22
|
+
logError(MediaCloudErrors.PLUGIN_NOT_CONFIGURED.message);
|
|
25
23
|
return config;
|
|
26
24
|
}
|
|
27
25
|
if (pluginOptions.enabled === false) return config;
|
|
28
26
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @returns
|
|
27
|
+
* Helper function to get or create Mux client instance
|
|
28
|
+
* @returns Mux client instance
|
|
31
29
|
*/
|
|
32
30
|
function getMuxClient() {
|
|
33
31
|
if (muxClient) return muxClient;
|
|
@@ -37,7 +35,7 @@ function mediaCloudPlugin(pluginOptions) {
|
|
|
37
35
|
validateMuxConfig(pluginOptions.mux);
|
|
38
36
|
muxClient = getMuxClient();
|
|
39
37
|
} else {
|
|
40
|
-
logError(MediaCloudErrors.MUX_CONFIG_INCOMPLETE);
|
|
38
|
+
logError(MediaCloudErrors.MUX_CONFIG_INCOMPLETE.message);
|
|
41
39
|
muxClient = null;
|
|
42
40
|
}
|
|
43
41
|
const s3Store = createS3Store(pluginOptions.s3);
|
|
@@ -77,18 +75,28 @@ function mediaCloudPlugin(pluginOptions) {
|
|
|
77
75
|
clientUploads: true,
|
|
78
76
|
disableLocalStorage: true
|
|
79
77
|
} } };
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
78
|
+
const mergedConfig = {
|
|
79
|
+
...config,
|
|
80
|
+
admin: {
|
|
81
|
+
...config.admin,
|
|
82
|
+
components: {
|
|
83
|
+
...config.admin?.components,
|
|
84
|
+
providers: [...config.admin?.components?.providers ?? [], "@maas/payload-plugin-media-cloud/components#UploadManagerProvider"]
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
collections: [...config.collections ?? [], mediaCollection],
|
|
88
|
+
endpoints: [
|
|
89
|
+
...config.endpoints ?? [],
|
|
90
|
+
...createTusEndpoints({
|
|
91
|
+
tusServer,
|
|
92
|
+
s3Store
|
|
93
|
+
}),
|
|
94
|
+
...createMuxEndpoints({
|
|
95
|
+
getMuxClient,
|
|
96
|
+
pluginOptions
|
|
97
|
+
})
|
|
98
|
+
]
|
|
90
99
|
};
|
|
91
|
-
const mergedConfig = deepmerge({ all: true })(config, customConfig);
|
|
92
100
|
return cloudStoragePlugin(cloudStorageConfig)(mergedConfig);
|
|
93
101
|
};
|
|
94
102
|
}
|
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":["muxClient: Mux | null","mergedConfig: Config"],"sources":["../src/plugin.ts"],"sourcesContent":["import Mux from '@mux/mux-node'\
|
|
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"}
|
|
@@ -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;
|