Skip to content

Commit

Permalink
fix: don't display error when screenshot fails
Browse files Browse the repository at this point in the history
  • Loading branch information
XZB-1248 committed Jun 2, 2022
1 parent b9a5511 commit a1d0bc8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v0.1.0

* fix: don't refresh after file upload
* fix: don't display error when screenshot fails

* 修复:文件上传成功后文件管理器不会自动刷新
* 修复:截图失败时不会显示错误提示



## v0.0.9

* Optimize: performance of front-end and back-end.
Expand Down
16 changes: 10 additions & 6 deletions web/src/components/explorer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, {useEffect, useMemo, useRef, useState} from 'react';
import {Breadcrumb, Card, Image, message, Modal, Popconfirm, Progress} from "antd";
import {Breadcrumb, Image, message, Modal, Popconfirm, Progress} from "antd";
import ProTable from '@ant-design/pro-table';
import {formatSize, post, request, translate, waitTime} from "../utils/utils";
import dayjs from "dayjs";
import i18n from "../locale/locale";
import './explorer.css';
import { VList } from "virtuallist-antd";
import {VList} from "virtuallist-antd";
import {HomeOutlined, ReloadOutlined, UploadOutlined} from "@ant-design/icons";
import axios from "axios";
import Qs from "qs";
Expand Down Expand Up @@ -141,8 +141,7 @@ function FileBrowser(props) {
let data = {};
try {
data = JSON.parse(str);
} catch (e) {
}
} catch (e) { }
message.warn(data.msg ? translate(data.msg) : i18n.t('requestFailed'));
});
} else {
Expand Down Expand Up @@ -421,10 +420,10 @@ function UploadModal(props) {
// 0: ready, 1: uploading, 2: success, 3: fail, 4: cancel

useEffect(() => {
setStatus(0);
if (props.file) {
setVisible(true);
setPercent(0);
setStatus(0);
}
}, [props.file]);

Expand All @@ -444,6 +443,7 @@ function UploadModal(props) {
path: props.path,
file: props.file.name
});
let uploadStatus = 1;
setStatus(1);
window.onbeforeunload = onPageUnload;
abortController = new AbortController();
Expand All @@ -464,16 +464,20 @@ function UploadModal(props) {
).then(res => {
let data = res.data;
if (data.code === 0) {
uploadStatus = 2;
setStatus(2);
message.success(i18n.t('uploadSuccess'));
} else {
uploadStatus = 3;
setStatus(3);
}
}).catch((err) => {
if (axios.isCancel(err)) {
uploadStatus = 4;
setStatus(4);
message.error(i18n.t('uploadAborted'));
} else {
uploadStatus = 3;
setStatus(3);
message.error(i18n.t('uploadFailed') + i18n.t('colon') + err.message);
}
Expand All @@ -482,7 +486,7 @@ function UploadModal(props) {
window.onbeforeunload = null;
setTimeout(() => {
setVisible(false);
if (status === 2) {
if (uploadStatus === 2) {
props.onSuccess();
} else {
props.onCanel();
Expand Down
4 changes: 2 additions & 2 deletions web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ axios.interceptors.response.use(async (res) => {
}
return Promise.resolve(res);
}, (err) => {
console.error(err);
// console.error(err);
if (err.code === 'ECONNABORTED') {
message.error(i18n.t('requestTimeout'));
return Promise.reject(err);
}
let res = err.response;
let data = res?.data ?? {};
if (data.hasOwnProperty('code')) {
if (data.hasOwnProperty('code') && data.hasOwnProperty('msg')) {
if (data.code !== 0){
message.warn(translate(data.msg));
return Promise.resolve(res);
Expand Down
22 changes: 13 additions & 9 deletions web/src/pages/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,20 +298,24 @@ function overview(props) {
request('/api/device/screenshot/get', {device: device.id}, {}, {
responseType: 'blob'
}).then((res) => {
if ((res.data.type ?? '').substring(0, 16) === 'application/json') {
res.data.text().then((str) => {
console.log(res.data.type);
if ((res.data.type ?? '').substring(0, 5) === 'image') {
if (screenBlob.length > 0) {
URL.revokeObjectURL(screenBlob);
}
setScreenBlob(URL.createObjectURL(res.data));
}
}).catch((e) => {
let res = e.response;
if ((res?.data?.type ?? '').substring(0, 16) === 'application/json') {
let data = res?.data ?? {};
data.text().then((str) => {
let data = {};
try {
data = JSON.parse(str);
} catch (e) {
}
} catch (e) { }
message.warn(data.msg ? translate(data.msg) : i18n.t('requestFailed'));
});
} else {
if (screenBlob.length > 0) {
URL.revokeObjectURL(screenBlob);
}
setScreenBlob(URL.createObjectURL(res.data));
}
});
return;
Expand Down

0 comments on commit a1d0bc8

Please sign in to comment.