forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload-thumbnails.ts
More file actions
44 lines (37 loc) · 1.27 KB
/
Copy pathupload-thumbnails.ts
File metadata and controls
44 lines (37 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use server';
import uploadThumbnail from './upload-thumbnail';
export default async function uploadThumbnails(
thumbnailUrls: string[],
token: string,
): Promise<string[]> {
const thumbnailIds: string[] = [];
if (thumbnailUrls.length === 0) {
return thumbnailIds;
}
console.log('📸 [uploadThumbnails] Uploading thumbnails...');
for (const thumbnailUrl of thumbnailUrls) {
try {
const response = await fetch(thumbnailUrl);
const blob = await response.blob();
const thumbnailFormData = new FormData();
thumbnailFormData.append('file', blob, 'thumbnail.jpg');
const thumbnailResult = await uploadThumbnail(thumbnailFormData, token);
if (thumbnailResult) {
thumbnailIds.push(thumbnailResult.thumbnail_id);
console.log(
'📸 [uploadThumbnails] Thumbnail uploaded successfully:',
thumbnailResult.thumbnail_id,
);
} else {
console.warn('⚠️ [uploadThumbnails] Failed to upload thumbnail');
}
} catch (thumbnailError) {
console.warn(
'⚠️ [uploadThumbnails] Error uploading thumbnail, continuing:',
thumbnailError,
);
}
}
console.log('📸 [uploadThumbnails] Thumbnail IDs collected:', thumbnailIds);
return thumbnailIds;
}