From 3f540481276aaf518d590af043801b2199d2d817 Mon Sep 17 00:00:00 2001 From: whyour Date: Fri, 22 Mar 2024 22:23:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8E=8B=E7=BC=A9=E8=A7=A3?= =?UTF-8?q?=E5=8E=8B=E6=96=87=E4=BB=B6=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/system.ts | 17 +++++------------ package.json | 2 -- pnpm-lock.yaml | 18 ------------------ src/pages/setting/other.tsx | 18 ++++++++++++------ src/pages/setting/progress.tsx | 34 +++++++++++++++++++++++----------- 5 files changed, 40 insertions(+), 49 deletions(-) diff --git a/back/services/system.ts b/back/services/system.ts index 074052d7..c7eb5047 100644 --- a/back/services/system.ts +++ b/back/services/system.ts @@ -4,7 +4,6 @@ import fs from 'fs'; import got from 'got'; import sum from 'lodash/sum'; import path from 'path'; -import tar from 'tar'; import { Inject, Service } from 'typedi'; import winston from 'winston'; import config from '../config'; @@ -389,15 +388,7 @@ export default class SystemService { public async exportData(res: Response) { try { - tar.create( - { - gzip: true, - file: config.dataTgzFile, - cwd: config.rootPath, - sync: true, - }, - ['data'], - ); + await promiseExec(`cd ${config.rootPath} && tar -zcvf ${config.dataTgzFile} data/`); res.download(config.dataTgzFile); } catch (error: any) { return res.send({ code: 400, message: error.message }); @@ -407,8 +398,10 @@ export default class SystemService { public async importData() { try { await promiseExec(`rm -rf ${path.join(config.tmpPath, 'data')}`); - tar.x({ file: config.dataTgzFile, cwd: config.tmpPath, sync: true }); - return { code: 200 }; + const res = await promiseExec( + `cd ${config.tmpPath} && tar -zxvf data.tgz`, + ); + return { code: 200, data: res }; } catch (error: any) { return { code: 400, message: error.message }; } diff --git a/package.json b/package.json index dcbc4453..78d91b4d 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,6 @@ "serve-handler": "^6.1.3", "sockjs": "^0.3.24", "sqlite3": "git+https://github.com/whyour/node-sqlite3.git#v1.0.3", - "tar": "^6.1.15", "toad-scheduler": "^1.6.0", "typedi": "^0.10.0", "uuid": "^8.3.2", @@ -130,7 +129,6 @@ "@types/serve-handler": "^6.1.1", "@types/sockjs": "^0.3.33", "@types/sockjs-client": "^1.5.1", - "@types/tar": "^6.1.5", "@types/uuid": "^8.3.4", "@types/request-ip": "0.0.41", "@uiw/codemirror-extensions-langs": "^4.21.9", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 84546156..0555c5ab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -112,9 +112,6 @@ dependencies: sqlite3: specifier: git+https://github.com/whyour/node-sqlite3.git#v1.0.3 version: github.com/whyour/node-sqlite3/3a00af0b5d7603b7f1b290032507320b18a6b741 - tar: - specifier: ^6.1.15 - version: 6.1.15 toad-scheduler: specifier: ^1.6.0 version: 1.6.1 @@ -219,9 +216,6 @@ devDependencies: '@types/sockjs-client': specifier: ^1.5.1 version: 1.5.1 - '@types/tar': - specifier: ^6.1.5 - version: 6.1.5 '@types/uuid': specifier: ^8.3.4 version: 8.3.4 @@ -5128,13 +5122,6 @@ packages: '@types/node': 17.0.45 dev: true - /@types/tar@6.1.5: - resolution: {integrity: sha512-qm2I/RlZij5RofuY7vohTpYNaYcrSQlN2MyjucQc7ZweDwaEWkdN/EeNh6e9zjK6uEm6PwjdMXkcj05BxZdX1Q==} - dependencies: - '@types/node': 17.0.45 - minipass: 4.2.8 - dev: true - /@types/triple-beam@1.3.2: resolution: {integrity: sha512-txGIh+0eDFzKGC25zORnswy+br1Ha7hj5cMVwKIU7+s0U2AxxJru/jZSMU6OC9MJWP6+pc/hc6ZjyZShpsyY2g==} dev: false @@ -11090,11 +11077,6 @@ packages: yallist: 4.0.0 dev: false - /minipass@4.2.8: - resolution: {integrity: sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ==} - engines: {node: '>=8'} - dev: true - /minipass@5.0.0: resolution: {integrity: sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==} engines: {node: '>=8'} diff --git a/src/pages/setting/other.tsx b/src/pages/setting/other.tsx index 5665ad89..84583a98 100644 --- a/src/pages/setting/other.tsx +++ b/src/pages/setting/other.tsx @@ -273,12 +273,18 @@ const Other = ({ showUploadList={false} maxCount={1} action={`${config.apiPrefix}system/data/import`} - onChange={(e) => { - if (e.event?.percent) { - showUploadProgress(parseFloat(e.event?.percent.toFixed(1))); - if (e.event?.percent === 100) { - showReloadModal(); - } + onChange={({ file, event }) => { + if (event?.percent) { + showUploadProgress( + Math.min(parseFloat(event?.percent.toFixed(1)), 99), + ); + } + if (file.status === 'done') { + showUploadProgress(100); + showReloadModal(); + } + if (file.status === 'error') { + message.error('上传失败'); } }} name="data" diff --git a/src/pages/setting/progress.tsx b/src/pages/setting/progress.tsx index 21d8788d..d95d4fde 100644 --- a/src/pages/setting/progress.tsx +++ b/src/pages/setting/progress.tsx @@ -2,30 +2,42 @@ import intl from 'react-intl-universal'; import { Modal, Progress } from 'antd'; import { useRef } from 'react'; -export default function useProgress(title: string) { - const modalRef = useRef>(); +const ProgressElement = ({ percent }: { percent: number }) => ( + +); - const ProgressElement = ({ percent }: { percent: number }) => ( - - ); +export default function useProgress(title: string) { + const modalRef = useRef | null>(); const showProgress = (percent: number) => { if (modalRef.current) { modalRef.current.update({ - title: `${title}${percent >= 100 ? intl.get('成功') : intl.get('中...')}`, + title: `${title}${ + percent >= 100 ? intl.get('成功') : intl.get('中...') + }`, content: , + okButtonProps: { disabled: percent !== 100 }, }); + if (percent === 100) { + setTimeout(() => { + modalRef.current?.destroy(); + modalRef.current = null; + }); + } } else { modalRef.current = Modal.info({ width: 600, maskClosable: false, - title: `${title}${percent >= 100 ? intl.get('成功') : intl.get('中...')}`, + title: `${title}${ + percent >= 100 ? intl.get('成功') : intl.get('中...') + }`, centered: true, content: , + okButtonProps: { disabled: true }, }); } };