修改压缩解压文件命令

This commit is contained in:
whyour 2024-03-22 22:23:49 +08:00
parent 47c2c61f33
commit 3f54048127
5 changed files with 40 additions and 49 deletions

View File

@ -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 };
}

View File

@ -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",

View File

@ -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'}

View File

@ -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) {
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"

View File

@ -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<ReturnType<typeof Modal.info>>();
const ProgressElement = ({ percent }: { percent: number }) => (
const ProgressElement = ({ percent }: { percent: number }) => (
<Progress
style={{ display: 'flex', justifyContent: 'center' }}
type="circle"
percent={percent}
/>
);
);
export default function useProgress(title: string) {
const modalRef = useRef<ReturnType<typeof Modal.info> | 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: <ProgressElement percent={percent} />,
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: <ProgressElement percent={percent} />,
okButtonProps: { disabled: true },
});
}
};