@uploadista/vue 0.0.3
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/.turbo/turbo-check.log +240 -0
- package/LICENSE +21 -0
- package/README.md +554 -0
- package/package.json +36 -0
- package/src/components/FlowUploadList.vue +342 -0
- package/src/components/FlowUploadZone.vue +305 -0
- package/src/components/UploadList.vue +303 -0
- package/src/components/UploadZone.vue +254 -0
- package/src/components/index.ts +11 -0
- package/src/composables/index.ts +44 -0
- package/src/composables/plugin.ts +76 -0
- package/src/composables/useDragDrop.ts +343 -0
- package/src/composables/useFlowUpload.ts +431 -0
- package/src/composables/useMultiFlowUpload.ts +322 -0
- package/src/composables/useMultiUpload.ts +546 -0
- package/src/composables/useUpload.ts +300 -0
- package/src/composables/useUploadMetrics.ts +502 -0
- package/src/composables/useUploadistaClient.ts +73 -0
- package/src/index.ts +28 -0
- package/src/providers/UploadistaProvider.vue +69 -0
- package/src/providers/index.ts +1 -0
- package/src/utils/index.ts +156 -0
- package/src/utils/is-browser-file.ts +2 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for the Vue upload client
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Format file size in human-readable format
|
|
7
|
+
*/
|
|
8
|
+
export function formatFileSize(bytes: number): string {
|
|
9
|
+
if (bytes === 0) return "0 Bytes";
|
|
10
|
+
const k = 1024;
|
|
11
|
+
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
|
|
12
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
13
|
+
return `${Number.parseFloat((bytes / k ** i).toFixed(2))} ${sizes[i]}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Format upload speed in human-readable format
|
|
18
|
+
*/
|
|
19
|
+
export function formatSpeed(bytesPerSecond: number): string {
|
|
20
|
+
if (bytesPerSecond === 0) return "0 B/s";
|
|
21
|
+
const k = 1024;
|
|
22
|
+
const sizes = ["B/s", "KB/s", "MB/s", "GB/s"];
|
|
23
|
+
const i = Math.floor(Math.log(bytesPerSecond) / Math.log(k));
|
|
24
|
+
return `${Number.parseFloat((bytesPerSecond / k ** i).toFixed(1))} ${sizes[i]}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Format duration in human-readable format
|
|
29
|
+
*/
|
|
30
|
+
export function formatDuration(milliseconds: number): string {
|
|
31
|
+
if (milliseconds < 1000) {
|
|
32
|
+
return `${Math.round(milliseconds)}ms`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (milliseconds < 60000) {
|
|
36
|
+
return `${Math.round(milliseconds / 1000)}s`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (milliseconds < 3600000) {
|
|
40
|
+
const minutes = Math.floor(milliseconds / 60000);
|
|
41
|
+
const seconds = Math.round((milliseconds % 60000) / 1000);
|
|
42
|
+
return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const hours = Math.floor(milliseconds / 3600000);
|
|
46
|
+
const minutes = Math.round((milliseconds % 3600000) / 60000);
|
|
47
|
+
return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Validate file type against accepted types
|
|
52
|
+
*/
|
|
53
|
+
export function validateFileType(file: File, accept: string[]): boolean {
|
|
54
|
+
if (!accept || accept.length === 0) return true;
|
|
55
|
+
|
|
56
|
+
return accept.some((acceptType) => {
|
|
57
|
+
if (acceptType.startsWith(".")) {
|
|
58
|
+
// File extension check
|
|
59
|
+
return file.name.toLowerCase().endsWith(acceptType.toLowerCase());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// MIME type check (supports wildcards like image/*)
|
|
63
|
+
if (acceptType.endsWith("/*")) {
|
|
64
|
+
const baseType = acceptType.slice(0, -2);
|
|
65
|
+
return file.type.startsWith(baseType);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return file.type === acceptType;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Generate a unique ID for upload items
|
|
74
|
+
*/
|
|
75
|
+
export function generateUploadId(): string {
|
|
76
|
+
return `upload-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get file extension from filename
|
|
81
|
+
*/
|
|
82
|
+
export function getFileExtension(filename: string): string {
|
|
83
|
+
const lastDot = filename.lastIndexOf(".");
|
|
84
|
+
return lastDot !== -1 ? filename.substring(lastDot + 1).toLowerCase() : "";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Check if a file is an image
|
|
89
|
+
*/
|
|
90
|
+
export function isImageFile(file: File): boolean {
|
|
91
|
+
return file.type.startsWith("image/");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Check if a file is a video
|
|
96
|
+
*/
|
|
97
|
+
export function isVideoFile(file: File): boolean {
|
|
98
|
+
return file.type.startsWith("video/");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Check if a file is an audio file
|
|
103
|
+
*/
|
|
104
|
+
export function isAudioFile(file: File): boolean {
|
|
105
|
+
return file.type.startsWith("audio/");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Check if a file is a document
|
|
110
|
+
*/
|
|
111
|
+
export function isDocumentFile(file: File): boolean {
|
|
112
|
+
const documentTypes = [
|
|
113
|
+
"application/pdf",
|
|
114
|
+
"application/msword",
|
|
115
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
116
|
+
"application/vnd.ms-excel",
|
|
117
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
118
|
+
"application/vnd.ms-powerpoint",
|
|
119
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
120
|
+
"text/plain",
|
|
121
|
+
"text/csv",
|
|
122
|
+
"application/rtf",
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
return documentTypes.includes(file.type);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Create a preview URL for a file (if supported)
|
|
130
|
+
*/
|
|
131
|
+
export function createFilePreview(file: File): string | null {
|
|
132
|
+
if (isImageFile(file) || isVideoFile(file) || isAudioFile(file)) {
|
|
133
|
+
return URL.createObjectURL(file);
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Clean up a preview URL created with createFilePreview
|
|
140
|
+
*/
|
|
141
|
+
export function revokeFilePreview(previewUrl: string): void {
|
|
142
|
+
URL.revokeObjectURL(previewUrl);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Calculate progress percentage
|
|
147
|
+
*/
|
|
148
|
+
export function calculateProgress(current: number, total: number): number {
|
|
149
|
+
if (total === 0) return 0;
|
|
150
|
+
return Math.min(100, Math.max(0, Math.round((current / total) * 100)));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Check if a value is a browser file
|
|
155
|
+
*/
|
|
156
|
+
export * from "./is-browser-file";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@uploadista/typescript-config/base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": "./",
|
|
5
|
+
"paths": {
|
|
6
|
+
"@/*": ["./src/*"]
|
|
7
|
+
},
|
|
8
|
+
"typeRoots": ["../../node_modules/@types"],
|
|
9
|
+
"types": [],
|
|
10
|
+
"jsx": "preserve",
|
|
11
|
+
"jsxImportSource": "vue"
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*.ts", "src/**/*.vue"],
|
|
14
|
+
"exclude": ["node_modules", "dist"]
|
|
15
|
+
}
|