Skip to content

Commit 905970a

Browse files
authored
Update worker.js
1 parent 37bbd05 commit 905970a

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

worker.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,31 @@ $(document).ready(function() {
146146
const selectedInterface = $('#interfaceSelector').val();
147147
const file = $('#fileInput')[0].files[0];
148148
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);
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;
155153
}
156-
return;
157-
}
158154
159-
if (file && (file.type === 'image/gif' || file.type.includes('image/'))) {
160-
await uploadFile(file);
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+
}
161172
}
162-
}
173+
}
163174
164175
// 处理上传文件函数
165176
async function uploadFile(file) {

0 commit comments

Comments
 (0)