@widgetic/file-browser 0.5.17
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/README.md +131 -0
- package/dist/components/FolderTree.svelte +143 -0
- package/dist/components/FolderTree.svelte.d.ts +32 -0
- package/dist/components/core/FileBrowser.css +79 -0
- package/dist/components/core/FileBrowser.svelte +3989 -0
- package/dist/components/core/FileBrowser.svelte.d.ts +55 -0
- package/dist/components/core/FileUploader.svelte +1152 -0
- package/dist/components/core/FileUploader.svelte.d.ts +43 -0
- package/dist/components/core/Header.svelte +143 -0
- package/dist/components/core/Header.svelte.d.ts +36 -0
- package/dist/components/core/RecentFiles.svelte +753 -0
- package/dist/components/core/RecentFiles.svelte.d.ts +37 -0
- package/dist/components/core/UploadStatus.svelte +133 -0
- package/dist/components/core/UploadStatus.svelte.d.ts +28 -0
- package/dist/components/core/UploadStatusList.svelte +138 -0
- package/dist/components/core/UploadStatusList.svelte.d.ts +33 -0
- package/dist/components/core/index.d.ts +4 -0
- package/dist/components/core/index.js +4 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.js +8 -0
- package/dist/components/items/FileItem.svelte +684 -0
- package/dist/components/items/FileItem.svelte.d.ts +34 -0
- package/dist/components/items/FolderItem.svelte +77 -0
- package/dist/components/items/FolderItem.svelte.d.ts +27 -0
- package/dist/components/items/index.d.ts +2 -0
- package/dist/components/items/index.js +2 -0
- package/dist/components/modals/MoveDialog.svelte +539 -0
- package/dist/components/modals/MoveDialog.svelte.d.ts +32 -0
- package/dist/components/modals/NewFolderButton.svelte +25 -0
- package/dist/components/modals/NewFolderButton.svelte.d.ts +20 -0
- package/dist/components/modals/README.md +99 -0
- package/dist/components/modals/SearchModal.svelte +500 -0
- package/dist/components/modals/SearchModal.svelte.d.ts +28 -0
- package/dist/components/modals/SelectedFilesModal.svelte +291 -0
- package/dist/components/modals/SelectedFilesModal.svelte.d.ts +32 -0
- package/dist/components/modals/index.d.ts +6 -0
- package/dist/components/modals/index.js +9 -0
- package/dist/components/previews/AudioPlayer.svelte +117 -0
- package/dist/components/previews/AudioPlayer.svelte.d.ts +22 -0
- package/dist/components/previews/ErrorPreview.svelte +12 -0
- package/dist/components/previews/ErrorPreview.svelte.d.ts +20 -0
- package/dist/components/previews/FilePreview.svelte +475 -0
- package/dist/components/previews/FilePreview.svelte.d.ts +31 -0
- package/dist/components/previews/FontPreview.svelte +82 -0
- package/dist/components/previews/FontPreview.svelte.d.ts +22 -0
- package/dist/components/previews/ImagePreview.svelte +551 -0
- package/dist/components/previews/ImagePreview.svelte.d.ts +27 -0
- package/dist/components/previews/TextPreview.svelte +92 -0
- package/dist/components/previews/TextPreview.svelte.d.ts +20 -0
- package/dist/components/previews/VideoPlayer.svelte +268 -0
- package/dist/components/previews/VideoPlayer.svelte.d.ts +22 -0
- package/dist/components/previews/WaveformVisualizer.svelte +240 -0
- package/dist/components/previews/WaveformVisualizer.svelte.d.ts +20 -0
- package/dist/components/previews/index.d.ts +8 -0
- package/dist/components/previews/index.js +8 -0
- package/dist/components/ui/ControlToolbar.svelte +342 -0
- package/dist/components/ui/ControlToolbar.svelte.d.ts +36 -0
- package/dist/components/ui/DragSelect.svelte +815 -0
- package/dist/components/ui/DragSelect.svelte.d.ts +31 -0
- package/dist/components/ui/DropdownMenu.svelte +83 -0
- package/dist/components/ui/DropdownMenu.svelte.d.ts +25 -0
- package/dist/components/ui/FileIcon.svelte +65 -0
- package/dist/components/ui/FileIcon.svelte.d.ts +25 -0
- package/dist/components/ui/FileMetadata.svelte +26 -0
- package/dist/components/ui/FileMetadata.svelte.d.ts +21 -0
- package/dist/components/ui/LoadingSkeleton.svelte +26 -0
- package/dist/components/ui/LoadingSkeleton.svelte.d.ts +22 -0
- package/dist/components/ui/SearchResults.svelte +37 -0
- package/dist/components/ui/SearchResults.svelte.d.ts +21 -0
- package/dist/components/ui/VirtualList.svelte +106 -0
- package/dist/components/ui/VirtualList.svelte.d.ts +45 -0
- package/dist/components/ui/index.d.ts +8 -0
- package/dist/components/ui/index.js +8 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.js +14 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +11 -0
- package/dist/static/favicon.png +0 -0
- package/dist/static/files/audio/audio-file.mp3 +0 -0
- package/dist/static/files/document/-missing-file.txt +1 -0
- package/dist/static/files/document/HeliosDesign Website Project Brief Sample.pdf +0 -0
- package/dist/static/files/document/RFP-NEC_Website-Development_2021-August.pdf +0 -0
- package/dist/static/files/document/The World Before Calculus.pdf +0 -0
- package/dist/static/files/document/specs.txt +15 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Bold.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-BoldItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Book.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-BookItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Heavy.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-HeavyItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Light.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-LightItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Medium.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-MediumItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Semibold.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-SemiboldItalic.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-Thin.otf +0 -0
- package/dist/static/files/font/CooperHewitt/CooperHewitt-ThinItalic.otf +0 -0
- package/dist/static/files/font/Kimpo/Kimpo-Bold.otf +0 -0
- package/dist/static/files/font/Kimpo/Kimpo-Regular.otf +0 -0
- package/dist/static/files/image/image 1.jpg +0 -0
- package/dist/static/files/image/image 10.jpg +0 -0
- package/dist/static/files/image/image 11.jpg +0 -0
- package/dist/static/files/image/image 12.jpg +0 -0
- package/dist/static/files/image/image 13.jpg +0 -0
- package/dist/static/files/image/image 14.jpg +0 -0
- package/dist/static/files/image/image 15.jpg +0 -0
- package/dist/static/files/image/image 16.jpg +0 -0
- package/dist/static/files/image/image 17.jpg +0 -0
- package/dist/static/files/image/image 18.jpg +0 -0
- package/dist/static/files/image/image 19.jpg +0 -0
- package/dist/static/files/image/image 2.jpg +0 -0
- package/dist/static/files/image/image 20.jpg +0 -0
- package/dist/static/files/image/image 21.jpg +0 -0
- package/dist/static/files/image/image 22.jpg +0 -0
- package/dist/static/files/image/image 23.jpg +0 -0
- package/dist/static/files/image/image 24.jpg +0 -0
- package/dist/static/files/image/image 25.jpg +0 -0
- package/dist/static/files/image/image 26.jpg +0 -0
- package/dist/static/files/image/image 27.jpg +0 -0
- package/dist/static/files/image/image 28.jpg +0 -0
- package/dist/static/files/image/image 29.jpg +0 -0
- package/dist/static/files/image/image 3.jpg +0 -0
- package/dist/static/files/image/image 30.jpg +0 -0
- package/dist/static/files/image/image 31.jpg +0 -0
- package/dist/static/files/image/image 32.jpg +0 -0
- package/dist/static/files/image/image 33.jpg +0 -0
- package/dist/static/files/image/image 34.jpg +0 -0
- package/dist/static/files/image/image 35.jpg +0 -0
- package/dist/static/files/image/image 36.jpg +0 -0
- package/dist/static/files/image/image 37.jpg +0 -0
- package/dist/static/files/image/image 38.jpg +0 -0
- package/dist/static/files/image/image 39.jpg +0 -0
- package/dist/static/files/image/image 4.jpg +0 -0
- package/dist/static/files/image/image 40.jpg +0 -0
- package/dist/static/files/image/image 41.jpg +0 -0
- package/dist/static/files/image/image 42.jpg +0 -0
- package/dist/static/files/image/image 43.jpg +0 -0
- package/dist/static/files/image/image 44.jpg +0 -0
- package/dist/static/files/image/image 45.jpg +0 -0
- package/dist/static/files/image/image 46.jpg +0 -0
- package/dist/static/files/image/image 47.jpg +0 -0
- package/dist/static/files/image/image 48.jpg +0 -0
- package/dist/static/files/image/image 49.jpg +0 -0
- package/dist/static/files/image/image 5.jpg +0 -0
- package/dist/static/files/image/image 50.jpg +0 -0
- package/dist/static/files/image/image 51.jpg +0 -0
- package/dist/static/files/image/image 52.jpg +0 -0
- package/dist/static/files/image/image 53.jpg +0 -0
- package/dist/static/files/image/image 54.jpg +0 -0
- package/dist/static/files/image/image 55.jpg +0 -0
- package/dist/static/files/image/image 56.jpg +0 -0
- package/dist/static/files/image/image 57.jpg +0 -0
- package/dist/static/files/image/image 58.jpg +0 -0
- package/dist/static/files/image/image 59.jpg +0 -0
- package/dist/static/files/image/image 6.jpg +0 -0
- package/dist/static/files/image/image 60.jpg +0 -0
- package/dist/static/files/image/image 61.jpg +0 -0
- package/dist/static/files/image/image 62.jpg +0 -0
- package/dist/static/files/image/image 63.jpg +0 -0
- package/dist/static/files/image/image 64.jpg +0 -0
- package/dist/static/files/image/image 65.jpg +0 -0
- package/dist/static/files/image/image 66.jpg +0 -0
- package/dist/static/files/image/image 67.jpg +0 -0
- package/dist/static/files/image/image 68.jpg +0 -0
- package/dist/static/files/image/image 7.jpg +0 -0
- package/dist/static/files/image/image 8.jpg +0 -0
- package/dist/static/files/image/image 9.jpg +0 -0
- package/dist/static/files/svg/astronaut.svg +30 -0
- package/dist/static/files/svg/cook.svg +30 -0
- package/dist/static/files/svg/dj.svg +28 -0
- package/dist/static/files/svg/doctor.svg +29 -0
- package/dist/static/files/svg/farmer.svg +43 -0
- package/dist/static/files/svg/fire fighter.svg +40 -0
- package/dist/static/files/svg/plumber.svg +32 -0
- package/dist/static/files/svg/santa.svg +34 -0
- package/dist/static/files/svg/scientist.svg +31 -0
- package/dist/static/files/svg/student.svg +32 -0
- package/dist/static/files/thumbnail/image 1.jpg +0 -0
- package/dist/static/files/thumbnail/image 10.jpg +0 -0
- package/dist/static/files/thumbnail/image 11.jpg +0 -0
- package/dist/static/files/thumbnail/image 12.jpg +0 -0
- package/dist/static/files/thumbnail/image 13.jpg +0 -0
- package/dist/static/files/thumbnail/image 14.jpg +0 -0
- package/dist/static/files/thumbnail/image 15.jpg +0 -0
- package/dist/static/files/thumbnail/image 16.jpg +0 -0
- package/dist/static/files/thumbnail/image 17.jpg +0 -0
- package/dist/static/files/thumbnail/image 18.jpg +0 -0
- package/dist/static/files/thumbnail/image 19.jpg +0 -0
- package/dist/static/files/thumbnail/image 2.jpg +0 -0
- package/dist/static/files/thumbnail/image 20.jpg +0 -0
- package/dist/static/files/thumbnail/image 21.jpg +0 -0
- package/dist/static/files/thumbnail/image 22.jpg +0 -0
- package/dist/static/files/thumbnail/image 23.jpg +0 -0
- package/dist/static/files/thumbnail/image 24.jpg +0 -0
- package/dist/static/files/thumbnail/image 25.jpg +0 -0
- package/dist/static/files/thumbnail/image 26.jpg +0 -0
- package/dist/static/files/thumbnail/image 27.jpg +0 -0
- package/dist/static/files/thumbnail/image 28.jpg +0 -0
- package/dist/static/files/thumbnail/image 29.jpg +0 -0
- package/dist/static/files/thumbnail/image 3.jpg +0 -0
- package/dist/static/files/thumbnail/image 30.jpg +0 -0
- package/dist/static/files/thumbnail/image 31.jpg +0 -0
- package/dist/static/files/thumbnail/image 32.jpg +0 -0
- package/dist/static/files/thumbnail/image 33.jpg +0 -0
- package/dist/static/files/thumbnail/image 34.jpg +0 -0
- package/dist/static/files/thumbnail/image 35.jpg +0 -0
- package/dist/static/files/thumbnail/image 36.jpg +0 -0
- package/dist/static/files/thumbnail/image 37.jpg +0 -0
- package/dist/static/files/thumbnail/image 38.jpg +0 -0
- package/dist/static/files/thumbnail/image 39.jpg +0 -0
- package/dist/static/files/thumbnail/image 4.jpg +0 -0
- package/dist/static/files/thumbnail/image 40.jpg +0 -0
- package/dist/static/files/thumbnail/image 41.jpg +0 -0
- package/dist/static/files/thumbnail/image 42.jpg +0 -0
- package/dist/static/files/thumbnail/image 43.jpg +0 -0
- package/dist/static/files/thumbnail/image 44.jpg +0 -0
- package/dist/static/files/thumbnail/image 45.jpg +0 -0
- package/dist/static/files/thumbnail/image 46.jpg +0 -0
- package/dist/static/files/thumbnail/image 47.jpg +0 -0
- package/dist/static/files/thumbnail/image 48.jpg +0 -0
- package/dist/static/files/thumbnail/image 49.jpg +0 -0
- package/dist/static/files/thumbnail/image 5.jpg +0 -0
- package/dist/static/files/thumbnail/image 50.jpg +0 -0
- package/dist/static/files/thumbnail/image 51.jpg +0 -0
- package/dist/static/files/thumbnail/image 52.jpg +0 -0
- package/dist/static/files/thumbnail/image 53.jpg +0 -0
- package/dist/static/files/thumbnail/image 54.jpg +0 -0
- package/dist/static/files/thumbnail/image 55.jpg +0 -0
- package/dist/static/files/thumbnail/image 56.jpg +0 -0
- package/dist/static/files/thumbnail/image 57.jpg +0 -0
- package/dist/static/files/thumbnail/image 58.jpg +0 -0
- package/dist/static/files/thumbnail/image 59.jpg +0 -0
- package/dist/static/files/thumbnail/image 6.jpg +0 -0
- package/dist/static/files/thumbnail/image 60.jpg +0 -0
- package/dist/static/files/thumbnail/image 61.jpg +0 -0
- package/dist/static/files/thumbnail/image 62.jpg +0 -0
- package/dist/static/files/thumbnail/image 63.jpg +0 -0
- package/dist/static/files/thumbnail/image 64.jpg +0 -0
- package/dist/static/files/thumbnail/image 65.jpg +0 -0
- package/dist/static/files/thumbnail/image 66.jpg +0 -0
- package/dist/static/files/thumbnail/image 67.jpg +0 -0
- package/dist/static/files/thumbnail/image 68.jpg +0 -0
- package/dist/static/files/thumbnail/image 7.jpg +0 -0
- package/dist/static/files/thumbnail/image 8.jpg +0 -0
- package/dist/static/files/thumbnail/image 9.jpg +0 -0
- package/dist/static/files/video/video-file.mp4 +0 -0
- package/dist/static/files/video/video-file.png +0 -0
- package/dist/static/icons/audio.svg +7 -0
- package/dist/static/icons/check.svg +3 -0
- package/dist/static/icons/checked.svg +4 -0
- package/dist/static/icons/close.svg +11 -0
- package/dist/static/icons/document.svg +11 -0
- package/dist/static/icons/dots.svg +1 -0
- package/dist/static/icons/download.svg +1 -0
- package/dist/static/icons/empty-folder.svg +24 -0
- package/dist/static/icons/error.svg +5 -0
- package/dist/static/icons/file-upload.svg +1 -0
- package/dist/static/icons/folder-plus.svg +1 -0
- package/dist/static/icons/folder.svg +28 -0
- package/dist/static/icons/jump-to-folder.svg +1 -0
- package/dist/static/icons/move.svg +1 -0
- package/dist/static/icons/new-folder.svg +5 -0
- package/dist/static/icons/pdf.svg +6 -0
- package/dist/static/icons/player-pause.svg +1 -0
- package/dist/static/icons/player-play.svg +3 -0
- package/dist/static/icons/plus.svg +1 -0
- package/dist/static/icons/rename.svg +1 -0
- package/dist/static/icons/search.svg +1 -0
- package/dist/static/icons/trash.svg +1 -0
- package/dist/static/icons/unorganized-folder.svg +60 -0
- package/dist/stores/dragStore.d.ts +2 -0
- package/dist/stores/dragStore.js +2 -0
- package/dist/stores/fileStore.d.ts +36 -0
- package/dist/stores/fileStore.js +166 -0
- package/dist/stores/folderCountStore.d.ts +5 -0
- package/dist/stores/folderCountStore.js +49 -0
- package/dist/stores/index.d.ts +7 -0
- package/dist/stores/index.js +8 -0
- package/dist/stores/missingFilesStore.d.ts +3 -0
- package/dist/stores/missingFilesStore.js +14 -0
- package/dist/stores/navigationStore.d.ts +36 -0
- package/dist/stores/navigationStore.js +615 -0
- package/dist/stores/persistentSelectStore.d.ts +17 -0
- package/dist/stores/persistentSelectStore.js +170 -0
- package/dist/stores/searchStore.d.ts +1 -0
- package/dist/stores/searchStore.js +2 -0
- package/dist/stores/uploadApiStore.d.ts +13 -0
- package/dist/stores/uploadApiStore.js +36 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/pdf.d.ts +3 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.js +1 -0
- package/dist/utils/apiConfig.d.ts +9 -0
- package/dist/utils/apiConfig.js +19 -0
- package/dist/utils/dateUtils.d.ts +2 -0
- package/dist/utils/dateUtils.js +38 -0
- package/dist/utils/fileOperations.d.ts +36 -0
- package/dist/utils/fileOperations.js +573 -0
- package/dist/utils/fileTypes.d.ts +17 -0
- package/dist/utils/fileTypes.js +110 -0
- package/dist/utils/fileUtils.d.ts +15 -0
- package/dist/utils/fileUtils.js +112 -0
- package/dist/utils/folderUtils.d.ts +4 -0
- package/dist/utils/folderUtils.js +26 -0
- package/dist/utils/imageTransform.d.ts +22 -0
- package/dist/utils/imageTransform.js +60 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/resolveFileUrl.d.ts +6 -0
- package/dist/utils/resolveFileUrl.js +21 -0
- package/dist/utils/userUploadsStorage.d.ts +27 -0
- package/dist/utils/userUploadsStorage.js +168 -0
- package/dist/utils/widgeticTusUpload.d.ts +18 -0
- package/dist/utils/widgeticTusUpload.js +131 -0
- package/dist/utils/widgeticUpload.d.ts +29 -0
- package/dist/utils/widgeticUpload.js +105 -0
- package/package.json +156 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Define which document types can be displayed as text
|
|
2
|
+
export const PREVIEWABLE_TEXT_EXTENSIONS = ['.txt', '.md', '.csv', '.json', '.xml', '.log'];
|
|
3
|
+
export const FILE_TYPES = {
|
|
4
|
+
image: ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.heic', '.heif'],
|
|
5
|
+
audio: ['.mp3'],
|
|
6
|
+
video: ['.mp4'],
|
|
7
|
+
document: ['.pdf', '.doc', '.docx', '.txt', '.md', '.csv', '.json', '.xml', '.log'],
|
|
8
|
+
font: ['.ttf', '.otf', '.woff', '.woff2'],
|
|
9
|
+
svg: ['.svg']
|
|
10
|
+
};
|
|
11
|
+
export const FILTER_OPTIONS = ['all', 'image', 'audio', 'video', 'document', 'font', 'svg'];
|
|
12
|
+
export function getAllowedFileTypes(filter) {
|
|
13
|
+
if (filter === 'all') {
|
|
14
|
+
return Object.values(FILE_TYPES).flat();
|
|
15
|
+
}
|
|
16
|
+
return FILE_TYPES[filter];
|
|
17
|
+
}
|
|
18
|
+
export function getFileTypeFromExtension(extension) {
|
|
19
|
+
extension = extension.toLowerCase();
|
|
20
|
+
for (const [type, extensions] of Object.entries(FILE_TYPES)) {
|
|
21
|
+
if (extensions.some(ext => ext.toLowerCase() === extension)) {
|
|
22
|
+
return type;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return 'all';
|
|
26
|
+
}
|
|
27
|
+
// New function to check if a file can be displayed as text
|
|
28
|
+
export function isPreviewableTextFile(filename) {
|
|
29
|
+
const extension = '.' + filename.split('.').pop()?.toLowerCase();
|
|
30
|
+
return PREVIEWABLE_TEXT_EXTENSIONS.includes(extension);
|
|
31
|
+
}
|
|
32
|
+
export function formatFileTypesForDisplay() {
|
|
33
|
+
const imageTypes = FILE_TYPES.image.join(', ');
|
|
34
|
+
const audioTypes = FILE_TYPES.audio.join(', ');
|
|
35
|
+
const videoTypes = FILE_TYPES.video.join(', ');
|
|
36
|
+
const documentTypes = FILE_TYPES.document.join(', ');
|
|
37
|
+
const fontTypes = FILE_TYPES.font.join(', ');
|
|
38
|
+
const svgType = FILE_TYPES.svg.join(', ');
|
|
39
|
+
return `Add images (${imageTypes}), audio (${audioTypes}), video (${videoTypes}), documents (${documentTypes}), fonts (${fontTypes}) or vector graphics (${svgType}).`;
|
|
40
|
+
}
|
|
41
|
+
export function formatAllowedTypesForDisplay(filter) {
|
|
42
|
+
if (filter === 'all') {
|
|
43
|
+
return `Allowed types: ${Object.values(FILE_TYPES).flat().join(', ')}`;
|
|
44
|
+
}
|
|
45
|
+
let allowedTypes = '';
|
|
46
|
+
if (filter === 'svg') {
|
|
47
|
+
allowedTypes = 'Allowed types: SVG files (.svg)';
|
|
48
|
+
}
|
|
49
|
+
else if (filter === 'document') {
|
|
50
|
+
allowedTypes = `Allowed types: document files (${FILE_TYPES[filter].join(', ')})`;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
allowedTypes = `Allowed types: ${FILE_TYPES[filter].join(', ')}`;
|
|
54
|
+
}
|
|
55
|
+
if (filter === 'font') {
|
|
56
|
+
allowedTypes += '\n\nFont naming convention:\nFontFamily-Weight.extension\n\nExample:\nGeistMono-Black.ttf';
|
|
57
|
+
}
|
|
58
|
+
return allowedTypes;
|
|
59
|
+
}
|
|
60
|
+
export const MIME_TYPES = {
|
|
61
|
+
// Images
|
|
62
|
+
'image/jpeg': '.jpg',
|
|
63
|
+
'image/jpg': '.jpg',
|
|
64
|
+
'image/png': '.png',
|
|
65
|
+
'image/gif': '.gif',
|
|
66
|
+
'image/webp': '.webp',
|
|
67
|
+
'image/svg+xml': '.svg',
|
|
68
|
+
// HEIC/HEIF — converted to JPEG server-side on upload
|
|
69
|
+
'image/heic': '.heic',
|
|
70
|
+
'image/heif': '.heif',
|
|
71
|
+
// Audio
|
|
72
|
+
'audio/mpeg': '.mp3',
|
|
73
|
+
'audio/mp3': '.mp3',
|
|
74
|
+
// Video
|
|
75
|
+
'video/mp4': '.mp4',
|
|
76
|
+
// Documents
|
|
77
|
+
'application/pdf': '.pdf',
|
|
78
|
+
'application/msword': '.doc',
|
|
79
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': '.docx',
|
|
80
|
+
'text/plain': '.txt',
|
|
81
|
+
'text/markdown': '.md',
|
|
82
|
+
'text/csv': '.csv',
|
|
83
|
+
'application/json': '.json',
|
|
84
|
+
'text/xml': '.xml',
|
|
85
|
+
'text/log': '.log',
|
|
86
|
+
'application/vnd.ms-excel': '.xls',
|
|
87
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': '.xlsx',
|
|
88
|
+
// Fonts
|
|
89
|
+
'font/ttf': '.ttf',
|
|
90
|
+
'font/otf': '.otf',
|
|
91
|
+
'font/woff': '.woff',
|
|
92
|
+
'font/woff2': '.woff2'
|
|
93
|
+
};
|
|
94
|
+
export function getMimeTypeExtension(mimeType) {
|
|
95
|
+
return MIME_TYPES[mimeType] || '.' + mimeType.split('/').pop();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Chrome reports an empty MIME type for HEIC/HEIF files, which would fail upload
|
|
99
|
+
* validation. Re-wraps such files with the correct type so both multipart and TUS
|
|
100
|
+
* uploads declare image/heic.
|
|
101
|
+
*/
|
|
102
|
+
export function normalizeFileMimeType(file) {
|
|
103
|
+
if (file.type)
|
|
104
|
+
return file;
|
|
105
|
+
const extension = '.' + file.name.split('.').pop()?.toLowerCase();
|
|
106
|
+
if (extension === '.heic' || extension === '.heif') {
|
|
107
|
+
return new File([file], file.name, { type: 'image/heic', lastModified: file.lastModified });
|
|
108
|
+
}
|
|
109
|
+
return file;
|
|
110
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type FileFilterType } from './fileTypes';
|
|
2
|
+
export declare function formatFileSize(bytes: number): string;
|
|
3
|
+
export declare function getFileIcon(fileName: string): string;
|
|
4
|
+
export declare function getFileExtension(fileNameOrUrl: string): string;
|
|
5
|
+
export declare function getFileType(fileNameOrUrl: string): FileFilterType;
|
|
6
|
+
export declare function checkFileExists(url: string | undefined): Promise<boolean>;
|
|
7
|
+
/**
|
|
8
|
+
* Gets the correct URL for a static asset using SvelteKit's assets path
|
|
9
|
+
* This leverages SvelteKit's handling of static assets in packages:
|
|
10
|
+
* https://kit.svelte.dev/docs/kit/$app-paths#assets
|
|
11
|
+
*
|
|
12
|
+
* @param path The relative path to the asset (should start with /)
|
|
13
|
+
* @returns The corrected path that will work in both local development and when imported as a package
|
|
14
|
+
*/
|
|
15
|
+
export declare function getAssetUrl(path: string): string;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { FILE_TYPES } from './fileTypes';
|
|
2
|
+
import icAudio from '../static/icons/audio.svg?url';
|
|
3
|
+
import icChecked from '../static/icons/checked.svg?url';
|
|
4
|
+
import icDocument from '../static/icons/document.svg?url';
|
|
5
|
+
import icDots from '../static/icons/dots.svg?url';
|
|
6
|
+
import icEmptyFolder from '../static/icons/empty-folder.svg?url';
|
|
7
|
+
import icError from '../static/icons/error.svg?url';
|
|
8
|
+
import icFolder from '../static/icons/folder.svg?url';
|
|
9
|
+
import icJumpToFolder from '../static/icons/jump-to-folder.svg?url';
|
|
10
|
+
import icNewFolder from '../static/icons/new-folder.svg?url';
|
|
11
|
+
import icPlayerPlay from '../static/icons/player-play.svg?url';
|
|
12
|
+
import icUnorganizedFolder from '../static/icons/unorganized-folder.svg?url';
|
|
13
|
+
/**
|
|
14
|
+
* Pattern to match if a path is already an absolute URL
|
|
15
|
+
* This will match http://, https://, data:, etc.
|
|
16
|
+
*/
|
|
17
|
+
const absoluteUrlPattern = /^(?:[a-z+]+:)?\/\//i;
|
|
18
|
+
// Show logs for debugging
|
|
19
|
+
let showLogs = false;
|
|
20
|
+
const bundledIconUrls = {
|
|
21
|
+
'/icons/audio.svg': icAudio,
|
|
22
|
+
'/icons/checked.svg': icChecked,
|
|
23
|
+
'/icons/document.svg': icDocument,
|
|
24
|
+
'/icons/dots.svg': icDots,
|
|
25
|
+
'/icons/empty-folder.svg': icEmptyFolder,
|
|
26
|
+
'/icons/error.svg': icError,
|
|
27
|
+
'/icons/folder.svg': icFolder,
|
|
28
|
+
'/icons/jump-to-folder.svg': icJumpToFolder,
|
|
29
|
+
'/icons/new-folder.svg': icNewFolder,
|
|
30
|
+
'/icons/player-play.svg': icPlayerPlay,
|
|
31
|
+
'/icons/unorganized-folder.svg': icUnorganizedFolder,
|
|
32
|
+
};
|
|
33
|
+
export function formatFileSize(bytes) {
|
|
34
|
+
if (bytes === 0)
|
|
35
|
+
return '0 Bytes';
|
|
36
|
+
const k = 1024;
|
|
37
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
38
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
39
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
40
|
+
}
|
|
41
|
+
export function getFileIcon(fileName) {
|
|
42
|
+
const fileType = getFileType(fileName);
|
|
43
|
+
const extension = getFileExtension(fileName).toLowerCase();
|
|
44
|
+
switch (fileType) {
|
|
45
|
+
case 'audio':
|
|
46
|
+
return getAssetUrl('/icons/audio.svg');
|
|
47
|
+
case 'document':
|
|
48
|
+
if (extension === '.pdf') {
|
|
49
|
+
return getAssetUrl('/icons/document.svg');
|
|
50
|
+
}
|
|
51
|
+
return getAssetUrl('/icons/document.svg');
|
|
52
|
+
case 'video':
|
|
53
|
+
return getAssetUrl('/icons/document.svg');
|
|
54
|
+
case 'svg':
|
|
55
|
+
return fileName;
|
|
56
|
+
case 'font':
|
|
57
|
+
return 'aA';
|
|
58
|
+
default:
|
|
59
|
+
return getAssetUrl('/icons/document.svg');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function getFileExtension(fileNameOrUrl) {
|
|
63
|
+
const cleanPath = fileNameOrUrl.split(/[?#]/)[0];
|
|
64
|
+
const fileName = cleanPath.split('/').pop() || '';
|
|
65
|
+
const extension = fileName.split('.').pop()?.toLowerCase() || '';
|
|
66
|
+
return extension ? `.${extension}` : '';
|
|
67
|
+
}
|
|
68
|
+
export function getFileType(fileNameOrUrl) {
|
|
69
|
+
const extension = getFileExtension(fileNameOrUrl);
|
|
70
|
+
for (const [type, extensions] of Object.entries(FILE_TYPES)) {
|
|
71
|
+
if (extensions.includes(extension.toLowerCase())) {
|
|
72
|
+
return type;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return 'document';
|
|
76
|
+
}
|
|
77
|
+
export async function checkFileExists(url) {
|
|
78
|
+
if (!url)
|
|
79
|
+
return false;
|
|
80
|
+
try {
|
|
81
|
+
const response = await fetch(url, { method: 'HEAD' });
|
|
82
|
+
return response.ok;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Gets the correct URL for a static asset using SvelteKit's assets path
|
|
90
|
+
* This leverages SvelteKit's handling of static assets in packages:
|
|
91
|
+
* https://kit.svelte.dev/docs/kit/$app-paths#assets
|
|
92
|
+
*
|
|
93
|
+
* @param path The relative path to the asset (should start with /)
|
|
94
|
+
* @returns The corrected path that will work in both local development and when imported as a package
|
|
95
|
+
*/
|
|
96
|
+
export function getAssetUrl(path) {
|
|
97
|
+
// if(showLogs) console.log('getAssetUrl: path:', path);
|
|
98
|
+
// If the URL is already absolute, return it as is
|
|
99
|
+
if (absoluteUrlPattern.test(path))
|
|
100
|
+
return path;
|
|
101
|
+
// Ensure path starts with a slash
|
|
102
|
+
let normalizedPath = path.startsWith('/') ? path : `/${path}`;
|
|
103
|
+
if (bundledIconUrls[normalizedPath]) {
|
|
104
|
+
return bundledIconUrls[normalizedPath];
|
|
105
|
+
}
|
|
106
|
+
// Use the API_BASE_URL for local development
|
|
107
|
+
// return `${API_BASE_URL}${normalizedPath}`;
|
|
108
|
+
if (showLogs)
|
|
109
|
+
console.log('getAssetUrl: in development, using relative path from static folder:', normalizedPath);
|
|
110
|
+
// Return the normalized path
|
|
111
|
+
return normalizedPath;
|
|
112
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FileSystemItem } from '../types';
|
|
2
|
+
import type { FileFilterType } from './fileTypes';
|
|
3
|
+
export declare function countFilteredItems(folder: FileSystemItem, filter: string): number;
|
|
4
|
+
export declare function getFolderIcon(folder: FileSystemItem, filter: FileFilterType): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getFileType, getAssetUrl } from './fileUtils';
|
|
2
|
+
const UNORGANIZED_THRESHOLD = 50;
|
|
3
|
+
export function countFilteredItems(folder, filter) {
|
|
4
|
+
let count = 0;
|
|
5
|
+
if (folder.type === 'folder' && folder.children) {
|
|
6
|
+
for (const item of folder.children) {
|
|
7
|
+
if (item.type === 'folder') {
|
|
8
|
+
count += countFilteredItems(item, filter);
|
|
9
|
+
}
|
|
10
|
+
else if (filter === 'all' || getFileType(item.url || item.name) === filter) {
|
|
11
|
+
count++;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return count;
|
|
16
|
+
}
|
|
17
|
+
export function getFolderIcon(folder, filter) {
|
|
18
|
+
const fileCount = folder.matchingFileCount || countFilteredItems(folder, filter);
|
|
19
|
+
if (fileCount === 0) {
|
|
20
|
+
return getAssetUrl('/icons/empty-folder.svg');
|
|
21
|
+
}
|
|
22
|
+
else if (fileCount > UNORGANIZED_THRESHOLD) {
|
|
23
|
+
return getAssetUrl('/icons/unorganized-folder.svg');
|
|
24
|
+
}
|
|
25
|
+
return getAssetUrl('/icons/folder.svg');
|
|
26
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Image Transformations helper.
|
|
3
|
+
* Wraps CDN image URLs with /cdn-cgi/image?... so the browser downloads a
|
|
4
|
+
* right-sized variant instead of the full-size original. Non-CDN URLs
|
|
5
|
+
* (localhost, blob:, external providers) pass through untouched.
|
|
6
|
+
*/
|
|
7
|
+
export type ImageTransformOptions = {
|
|
8
|
+
width: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
fit?: 'cover' | 'contain' | 'crop' | 'scale-down';
|
|
11
|
+
quality?: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Returns a Cloudflare-transformed URL for CDN-hosted images, or the original
|
|
15
|
+
* URL when transformation is disabled or the host is not allowlisted.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildTransformedUrl(url: string | null | undefined, options: ImageTransformOptions): string;
|
|
18
|
+
/**
|
|
19
|
+
* Builds a srcset across a fixed width ladder. Widths should come from a small
|
|
20
|
+
* allowlist — every unique width is billed as a separate transformation.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildImageSrcset(url: string | null | undefined, widths: number[], options?: Omit<ImageTransformOptions, 'width'>): string | undefined;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Image Transformations helper.
|
|
3
|
+
* Wraps CDN image URLs with /cdn-cgi/image?... so the browser downloads a
|
|
4
|
+
* right-sized variant instead of the full-size original. Non-CDN URLs
|
|
5
|
+
* (localhost, blob:, external providers) pass through untouched.
|
|
6
|
+
*/
|
|
7
|
+
/** Hosts allowed for transformation — keeps unique-transformation billing bounded. */
|
|
8
|
+
const TRANSFORM_HOSTS = (import.meta.env.PUBLIC_IMAGE_TRANSFORM_HOSTS ??
|
|
9
|
+
'static.widgetic.com,cdn.widgetic.com')
|
|
10
|
+
.split(',')
|
|
11
|
+
.map((host) => host.trim().toLowerCase())
|
|
12
|
+
.filter(Boolean);
|
|
13
|
+
const ENABLED = import.meta.env.PUBLIC_IMAGE_TRANSFORMS !== 'false';
|
|
14
|
+
function isTransformable(url) {
|
|
15
|
+
if (!ENABLED || !url)
|
|
16
|
+
return false;
|
|
17
|
+
if (url.startsWith('blob:') || url.startsWith('data:'))
|
|
18
|
+
return false;
|
|
19
|
+
try {
|
|
20
|
+
const parsed = new URL(url);
|
|
21
|
+
if (parsed.protocol !== 'https:')
|
|
22
|
+
return false;
|
|
23
|
+
return TRANSFORM_HOSTS.includes(parsed.hostname.toLowerCase());
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns a Cloudflare-transformed URL for CDN-hosted images, or the original
|
|
31
|
+
* URL when transformation is disabled or the host is not allowlisted.
|
|
32
|
+
*/
|
|
33
|
+
export function buildTransformedUrl(url, options) {
|
|
34
|
+
const source = url ?? '';
|
|
35
|
+
if (!isTransformable(source))
|
|
36
|
+
return source;
|
|
37
|
+
const params = new URLSearchParams();
|
|
38
|
+
params.set('width', String(options.width));
|
|
39
|
+
if (options.height)
|
|
40
|
+
params.set('height', String(options.height));
|
|
41
|
+
if (options.fit)
|
|
42
|
+
params.set('fit', options.fit);
|
|
43
|
+
params.set('q', String(options.quality ?? 75));
|
|
44
|
+
// format=auto lets Cloudflare negotiate AVIF/WebP from the Accept header.
|
|
45
|
+
params.set('format', 'auto');
|
|
46
|
+
const parsed = new URL(source);
|
|
47
|
+
return `${parsed.origin}/cdn-cgi/image?${params.toString()}/${encodeURIComponent(source)}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Builds a srcset across a fixed width ladder. Widths should come from a small
|
|
51
|
+
* allowlist — every unique width is billed as a separate transformation.
|
|
52
|
+
*/
|
|
53
|
+
export function buildImageSrcset(url, widths, options = {}) {
|
|
54
|
+
const source = url ?? '';
|
|
55
|
+
if (!isTransformable(source))
|
|
56
|
+
return undefined;
|
|
57
|
+
return widths
|
|
58
|
+
.map((width) => `${buildTransformedUrl(source, { ...options, width })} ${width}w`)
|
|
59
|
+
.join(', ');
|
|
60
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const absoluteUrlPattern = /^(?:[a-z+]+:)?\/\//i;
|
|
2
|
+
export function buildFileUrl(basePath, filePath) {
|
|
3
|
+
if (!filePath)
|
|
4
|
+
return filePath;
|
|
5
|
+
if (absoluteUrlPattern.test(filePath) || filePath.startsWith('data:') || filePath.startsWith('blob:')) {
|
|
6
|
+
return filePath;
|
|
7
|
+
}
|
|
8
|
+
if (!basePath)
|
|
9
|
+
return filePath.startsWith('/') ? filePath : `/${filePath}`;
|
|
10
|
+
const normalizedBase = basePath.endsWith('/') ? basePath : `${basePath}/`;
|
|
11
|
+
const normalizedPath = filePath.startsWith('/') ? filePath.slice(1) : filePath;
|
|
12
|
+
return `${normalizedBase}${normalizedPath}`;
|
|
13
|
+
}
|
|
14
|
+
export function resolveFileItemUrl(item, basePath) {
|
|
15
|
+
if (item.type !== 'file' || !item.url)
|
|
16
|
+
return item.name;
|
|
17
|
+
if (absoluteUrlPattern.test(item.url) || item.url.startsWith('blob:') || item.url.startsWith('data:')) {
|
|
18
|
+
return item.url;
|
|
19
|
+
}
|
|
20
|
+
return buildFileUrl(basePath, item.url) || item.url;
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { FileSystemItem, FileSystemRoot } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Load persisted uploads from L1 (falling back to the legacy localStorage blob).
|
|
4
|
+
*/
|
|
5
|
+
export declare function loadUserUploads(): Promise<FileSystemItem[]>;
|
|
6
|
+
/**
|
|
7
|
+
* Persist one upload into L1 (no entry cap; IndexedDB handles large sets).
|
|
8
|
+
* Fire-and-forget: callers do not await persistence.
|
|
9
|
+
*/
|
|
10
|
+
export declare function saveUserUpload(file: FileSystemItem): void;
|
|
11
|
+
/**
|
|
12
|
+
* Load the saved library tree children from L1 (legacy fallback).
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadLibraryTreeChildren(): Promise<FileSystemItem[] | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Persist the library tree children to L1 (fire-and-forget).
|
|
17
|
+
*/
|
|
18
|
+
export declare function saveLibraryTreeChildren(children: FileSystemItem[]): void;
|
|
19
|
+
/**
|
|
20
|
+
* Merge a persisted folder tree with latest upload files.
|
|
21
|
+
* Saved tree keeps user-created subfolders; upload files are upserted by id.
|
|
22
|
+
*/
|
|
23
|
+
export declare function mergeMyUploadsChildren(savedChildren: FileSystemItem[] | null, uploadFiles: FileSystemItem[]): FileSystemItem[];
|
|
24
|
+
/**
|
|
25
|
+
* Empty library root — only user uploads (CDN URLs), no broken demo assets.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createUserUploadsFileSystemRoot(files: FileSystemItem[]): Promise<FileSystemRoot>;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { CACHE_POLICIES, getCacheOwner, readEntity, writeEntity } from '@widgetic/cache-layer';
|
|
2
|
+
// Legacy localStorage keys, read once for migration then superseded by L1.
|
|
3
|
+
const LEGACY_STORAGE_KEY = 'widgetic-file-browser-uploads';
|
|
4
|
+
const LEGACY_LIBRARY_TREE_KEY = 'widgetic-file-browser-library-tree';
|
|
5
|
+
/** Entity kind for uploaded files in the L1 store. */
|
|
6
|
+
const UPLOADS_KIND = 'fileBrowserUploads';
|
|
7
|
+
/** Entity kind for the saved "My uploads" tree in the L1 store. */
|
|
8
|
+
const TREE_KIND = 'fileBrowserLibraryTree';
|
|
9
|
+
function entityKey() {
|
|
10
|
+
return 'current';
|
|
11
|
+
}
|
|
12
|
+
function ownerIdOrNull() {
|
|
13
|
+
return getCacheOwner();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Load persisted uploads from L1 (falling back to the legacy localStorage blob).
|
|
17
|
+
*/
|
|
18
|
+
export async function loadUserUploads() {
|
|
19
|
+
const ownerId = ownerIdOrNull();
|
|
20
|
+
if (ownerId) {
|
|
21
|
+
const persisted = await readEntity(ownerId, UPLOADS_KIND, entityKey(), CACHE_POLICIES['files.uploads'].staleTtlMs);
|
|
22
|
+
if (persisted && Array.isArray(persisted)) {
|
|
23
|
+
return persisted;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (typeof localStorage === 'undefined')
|
|
27
|
+
return [];
|
|
28
|
+
try {
|
|
29
|
+
const raw = localStorage.getItem(LEGACY_STORAGE_KEY);
|
|
30
|
+
if (!raw)
|
|
31
|
+
return [];
|
|
32
|
+
const parsed = JSON.parse(raw);
|
|
33
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Persist one upload into L1 (no entry cap; IndexedDB handles large sets).
|
|
41
|
+
* Fire-and-forget: callers do not await persistence.
|
|
42
|
+
*/
|
|
43
|
+
export function saveUserUpload(file) {
|
|
44
|
+
if (file.type !== 'file')
|
|
45
|
+
return;
|
|
46
|
+
const ownerId = ownerIdOrNull();
|
|
47
|
+
if (!ownerId)
|
|
48
|
+
return;
|
|
49
|
+
const entry = {
|
|
50
|
+
id: file.id,
|
|
51
|
+
name: file.name,
|
|
52
|
+
type: 'file',
|
|
53
|
+
url: file.url,
|
|
54
|
+
thumbnail: file.thumbnail,
|
|
55
|
+
size: file.size,
|
|
56
|
+
modified: file.modified || new Date().toISOString(),
|
|
57
|
+
hash: file.hash,
|
|
58
|
+
};
|
|
59
|
+
void (async () => {
|
|
60
|
+
try {
|
|
61
|
+
const existing = await loadAllPersistedUploads();
|
|
62
|
+
const merged = existing.filter((f) => f.id !== entry.id);
|
|
63
|
+
merged.unshift(entry);
|
|
64
|
+
await writeEntity(ownerId, UPLOADS_KIND, entityKey(), merged);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.error('[userUploadsStorage] Failed to persist upload:', error);
|
|
68
|
+
}
|
|
69
|
+
})();
|
|
70
|
+
}
|
|
71
|
+
/** Reads every persisted upload regardless of TTL (used for merge-on-save). */
|
|
72
|
+
async function loadAllPersistedUploads() {
|
|
73
|
+
const ownerId = ownerIdOrNull();
|
|
74
|
+
if (ownerId) {
|
|
75
|
+
const persisted = await readEntity(ownerId, UPLOADS_KIND, entityKey());
|
|
76
|
+
if (persisted && Array.isArray(persisted)) {
|
|
77
|
+
return persisted;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (typeof localStorage === 'undefined')
|
|
81
|
+
return [];
|
|
82
|
+
try {
|
|
83
|
+
const raw = localStorage.getItem(LEGACY_STORAGE_KEY);
|
|
84
|
+
if (!raw)
|
|
85
|
+
return [];
|
|
86
|
+
const parsed = JSON.parse(raw);
|
|
87
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Load the saved library tree children from L1 (legacy fallback).
|
|
95
|
+
*/
|
|
96
|
+
export async function loadLibraryTreeChildren() {
|
|
97
|
+
const ownerId = ownerIdOrNull();
|
|
98
|
+
if (ownerId) {
|
|
99
|
+
const persisted = await readEntity(ownerId, TREE_KIND, entityKey(), CACHE_POLICIES['files.libraryTree'].staleTtlMs);
|
|
100
|
+
if (persisted && Array.isArray(persisted)) {
|
|
101
|
+
return persisted;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (typeof localStorage === 'undefined')
|
|
105
|
+
return null;
|
|
106
|
+
try {
|
|
107
|
+
const raw = localStorage.getItem(LEGACY_LIBRARY_TREE_KEY);
|
|
108
|
+
if (!raw)
|
|
109
|
+
return null;
|
|
110
|
+
const parsed = JSON.parse(raw);
|
|
111
|
+
return Array.isArray(parsed) ? parsed : null;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Persist the library tree children to L1 (fire-and-forget).
|
|
119
|
+
*/
|
|
120
|
+
export function saveLibraryTreeChildren(children) {
|
|
121
|
+
const ownerId = ownerIdOrNull();
|
|
122
|
+
if (!ownerId)
|
|
123
|
+
return;
|
|
124
|
+
void writeEntity(ownerId, TREE_KIND, entityKey(), children).catch((error) => {
|
|
125
|
+
console.error('[userUploadsStorage] Failed to persist library tree:', error);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Merge a persisted folder tree with latest upload files.
|
|
130
|
+
* Saved tree keeps user-created subfolders; upload files are upserted by id.
|
|
131
|
+
*/
|
|
132
|
+
export function mergeMyUploadsChildren(savedChildren, uploadFiles) {
|
|
133
|
+
const byId = new Map();
|
|
134
|
+
if (savedChildren) {
|
|
135
|
+
for (const item of savedChildren) {
|
|
136
|
+
byId.set(item.id, item);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
for (const file of uploadFiles) {
|
|
140
|
+
if (file.type === 'file') {
|
|
141
|
+
byId.set(file.id, file);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return Array.from(byId.values());
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Empty library root — only user uploads (CDN URLs), no broken demo assets.
|
|
148
|
+
*/
|
|
149
|
+
export async function createUserUploadsFileSystemRoot(files) {
|
|
150
|
+
const savedChildren = await loadLibraryTreeChildren();
|
|
151
|
+
const children = mergeMyUploadsChildren(savedChildren, files);
|
|
152
|
+
return {
|
|
153
|
+
basePath: '',
|
|
154
|
+
root: {
|
|
155
|
+
id: 'root',
|
|
156
|
+
name: 'Root',
|
|
157
|
+
type: 'folder',
|
|
158
|
+
children: [
|
|
159
|
+
{
|
|
160
|
+
id: 'folder_my_uploads',
|
|
161
|
+
name: 'My uploads',
|
|
162
|
+
type: 'folder',
|
|
163
|
+
children,
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FileBrowserUploadConfig } from '../stores/uploadApiStore';
|
|
2
|
+
import type { WidgeticUploadResult } from './widgeticUpload';
|
|
3
|
+
/** Matches api-gateway MULTIPART_MAX_UPLOAD_BYTES — use TUS above this. */
|
|
4
|
+
export declare const WIDGETIC_MULTIPART_MAX_BYTES: number;
|
|
5
|
+
export type TusUploadProgress = {
|
|
6
|
+
bytesUploaded: number;
|
|
7
|
+
bytesTotal: number;
|
|
8
|
+
percentage: number;
|
|
9
|
+
};
|
|
10
|
+
export type TusUploadOptions = {
|
|
11
|
+
onProgress?: (progress: TusUploadProgress) => void;
|
|
12
|
+
abortSignal?: AbortSignal;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Resumable upload via TUS (POST/PATCH /v1/uploads/tus + POST .../complete).
|
|
16
|
+
*/
|
|
17
|
+
export declare function uploadToWidgeticApiTus(file: File, config: FileBrowserUploadConfig, options?: TusUploadOptions): Promise<WidgeticUploadResult>;
|
|
18
|
+
export declare function shouldUseTusUpload(file: File): boolean;
|