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