Skip to content

Commit

Permalink
右键解压方法缺失
Browse files Browse the repository at this point in the history
  • Loading branch information
midoks committed Dec 21, 2024
1 parent dd685b6 commit 48468a1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
12 changes: 11 additions & 1 deletion web/admin/files/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,17 @@ def get_dir():
dir_list['page'] = mw.getPage({'p':page, 'row': row, 'tojs':'getFiles', 'count': dir_list['count']}, '1,2,3,4,5,6,7,8')
return dir_list

# 解压
# 解压ZIP
@blueprint.route('/unzip', endpoint='unzip', methods=['POST'])
@panel_login_required
def unzip():
sfile = request.form.get('sfile', '')
dfile = request.form.get('dfile', '')
stype = request.form.get('type', '')
path = request.form.get('path', '')
return file.unzip(sfile, dfile, stype, path)

# 解压可解压文件
@blueprint.route('/uncompress', endpoint='uncompress', methods=['POST'])
@panel_login_required
def uncompress():
Expand Down
23 changes: 23 additions & 0 deletions web/utils/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,29 @@ def mvFile(sfile, dfile):
except Exception as e:
return mw.returnData(False, '移动或重名命文件失败!'+str(e))

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 &")

if os.path.exists(dfile):
setFileAccept(dfile)
mw.writeLog("文件管理", '文件[{1}]解压[{2}]成功!', (sfile, dfile))
return mw.returnData(True, '文件解压成功!')
except:
return mw.returnData(False, '文件解压失败!')

def uncompress(sfile, dfile, path):
if not os.path.exists(sfile):
return mw.returnData(False, '指定文件不存在!')
Expand Down

0 comments on commit 48468a1

Please sign in to comment.