Skip to content

Commit

Permalink
Update worker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
0-RTT authored May 27, 2024
1 parent 905970a commit 80fcac3
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,31 +146,20 @@ $(document).ready(function() {
const selectedInterface = $('#interfaceSelector').val();
const file = $('#fileInput')[0].files[0];
if (file) {
if (file.size > 5 * 1024 * 1024 || (file.type === 'image/gif' && file.size > 5 * 1024 * 1024)) {
toastr.error('文件大小不能超过5MB!');
return;
if (file && file.size > 5 * 1024 * 1024) {
if (file.type === 'image/gif') {
toastr.error('GIF 文件必须≤5MB');
} else {
const compressedFile = await compressImage(file);
await uploadFile(compressedFile);
}
return;
}
if (file.type.includes('image/')) {
const image = new Image();
image.src = URL.createObjectURL(file);
image.onload = async function() {
const width = this.width;
const height = this.height;
const resolution = width * height;
if (resolution > 20000000) {
const compressedFile = await compressImage(file);
uploadFile(compressedFile);
} else {
uploadFile(file);
}
};
}
if (file && (file.type === 'image/gif' || file.type.includes('image/'))) {
await uploadFile(file);
}
}
}
// 处理上传文件函数
async function uploadFile(file) {
Expand Down

0 comments on commit 80fcac3

Please sign in to comment.