mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 14:56:07 +08:00
修改压缩解压文件命令
This commit is contained in:
parent
47c2c61f33
commit
3f54048127
|
@ -4,7 +4,6 @@ import fs from 'fs';
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
import sum from 'lodash/sum';
|
import sum from 'lodash/sum';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import tar from 'tar';
|
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import winston from 'winston';
|
import winston from 'winston';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
|
@ -389,15 +388,7 @@ export default class SystemService {
|
||||||
|
|
||||||
public async exportData(res: Response) {
|
public async exportData(res: Response) {
|
||||||
try {
|
try {
|
||||||
tar.create(
|
await promiseExec(`cd ${config.rootPath} && tar -zcvf ${config.dataTgzFile} data/`);
|
||||||
{
|
|
||||||
gzip: true,
|
|
||||||
file: config.dataTgzFile,
|
|
||||||
cwd: config.rootPath,
|
|
||||||
sync: true,
|
|
||||||
},
|
|
||||||
['data'],
|
|
||||||
);
|
|
||||||
res.download(config.dataTgzFile);
|
res.download(config.dataTgzFile);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return res.send({ code: 400, message: error.message });
|
return res.send({ code: 400, message: error.message });
|
||||||
|
@ -407,8 +398,10 @@ export default class SystemService {
|
||||||
public async importData() {
|
public async importData() {
|
||||||
try {
|
try {
|
||||||
await promiseExec(`rm -rf ${path.join(config.tmpPath, 'data')}`);
|
await promiseExec(`rm -rf ${path.join(config.tmpPath, 'data')}`);
|
||||||
tar.x({ file: config.dataTgzFile, cwd: config.tmpPath, sync: true });
|
const res = await promiseExec(
|
||||||
return { code: 200 };
|
`cd ${config.tmpPath} && tar -zxvf data.tgz`,
|
||||||
|
);
|
||||||
|
return { code: 200, data: res };
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return { code: 400, message: error.message };
|
return { code: 400, message: error.message };
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,6 @@
|
||||||
"serve-handler": "^6.1.3",
|
"serve-handler": "^6.1.3",
|
||||||
"sockjs": "^0.3.24",
|
"sockjs": "^0.3.24",
|
||||||
"sqlite3": "git+https://github.com/whyour/node-sqlite3.git#v1.0.3",
|
"sqlite3": "git+https://github.com/whyour/node-sqlite3.git#v1.0.3",
|
||||||
"tar": "^6.1.15",
|
|
||||||
"toad-scheduler": "^1.6.0",
|
"toad-scheduler": "^1.6.0",
|
||||||
"typedi": "^0.10.0",
|
"typedi": "^0.10.0",
|
||||||
"uuid": "^8.3.2",
|
"uuid": "^8.3.2",
|
||||||
|
@ -130,7 +129,6 @@
|
||||||
"@types/serve-handler": "^6.1.1",
|
"@types/serve-handler": "^6.1.1",
|
||||||
"@types/sockjs": "^0.3.33",
|
"@types/sockjs": "^0.3.33",
|
||||||
"@types/sockjs-client": "^1.5.1",
|
"@types/sockjs-client": "^1.5.1",
|
||||||
"@types/tar": "^6.1.5",
|
|
||||||
"@types/uuid": "^8.3.4",
|
"@types/uuid": "^8.3.4",
|
||||||
"@types/request-ip": "0.0.41",
|
"@types/request-ip": "0.0.41",
|
||||||
"@uiw/codemirror-extensions-langs": "^4.21.9",
|
"@uiw/codemirror-extensions-langs": "^4.21.9",
|
||||||
|
|
|
@ -112,9 +112,6 @@ dependencies:
|
||||||
sqlite3:
|
sqlite3:
|
||||||
specifier: git+https://github.com/whyour/node-sqlite3.git#v1.0.3
|
specifier: git+https://github.com/whyour/node-sqlite3.git#v1.0.3
|
||||||
version: github.com/whyour/node-sqlite3/3a00af0b5d7603b7f1b290032507320b18a6b741
|
version: github.com/whyour/node-sqlite3/3a00af0b5d7603b7f1b290032507320b18a6b741
|
||||||
tar:
|
|
||||||
specifier: ^6.1.15
|
|
||||||
version: 6.1.15
|
|
||||||
toad-scheduler:
|
toad-scheduler:
|
||||||
specifier: ^1.6.0
|
specifier: ^1.6.0
|
||||||
version: 1.6.1
|
version: 1.6.1
|
||||||
|
@ -219,9 +216,6 @@ devDependencies:
|
||||||
'@types/sockjs-client':
|
'@types/sockjs-client':
|
||||||
specifier: ^1.5.1
|
specifier: ^1.5.1
|
||||||
version: 1.5.1
|
version: 1.5.1
|
||||||
'@types/tar':
|
|
||||||
specifier: ^6.1.5
|
|
||||||
version: 6.1.5
|
|
||||||
'@types/uuid':
|
'@types/uuid':
|
||||||
specifier: ^8.3.4
|
specifier: ^8.3.4
|
||||||
version: 8.3.4
|
version: 8.3.4
|
||||||
|
@ -5128,13 +5122,6 @@ packages:
|
||||||
'@types/node': 17.0.45
|
'@types/node': 17.0.45
|
||||||
dev: true
|
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:
|
/@types/triple-beam@1.3.2:
|
||||||
resolution: {integrity: sha512-txGIh+0eDFzKGC25zORnswy+br1Ha7hj5cMVwKIU7+s0U2AxxJru/jZSMU6OC9MJWP6+pc/hc6ZjyZShpsyY2g==}
|
resolution: {integrity: sha512-txGIh+0eDFzKGC25zORnswy+br1Ha7hj5cMVwKIU7+s0U2AxxJru/jZSMU6OC9MJWP6+pc/hc6ZjyZShpsyY2g==}
|
||||||
dev: false
|
dev: false
|
||||||
|
@ -11090,11 +11077,6 @@ packages:
|
||||||
yallist: 4.0.0
|
yallist: 4.0.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/minipass@4.2.8:
|
|
||||||
resolution: {integrity: sha512-fNzuVyifolSLFL4NzpF+wEF4qrgqaaKX0haXPQEdQ7NKAN+WecoKMHV09YcuL/DHxrUsYQOK3MiuDf7Ip2OXfQ==}
|
|
||||||
engines: {node: '>=8'}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/minipass@5.0.0:
|
/minipass@5.0.0:
|
||||||
resolution: {integrity: sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==}
|
resolution: {integrity: sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
|
|
|
@ -273,12 +273,18 @@ const Other = ({
|
||||||
showUploadList={false}
|
showUploadList={false}
|
||||||
maxCount={1}
|
maxCount={1}
|
||||||
action={`${config.apiPrefix}system/data/import`}
|
action={`${config.apiPrefix}system/data/import`}
|
||||||
onChange={(e) => {
|
onChange={({ file, event }) => {
|
||||||
if (e.event?.percent) {
|
if (event?.percent) {
|
||||||
showUploadProgress(parseFloat(e.event?.percent.toFixed(1)));
|
showUploadProgress(
|
||||||
if (e.event?.percent === 100) {
|
Math.min(parseFloat(event?.percent.toFixed(1)), 99),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (file.status === 'done') {
|
||||||
|
showUploadProgress(100);
|
||||||
showReloadModal();
|
showReloadModal();
|
||||||
}
|
}
|
||||||
|
if (file.status === 'error') {
|
||||||
|
message.error('上传失败');
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
name="data"
|
name="data"
|
||||||
|
|
|
@ -2,9 +2,6 @@ import intl from 'react-intl-universal';
|
||||||
import { Modal, Progress } from 'antd';
|
import { Modal, Progress } from 'antd';
|
||||||
import { useRef } from 'react';
|
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
|
<Progress
|
||||||
style={{ display: 'flex', justifyContent: 'center' }}
|
style={{ display: 'flex', justifyContent: 'center' }}
|
||||||
|
@ -13,19 +10,34 @@ export default function useProgress(title: string) {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export default function useProgress(title: string) {
|
||||||
|
const modalRef = useRef<ReturnType<typeof Modal.info> | null>();
|
||||||
|
|
||||||
const showProgress = (percent: number) => {
|
const showProgress = (percent: number) => {
|
||||||
if (modalRef.current) {
|
if (modalRef.current) {
|
||||||
modalRef.current.update({
|
modalRef.current.update({
|
||||||
title: `${title}${percent >= 100 ? intl.get('成功') : intl.get('中...')}`,
|
title: `${title}${
|
||||||
|
percent >= 100 ? intl.get('成功') : intl.get('中...')
|
||||||
|
}`,
|
||||||
content: <ProgressElement percent={percent} />,
|
content: <ProgressElement percent={percent} />,
|
||||||
|
okButtonProps: { disabled: percent !== 100 },
|
||||||
});
|
});
|
||||||
|
if (percent === 100) {
|
||||||
|
setTimeout(() => {
|
||||||
|
modalRef.current?.destroy();
|
||||||
|
modalRef.current = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
modalRef.current = Modal.info({
|
modalRef.current = Modal.info({
|
||||||
width: 600,
|
width: 600,
|
||||||
maskClosable: false,
|
maskClosable: false,
|
||||||
title: `${title}${percent >= 100 ? intl.get('成功') : intl.get('中...')}`,
|
title: `${title}${
|
||||||
|
percent >= 100 ? intl.get('成功') : intl.get('中...')
|
||||||
|
}`,
|
||||||
centered: true,
|
centered: true,
|
||||||
content: <ProgressElement percent={percent} />,
|
content: <ProgressElement percent={percent} />,
|
||||||
|
okButtonProps: { disabled: true },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user