Commit 80fcac3 1 parent 905970a commit 80fcac3 Copy full SHA for 80fcac3
File tree 1 file changed +11
-22
lines changed
1 file changed +11
-22
lines changed Original file line number Diff line number Diff line change @@ -146,31 +146,20 @@ $(document).ready(function() {
146
146
const selectedInterface = $('#interfaceSelector').val();
147
147
const file = $('#fileInput')[0].files[0];
148
148
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);
153
155
}
156
+ return;
157
+ }
154
158
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);
172
161
}
173
- }
162
+ }
174
163
175
164
// 处理上传文件函数
176
165
async function uploadFile(file) {
You can’t perform that action at this time.
0 commit comments