mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
备份数据支持选择模块,支持清除依赖缓存
This commit is contained in:
+24
-1
@@ -316,10 +316,15 @@ export default (app: Router) => {
|
||||
|
||||
route.put(
|
||||
'/data/export',
|
||||
celebrate({
|
||||
body: Joi.object({
|
||||
type: Joi.array().items(Joi.string()).optional(),
|
||||
}),
|
||||
}),
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const systemService = Container.get(SystemService);
|
||||
await systemService.exportData(res);
|
||||
await systemService.exportData(res, req.body.type);
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
@@ -416,4 +421,22 @@ export default (app: Router) => {
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
route.put(
|
||||
'/config/dependence-clean',
|
||||
celebrate({
|
||||
body: Joi.object({
|
||||
type: Joi.string().allow(''),
|
||||
}),
|
||||
}),
|
||||
async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const systemService = Container.get(SystemService);
|
||||
const result = await systemService.cleanDependence(req.body.type);
|
||||
res.send(result);
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -86,6 +86,7 @@ const dbPath = path.join(dataPath, 'db/');
|
||||
const uploadPath = path.join(dataPath, 'upload/');
|
||||
const sshdPath = path.join(dataPath, 'ssh.d/');
|
||||
const systemLogPath = path.join(dataPath, 'syslog/');
|
||||
const dependenceCachePath = path.join(dataPath, 'dep_cache/');
|
||||
|
||||
const envFile = path.join(preloadPath, 'env.sh');
|
||||
const jsEnvFile = path.join(preloadPath, 'env.js');
|
||||
@@ -174,4 +175,5 @@ export default {
|
||||
sqliteFile,
|
||||
sshdPath,
|
||||
systemLogPath,
|
||||
dependenceCachePath,
|
||||
};
|
||||
|
||||
+20
-2
@@ -415,10 +415,17 @@ export default class SystemService {
|
||||
}
|
||||
}
|
||||
|
||||
public async exportData(res: Response) {
|
||||
public async exportData(res: Response, type?: string[]) {
|
||||
try {
|
||||
let dataDirs = ['db', 'upload'];
|
||||
if (type && type.length) {
|
||||
dataDirs = dataDirs.concat(type.filter((x) => x !== 'base'));
|
||||
}
|
||||
const dataPaths = dataDirs.map((dir) => `data/${dir}`);
|
||||
await promiseExec(
|
||||
`cd ${config.dataPath} && cd ../ && tar -zcvf ${config.dataTgzFile} data/`,
|
||||
`cd ${config.dataPath} && cd ../ && tar -zcvf ${
|
||||
config.dataTgzFile
|
||||
} ${dataPaths.join(' ')}`,
|
||||
);
|
||||
res.download(config.dataTgzFile);
|
||||
} catch (error: any) {
|
||||
@@ -503,4 +510,15 @@ export default class SystemService {
|
||||
return { code: 400, message: '设置时区失败' };
|
||||
}
|
||||
}
|
||||
|
||||
public async cleanDependence(type: 'node' | 'python3') {
|
||||
if (!type || !['node', 'python3'].includes(type)) {
|
||||
return { code: 400, message: '参数错误' };
|
||||
}
|
||||
try {
|
||||
const finalPath = path.join(config.dependenceCachePath, type);
|
||||
await fs.promises.rm(finalPath, { recursive: true });
|
||||
} catch (error) {}
|
||||
return { code: 200 };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user