新增 压缩文件功能

This commit is contained in:
Suwings 2019-11-04 16:15:29 +08:00
parent e06b5045fe
commit ee1d6ed122
3 changed files with 36 additions and 1 deletions

View File

@ -115,7 +115,7 @@ router.post('/edit_read', (req, res) => {
//文件内容写入路由
router.post('/edit_write', (req, res) => {
const obj = (parseHandle(req.body))
if (!obj || !obj.filename || !obj.context) return
if (!obj || !obj.filename || !obj.context) return;
//没有经过安全的 UseFileOperate 进行安全操作
//必须经过目录越级漏洞防御
if (obj.filename.indexOf('../') != -1 || obj.filename.indexOf('./') != -1) return;
@ -140,6 +140,19 @@ router.post('/extract', (req, res) => {
});
//压缩文件路由
router.post('/compress', (req, res) => {
const directoryName = (parseHandle(req.body))
if (!directoryName) {
res.status(403).send("非法名称");
}
const fileOperate = new UseFileOperate(req.session.fsos).fileOperate;
const cwd = req.session.fsos.cwd;
fileOperate.extract(pathm.join(cwd, directoryName));
sendHandle(req, res, "OK");
});
const multiparty = require('multiparty');
router.post('/upload', (req, res) => {
//权限判断,需要登录

View File

@ -1,4 +1,5 @@
const AdmZip = require('adm-zip');
const zipper = require("zip-local");
const iconv = require('iconv-lite');
const fsex = require('fs-extra');
const os = require('os');
@ -48,5 +49,19 @@ if (realArgv.length >= 1) {
fsex.removeSync(realArgv[1])
}
//文件压缩子进程
if (ACTION === 'compress') {
zipper.zip(realArgv[1], function (error, zipped) {
if (!error) {
zipped.compress(); // compress before exporting
var buff = zipped.memory(); // get the zipped file as a Buffer
// or save the zipped file to disk
zipped.save('压缩文件_' + realArgv[1] + '.zip', function (error) {
if (!error) { }
});
}
});
}
process.exit(0);
}

View File

@ -155,6 +155,13 @@ class FileOperate extends BaseFileOperate {
});
}
compress(path) {
return this.pathAccessCheck(path, (absPath) => {
//分配子进程来进行解压操作
child_process.fork("./onlinefs/module/extend_worker.js", ['compress', absPath]);
});
}
writeFile(path, data) {
return this.pathAccessCheck(path, (absPath) => {
try {