From abc6e8f5970725973cd4f06b943e0b2df92d8f78 Mon Sep 17 00:00:00 2001 From: midoks Date: Fri, 15 Sep 2023 00:01:37 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=94=AF=E6=8C=81rar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/config_api.py | 2 +- class/core/files_api.py | 42 ++++++++- route/static/app/files.js | 179 ++++++++++++++++++++++++++----------- route/static/app/public.js | 21 +++-- 4 files changed, 182 insertions(+), 62 deletions(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index 53f0e2b2d..c2eab6678 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -27,7 +27,7 @@ from flask import request class config_api: - __version = '0.16.1' + __version = '0.16.1.1' __api_addr = 'data/api.json' def __init__(self): diff --git a/class/core/files_api.py b/class/core/files_api.py index 332fb9574..08987ef3e 100755 --- a/class/core/files_api.py +++ b/class/core/files_api.py @@ -87,6 +87,12 @@ class files_api: path = request.form.get('path', '') return self.unzip(sfile, dfile, stype, path) + def uncompressApi(self): + sfile = request.form.get('sfile', '') + dfile = request.form.get('dfile', '') + path = request.form.get('path', '') + return self.uncompress(sfile, dfile, path) + # 移动文件或目录 def mvFileApi(self): sfile = request.form.get('sfile', '') @@ -830,10 +836,42 @@ class files_api: except: return mw.returnJson(False, '文件压缩失败!') - def unzip(self, sfile, dfile, stype, path): + def uncompress(self, sfile, dfile, path): + if not os.path.exists(sfile): + return mw.returnJson(False, '指定文件不存在!') + + filename = os.path.basename(sfile) + extension = os.path.splitext(filename)[-1] + extension = extension.strip('.') + + if not extension in ['gz', 'zip', 'rar']: + return mw.returnJson(False, '现在仅支持gz,zip,rar文件解压!') + try: + tmps = mw.getRunDir() + '/tmp/panelExec.log' + if extension == 'zip': + cmd = "cd " + path + " && unzip -o -d '" + dfile + \ + "' '" + sfile + "' > " + tmps + " 2>&1 &" + mw.execShell(cmd) + if extension == 'gz': + cmd = "cd " + path + " && tar -zxvf " + sfile + \ + " -C " + dfile + " > " + tmps + " 2>&1 &" + mw.execShell(cmd) + if extension == 'rar': + cmd = "cd " + path + " && unrar x t.rar " + \ + sfile + " " + dfile + " > " + tmps + " 2>&1 &" + mw.execShell(cmd) + + if os.path.exists(dfile): + self.setFileAccept(dfile) + mw.writeLog("文件管理", '文件解压成功!', (sfile, dfile)) + return mw.returnJson(True, '文件解压成功!') + except Exception as e: + return mw.returnJson(False, '文件解压失败!:' + str(e)) + + def unzip(self, sfile, dfile, stype, path): if not os.path.exists(sfile): - return mw.returnMsg(False, '指定文件不存在!') + return mw.returnJson(False, '指定文件不存在!') try: tmps = mw.getRunDir() + '/tmp/panelExec.log' diff --git a/route/static/app/files.js b/route/static/app/files.js index 9bee48b4b..415502ac8 100755 --- a/route/static/app/files.js +++ b/route/static/app/files.js @@ -351,7 +351,6 @@ function getFiles(Path) { } var body = ''; var data = 'path=' + Path; - var loadT = layer.load(); var totalSize = 0; var search_all = ''; @@ -359,7 +358,8 @@ function getFiles(Path) { if(all){ search_all = "&all=yes"; } - + + var loadT = layer.load(); $.post('/files/get_dir?p=' + p + '&showRow=' + showRow + search + search_all, data, function(rdata) { layer.close(loadT); @@ -400,13 +400,14 @@ function getFiles(Path) { "+fmp[3]+"\ "+fmp[4]+"\ \ - 复制 | \ - 剪切 | \ - 重命名 | \ - 权限 | \ - 压缩 | \ - 删除\ - "; + 复制 | \ + 剪切 | \ + 重命名 | \ + 权限 | \ + 压缩 | \ + 删除\ + \ + "; } else { $("#set_icon").addClass("active"); $("#set_list").removeClass("active"); @@ -414,28 +415,33 @@ function getFiles(Path) { + toSize(fmp[1])+" "+lan.files.file_etime+":"+getLocalTime(fmp[2])+" "+lan.files.file_auth+":"+fmp[3]+" "+lan.files.file_own+":"+fmp[4]+"'>\ \
\ -
" + fmp[0] + "
\ - "; +
\ + " + fmp[0] + "\ +
\ + "; } } for (var i = 0; i < rdata.FILES.length; i++) { if(rdata.FILES[i] == null) continue; var fmp = rdata.FILES[i].split(";"); - var displayZip = isZip(fmp[0]); var bodyZip = ''; var download = ''; var cnametext =fmp[0] + fmp[5]; fmp[0] = fmp[0].replace(/'/,"\\'"); - if(cnametext.length>48){ - cnametext = cnametext.substring(0,48) + '...'; - } + if(isChineseChar(cnametext)){ if(cnametext.length>16){ cnametext = cnametext.substring(0,16) + '...'; } + } else{ + if( cnametext.length > 48 ){ + cnametext = cnametext.substring(0,48) + '...'; + } } - if(displayZip != -1){ - bodyZip = "解压 | "; + + var displayCompress = 1; + if(isCompressFile(fmp[0])){ + bodyZip = "解压 | "; } if(isText(fmp[0])){ @@ -462,17 +468,21 @@ function getFiles(Path) { 剪切 | \ 重命名 | \ 权限 | \ - 压缩 | "+bodyZip+download+"\ - 删除\ + 压缩 | " + + bodyZip + + download + + "删除\ \ "; } else{ body += ""; } } @@ -481,19 +491,19 @@ function getFiles(Path) { $("#dir_info").html(dirInfo); if( getCookie('rank') == 'a' ){ var tablehtml = '\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - '+body+'\ -
文件名大小修改时间权限所有者操作
'; + \ + \ + \ + 文件名\ + 大小\ + 修改时间\ + 权限\ + 所有者\ + 操作\ + \ + \ + '+body+'\ + '; $("#fileCon").removeClass("fileList").html(tablehtml); $("#tipTools").width($("#fileCon").width()); } else { @@ -502,14 +512,14 @@ function getFiles(Path) { } $("#DirPathPlace input").val(rdata.PATH); var BarTools = '
\ - \ - \ -
'; + \ + \ + '; if (rdata.PATH != '/') { BarTools += ' '; } @@ -1288,21 +1298,24 @@ function unZip(fileName, type) { if(type.length ==3){ var sfile = encodeURIComponent($("#sfile").val()); var dfile = encodeURIComponent($("#dfile").val()); - coding = $("select[name='coding']").val(); - layer.closeAll(); - layer.msg(lan.files.unzip_the, {icon: 16,time: 0,shade: [0.3, '#000']}); + var coding = $("select[name='coding']").val(); + var tip = layer.msg(lan.files.unzip_the, {icon: 16,time: 0,shade: [0.3, '#000']}); $.post('/files/unzip', 'sfile=' + sfile + '&dfile=' + dfile +'&type=' + type + '&path='+encodeURIComponent(path), function(rdata) { - layer.closeAll(); - layer.msg(rdata.msg, {icon: rdata.status ? 1 : 2}); - getFiles(path); + layer.close(tip); + showMsg(rdata.msg, function(){ + getFiles(path); + },{icon: rdata.status ? 1 : 2},2000); },'json'); - return + return; } type = (type == 1) ? 'tar':'zip'; var umpass = ''; if(type == 'zip'){ - umpass = '
'+lan.files.zip_pass_title+'
' + umpass = '
\ + '+lan.files.zip_pass_title+'\ + \ +
'; } layer.open({ type: 1, @@ -1327,6 +1340,70 @@ function unZip(fileName, type) { }); } +function isCompressFile(fileName){ + var ext = fileName.split('.'); + var extName = ext[ext.length-1].toLowerCase(); + var support = ['zip','gz','tgz','rar']; + for (x in support) { + if (support[x]==extName){ + return true; + } + } + return false; +} + +function unCompressFile(fileName, type = 0){ + // 解压文件 + var path = $("#DirPathPlace input").val(); + if(type == 3){ + var sfile = encodeURIComponent($("#sfile").val()); + var dfile = encodeURIComponent($("#dfile").val()); + var coding = $("select[name='coding']").val(); + var tip = layer.msg('正在解压,请稍候...', {icon: 16,time: 0,shade: [0.3, '#000']}); + $.post('/files/uncompress', 'sfile=' + sfile + '&dfile=' + dfile +'&type=' + type + '&path='+encodeURIComponent(path), function(rdata) { + layer.close(tip); + showMsg(rdata.msg, function(){ + layer.closeAll(); + getFiles(path); + },{icon: rdata.status ? 1 : 2},2000); + },'json'); + return; + } + + // var umpass = '
\ + // 解压密码\ + // \ + //
'; + layer.open({ + type: 1, + shift: 5, + closeBtn: 1, + area: '490px', + title: '解压文件', + content: '
\ +
\ + 文件名\ + \ +
\ +
\ + 解压到\ + \ +
\ +
\ + 编码\ + \ +
\ +
\ + \ + \ +
\ +
' + }); +} + //是否压缩文件 function isZip(fileName){ var ext = fileName.split('.'); diff --git a/route/static/app/public.js b/route/static/app/public.js index 0abe3cb66..5e272d260 100755 --- a/route/static/app/public.js +++ b/route/static/app/public.js @@ -362,14 +362,17 @@ function getDiskList(b) { for(var f = 0; f < h.DIR.length; f++) { var g = h.DIR[f].split(";"); var e = g[0]; - if(e.length > 20) { - e = e.substring(0, 20) + "..." - } + if(isChineseChar(e)) { if(e.length > 10) { - e = e.substring(0, 10) + "..." + e = e.substring(0, 10) + "..."; + } + } else{ + if(e.length > 20) { + e = e.substring(0, 20) + "..."; } } + d += "\ \ " + e + "" + getLocalTime(g[2]) + "\ @@ -382,14 +385,16 @@ function getDiskList(b) { for(var f = 0; f < h.FILES.length; f++) { var g = h.FILES[f].split(";"); var e = g[0]; - if(e.length > 20) { - e = e.substring(0, 20) + "..." - } if(isChineseChar(e)) { if(e.length > 10) { e = e.substring(0, 10) + "..." } + } else{ + if(e.length > 20) { + e = e.substring(0, 20) + "..." + } } + d += "\ " + e + "\ " + getLocalTime(g[2]) + "\ @@ -403,7 +408,7 @@ function getDiskList(b) { $(".file-list").show(); $("#tbody").html(d); if(h.PATH.substr(h.PATH.length - 1, 1) != "/") { - h.PATH += "/" + h.PATH += "/"; } $("#PathPlace").find("span").html(h.PATH); activeDisk(); From fe4c95276df7b91195cd4ae1e1c56208729c350b Mon Sep 17 00:00:00 2001 From: midoks Date: Fri, 15 Sep 2023 00:08:13 +0800 Subject: [PATCH 2/7] Update files_api.py --- class/core/files_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/class/core/files_api.py b/class/core/files_api.py index 08987ef3e..34f7f8803 100755 --- a/class/core/files_api.py +++ b/class/core/files_api.py @@ -858,8 +858,8 @@ class files_api: " -C " + dfile + " > " + tmps + " 2>&1 &" mw.execShell(cmd) if extension == 'rar': - cmd = "cd " + path + " && unrar x t.rar " + \ - sfile + " " + dfile + " > " + tmps + " 2>&1 &" + cmd = "cd " + path + " && unrar x " + sfile + \ + " " + dfile + " > " + tmps + " 2>&1 &" mw.execShell(cmd) if os.path.exists(dfile): From f05de84dc2f3bc65daf6e5bc81ccc885fcb0c76b Mon Sep 17 00:00:00 2001 From: midoks Date: Fri, 15 Sep 2023 00:13:05 +0800 Subject: [PATCH 3/7] Update files_api.py --- class/core/files_api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/class/core/files_api.py b/class/core/files_api.py index 34f7f8803..a4460d276 100755 --- a/class/core/files_api.py +++ b/class/core/files_api.py @@ -845,7 +845,10 @@ class files_api: extension = extension.strip('.') if not extension in ['gz', 'zip', 'rar']: - return mw.returnJson(False, '现在仅支持gz,zip,rar文件解压!') + return mw.returnJson(False, '现在仅支持gz,zip,rar格式解压!') + + if mw.isAppleSystem() and extension == 'rar': + return mw.returnJson(False, 'macosx暂时不支持rar格式解压') try: tmps = mw.getRunDir() + '/tmp/panelExec.log' From a488f106ca14cbd392a145680a630d8c6ee23b7f Mon Sep 17 00:00:00 2001 From: midoks Date: Fri, 15 Sep 2023 00:37:23 +0800 Subject: [PATCH 4/7] Update files_api.py --- class/core/files_api.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/class/core/files_api.py b/class/core/files_api.py index a4460d276..f7e7598cb 100755 --- a/class/core/files_api.py +++ b/class/core/files_api.py @@ -844,7 +844,13 @@ class files_api: extension = os.path.splitext(filename)[-1] extension = extension.strip('.') - if not extension in ['gz', 'zip', 'rar']: + tar_gz = 'tar.gz' + tar_gz_len = len(tar_gz) + suffix_gz = sfile[-tar_gz_len:] + if suffix_gz == tar_gz: + extension = suffix_gz + + if not extension in ['tar.gz', 'gz', 'zip', 'rar']: return mw.returnJson(False, '现在仅支持gz,zip,rar格式解压!') if mw.isAppleSystem() and extension == 'rar': @@ -856,10 +862,13 @@ class files_api: cmd = "cd " + path + " && unzip -o -d '" + dfile + \ "' '" + sfile + "' > " + tmps + " 2>&1 &" mw.execShell(cmd) - if extension == 'gz': + if extension == 'tar.gz': cmd = "cd " + path + " && tar -zxvf " + sfile + \ " -C " + dfile + " > " + tmps + " 2>&1 &" mw.execShell(cmd) + if extension == 'gz': + cmd = "cd " + path + " && gunzip -k " + sfile + " > " + tmps + " 2>&1 &" + mw.execShell(cmd) if extension == 'rar': cmd = "cd " + path + " && unrar x " + sfile + \ " " + dfile + " > " + tmps + " 2>&1 &" From 4af7183dbd9bf27c18a1b8580c08ab065ff72088 Mon Sep 17 00:00:00 2001 From: midoks Date: Fri, 15 Sep 2023 00:43:01 +0800 Subject: [PATCH 5/7] Update config_api.py --- class/core/config_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index c2eab6678..53f0e2b2d 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -27,7 +27,7 @@ from flask import request class config_api: - __version = '0.16.1.1' + __version = '0.16.1' __api_addr = 'data/api.json' def __init__(self): From 586302b57560ec9de4b2d7e21d7b1b0ac2ea2f06 Mon Sep 17 00:00:00 2001 From: midoks Date: Fri, 15 Sep 2023 00:59:50 +0800 Subject: [PATCH 6/7] Update config_api.py --- class/core/config_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index 53f0e2b2d..4a4a306b3 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -27,7 +27,7 @@ from flask import request class config_api: - __version = '0.16.1' + __version = '0.16.1.2' __api_addr = 'data/api.json' def __init__(self): From 682f8309c4c265b3741c36e45ec6147bf653d839 Mon Sep 17 00:00:00 2001 From: midoks Date: Fri, 15 Sep 2023 01:07:29 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=94=AF=E6=8C=81rar=E8=A7=A3=E5=8E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + class/core/config_api.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aa5bc78d2..bb4c51286 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443: * 安装时默认监控开启。 * MySQL/MYSQL-YUM/MySQL-APT添加重置master功能。 * 支持华为欧拉系统。 +* 支持rar解压。 ### JSDelivr安装地址 diff --git a/class/core/config_api.py b/class/core/config_api.py index 4a4a306b3..53f0e2b2d 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -27,7 +27,7 @@ from flask import request class config_api: - __version = '0.16.1.2' + __version = '0.16.1' __api_addr = 'data/api.json' def __init__(self):