File tree Expand file tree Collapse file tree 6 files changed +21
-113
lines changed Expand file tree Collapse file tree 6 files changed +21
-113
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -18,11 +18,15 @@ const isZipCompressing = ref(false);
18
18
const anyUncompressed = computed (() => files .value .some ((file ) => ! file .isCompressed ));
19
19
20
20
async function editFileObj(fileObj : FileObj ) {
21
- const compressedFile = await useImageCompression (fileObj .file );
22
- const item = files .value .find ((item ) => item .id === fileObj .id );
23
- if (! item ) return ;
24
- item .file = compressedFile ;
25
- item .isCompressed = true ;
21
+ try {
22
+ const compressedFile = await useImageCompression (fileObj .file );
23
+ const item = files .value .find ((item ) => item .id === fileObj .id );
24
+ if (! item ) return ;
25
+ item .file = compressedFile ;
26
+ item .isCompressed = true ;
27
+ } catch {
28
+ fileObj .isTooLarge = true ;
29
+ }
26
30
}
27
31
28
32
async function compressFiles() {
Original file line number Diff line number Diff line change @@ -41,8 +41,12 @@ const computeFileSize = (size: number) =>
41
41
<div >
42
42
<div ><span class =" field-title" >Name:</span > {{ fileObj.file.name }}</div >
43
43
<div ><span class =" field-title" >Original Size:</span > {{ computeFileSize(orgSize) }}MB</div >
44
- <div v-if =" compSize" >
45
- <span class =" field-title" >Compressed Size:</span > {{ computeFileSize(compSize) }}MB
44
+ <div v-if =" compSize" ><span class =" field-title" >Compressed Size:</span > {{ computeFileSize(compSize) }}MB</div >
45
+ <div
46
+ v-if =" fileObj.isTooLarge"
47
+ class =" error"
48
+ >
49
+ <span class =" field-title" >Error:</span > File is too large!
46
50
</div >
47
51
</div >
48
52
<a
@@ -78,6 +82,10 @@ const computeFileSize = (size: number) =>
78
82
font-weight : bold ;
79
83
}
80
84
85
+ .error {
86
+ color : red ;
87
+ }
88
+
81
89
.delete-button {
82
90
width : auto ;
83
91
margin : 0 ;
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ function addFiles(uploadedFiles: FileList) {
29
29
const fileObj: FileObj = {
30
30
id: id ++ ,
31
31
isCompressed: false ,
32
+ isTooLarge: false ,
32
33
file ,
33
34
};
34
35
files .value .push (fileObj );
Original file line number Diff line number Diff line change 1
1
export interface FileObj {
2
2
id : number ;
3
3
isCompressed : boolean ;
4
+ isTooLarge : boolean ;
4
5
file : File ;
5
6
}
You can’t perform that action at this time.
0 commit comments