pull/632/head
Mr Chen 5 months ago
parent 66c8900a30
commit 6858a827f9
  1. 12
      web/admin/files/files.py
  2. 45
      web/utils/file.py

@ -69,7 +69,17 @@ def batch_paste():
stype = request.form.get('type', '') stype = request.form.get('type', '')
return file.batchPaste(path, stype) return file.batchPaste(path, stype)
# 获取文件内容 # 压缩文件
@blueprint.route('/zip', endpoint='zip', methods=['POST'])
@panel_login_required
def zip():
sfile = request.form.get('sfile', '')
dfile = request.form.get('dfile', '')
stype = request.form.get('type', '')
path = request.form.get('path', '')
return file.zip(sfile, dfile, stype, path)
# 复制文件内容
@blueprint.route('/copy_file', endpoint='copy_file', methods=['POST']) @blueprint.route('/copy_file', endpoint='copy_file', methods=['POST'])
@panel_login_required @panel_login_required
def copy_file(): def copy_file():

@ -249,6 +249,51 @@ def batchPaste(path, stype):
return mw.returnData(True, msg) return mw.returnData(True, msg)
def zip(sfile, dfile, stype, path):
if sfile.find(',') == -1:
if not os.path.exists(path + '/' + sfile):
return mw.returnData(False, '指定文件不存在!')
try:
tmps = mw.getPanelDir() + '/logs/panel_exec.log'
if stype == 'zip':
mw.execShell("cd '" + path + "' && zip '" + dfile +
"' -r '" + sfile + "' > " + tmps + " 2>&1")
else:
sfiles = ''
for sfile in sfile.split(','):
if not sfile:
continue
sfiles += " '" + sfile + "'"
mw.execShell("cd '" + path + "' && tar -zcvf '" + dfile + "' " + sfiles + " > " + tmps + " 2>&1")
setFileAccept(dfile)
mw.writeLog("文件管理", '文件[{1}]压缩[{2}]成功!', (sfile, dfile))
return mw.returnData(True, '文件压缩成功!')
except:
return mw.returnData(False, '文件压缩失败!')
def unzip(sfile, dfile, stype, path):
if not os.path.exists(sfile):
return mw.returnData(False, '指定文件不存在!')
try:
tmps = mw.getPanelDir() + '/logs/panel_exec.log'
if stype == 'zip':
mw.execShell("cd " + path + " && unzip -o -d '" + dfile + "' '" + sfile + "' > " + tmps + " 2>&1 &")
else:
sfiles = ''
for sfile in sfile.split(','):
if not sfile:
continue
sfiles += " '" + sfile + "'"
mw.execShell("cd " + path + " && tar -zxvf " + sfiles + " -C " + dfile + " > " + tmps + " 2>&1 &")
setFileAccept(dfile)
mw.writeLog("文件管理", '文件[{1}]解压[{2}]成功!', (sfile, dfile))
return mw.returnData(True, '文件解压成功!')
except:
return mw.returnData(False, '文件解压失败!')
def copyDir(src_file, dst_file): def copyDir(src_file, dst_file):
if not os.path.exists(src_file): if not os.path.exists(src_file):
return mw.returnData(False, '指定目录不存在!') return mw.returnData(False, '指定目录不存在!')

Loading…
Cancel
Save