umwd-components 0.1.784 → 0.1.785
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/cjs/src/data/actions/media/minio/uploadMinioMediaAction.js +1 -1
- package/dist/cjs/src/data/services/common/media/minio/minioUploadService.js +1 -1
- package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/src/data/actions/media/minio/uploadMinioMediaAction.js +33 -48
- package/dist/esm/src/data/services/common/media/minio/minioUploadService.js +7 -5
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/types/data/services/common/media/minio/minioUploadService.d.ts +5 -1
- package/package.json +1 -1
|
@@ -55,73 +55,58 @@ async function uploadMinioMediaAction(prevState, formData) {
|
|
|
55
55
|
severity: "error",
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
// VALIDATE THE FILES
|
|
59
|
-
const validatedFields = {
|
|
60
|
-
success: true,
|
|
61
|
-
};
|
|
62
|
-
/* filesSchema.safeParse({
|
|
63
|
-
files: validFiles.length === 1 ? validFiles[0] : validFiles,
|
|
64
|
-
}); */
|
|
65
|
-
if (!validatedFields.success) ;
|
|
66
58
|
console.log(`Uploading ${validFiles.length} file(s):`);
|
|
67
|
-
//
|
|
68
|
-
const
|
|
69
|
-
const errors = [];
|
|
59
|
+
// Prepare files data for upload
|
|
60
|
+
const filesData = [];
|
|
70
61
|
for (const file of validFiles) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
uploadResults.push({
|
|
90
|
-
fileName: file.name,
|
|
91
|
-
data: flattenedData
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
catch (fileError) {
|
|
95
|
-
console.error(`Error uploading ${file.name}:`, fileError);
|
|
96
|
-
errors.push(`Failed to process ${file.name}`);
|
|
97
|
-
}
|
|
62
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
63
|
+
const fileContent = Buffer.from(arrayBuffer).toString("base64");
|
|
64
|
+
filesData.push({
|
|
65
|
+
fileName: file.name,
|
|
66
|
+
fileContent: fileContent,
|
|
67
|
+
});
|
|
68
|
+
console.log("Prepared file:", file.name, "Size:", Math.round(fileContent.length / 1024 / 1024), "MB");
|
|
69
|
+
}
|
|
70
|
+
// UPLOAD ALL FILES TO MINIO
|
|
71
|
+
const fileUploadResponse = await minioUploadService(bucketName, filesData, reference, refID, field);
|
|
72
|
+
if (!fileUploadResponse) {
|
|
73
|
+
return {
|
|
74
|
+
...prevState,
|
|
75
|
+
strapiErrors: null,
|
|
76
|
+
zodErrors: null,
|
|
77
|
+
message: "Failed to upload files",
|
|
78
|
+
severity: "error",
|
|
79
|
+
};
|
|
98
80
|
}
|
|
99
|
-
|
|
100
|
-
if (uploadResults.length === 0) {
|
|
81
|
+
if (fileUploadResponse.error) {
|
|
101
82
|
return {
|
|
102
83
|
...prevState,
|
|
103
|
-
strapiErrors:
|
|
84
|
+
strapiErrors: fileUploadResponse.error,
|
|
104
85
|
zodErrors: null,
|
|
105
|
-
message: "Failed to upload
|
|
86
|
+
message: "Failed to upload files",
|
|
106
87
|
severity: "error",
|
|
107
88
|
};
|
|
108
89
|
}
|
|
109
|
-
|
|
90
|
+
// Handle partial failures
|
|
91
|
+
if (fileUploadResponse.errors && fileUploadResponse.errors.length > 0) {
|
|
92
|
+
const successCount = fileUploadResponse.uploadResults?.length || 0;
|
|
93
|
+
const errorCount = fileUploadResponse.errors.length;
|
|
110
94
|
return {
|
|
111
95
|
...prevState,
|
|
112
|
-
data: uploadResults,
|
|
96
|
+
data: fileUploadResponse.uploadResults,
|
|
113
97
|
zodErrors: null,
|
|
114
98
|
strapiErrors: null,
|
|
115
|
-
message: `Uploaded ${
|
|
116
|
-
severity: "warning",
|
|
99
|
+
message: `Uploaded ${successCount} file(s) successfully. ${errorCount} file(s) failed.`,
|
|
100
|
+
severity: successCount > 0 ? "warning" : "error",
|
|
117
101
|
};
|
|
118
102
|
}
|
|
103
|
+
const flattenedData = flattenAttributes(fileUploadResponse);
|
|
119
104
|
return {
|
|
120
105
|
...prevState,
|
|
121
|
-
data:
|
|
106
|
+
data: flattenedData,
|
|
122
107
|
zodErrors: null,
|
|
123
108
|
strapiErrors: null,
|
|
124
|
-
message: `Successfully uploaded ${
|
|
109
|
+
message: `Successfully uploaded ${validFiles.length} file(s)`,
|
|
125
110
|
severity: "success",
|
|
126
111
|
};
|
|
127
112
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { getAuthToken } from '../../../get-token.js';
|
|
9
9
|
import { getStrapiURL } from '../../../../../lib/utils.js';
|
|
10
10
|
|
|
11
|
-
async function minioUploadService(bucketName,
|
|
11
|
+
async function minioUploadService(bucketName, files, reference, refID, field) {
|
|
12
12
|
const authToken = await getAuthToken();
|
|
13
13
|
if (!authToken)
|
|
14
14
|
throw new Error("No auth token found");
|
|
@@ -16,13 +16,15 @@ async function minioUploadService(bucketName, fileName, fileContent, reference,
|
|
|
16
16
|
const url = new URL("/api/minio-plugin/uploadbyreference", baseUrl);
|
|
17
17
|
try {
|
|
18
18
|
const response = await fetch(url, {
|
|
19
|
-
headers: {
|
|
19
|
+
headers: {
|
|
20
|
+
Authorization: `Bearer ${authToken}`,
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
},
|
|
20
23
|
method: "POST",
|
|
21
24
|
body: JSON.stringify({
|
|
22
25
|
data: {
|
|
23
26
|
bucketName,
|
|
24
|
-
|
|
25
|
-
fileContent,
|
|
27
|
+
files,
|
|
26
28
|
reference,
|
|
27
29
|
refID,
|
|
28
30
|
field,
|
|
@@ -33,7 +35,7 @@ async function minioUploadService(bucketName, fileName, fileContent, reference,
|
|
|
33
35
|
return dataResponse;
|
|
34
36
|
}
|
|
35
37
|
catch (error) {
|
|
36
|
-
console.error("Error uploading
|
|
38
|
+
console.error("Error uploading files:", error);
|
|
37
39
|
throw error;
|
|
38
40
|
}
|
|
39
41
|
}
|