Skip to content

Commit 80fcac3

Browse files
authored
Update worker.js
1 parent 905970a commit 80fcac3

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

worker.js

+11-22
Original file line numberDiff line numberDiff line change
@@ -146,31 +146,20 @@ $(document).ready(function() {
146146
const selectedInterface = $('#interfaceSelector').val();
147147
const file = $('#fileInput')[0].files[0];
148148
149-
if (file) {
150-
if (file.size > 5 * 1024 * 1024 || (file.type === 'image/gif' && file.size > 5 * 1024 * 1024)) {
151-
toastr.error('文件大小不能超过5MB!');
152-
return;
149+
if (file && file.size > 5 * 1024 * 1024) {
150+
if (file.type === 'image/gif') {
151+
toastr.error('GIF 文件必须≤5MB');
152+
} else {
153+
const compressedFile = await compressImage(file);
154+
await uploadFile(compressedFile);
153155
}
156+
return;
157+
}
154158
155-
if (file.type.includes('image/')) {
156-
const image = new Image();
157-
image.src = URL.createObjectURL(file);
158-
159-
image.onload = async function() {
160-
const width = this.width;
161-
const height = this.height;
162-
const resolution = width * height;
163-
164-
if (resolution > 20000000) {
165-
const compressedFile = await compressImage(file);
166-
uploadFile(compressedFile);
167-
} else {
168-
uploadFile(file);
169-
}
170-
};
171-
}
159+
if (file && (file.type === 'image/gif' || file.type.includes('image/'))) {
160+
await uploadFile(file);
172161
}
173-
}
162+
}
174163
175164
// 处理上传文件函数
176165
async function uploadFile(file) {

0 commit comments

Comments
 (0)