diff --git a/class/core/files_api.py b/class/core/files_api.py
index 0260d023f..3c8843201 100755
--- a/class/core/files_api.py
+++ b/class/core/files_api.py
@@ -161,15 +161,12 @@ class files_api:
search = request.args.get('search', '').strip().lower()
search_all = request.args.get('all', '').strip().lower()
page = request.args.get('p', '1').strip().lower()
- row = request.args.get('showRow', '10')
- disk = request.form.get('disk', '')
- if disk == 'True':
- row = 1000
+ row = request.args.get('row', '10')
+ order = request.form.get('order', '')
- # return self.getAllDir(path, int(page), int(row), "wp-inlcude")
if search_all == 'yes' and search != '':
- return self.getAllDir(path, int(page), int(row), search)
- return self.getDir(path, int(page), int(row), search)
+ return self.getAllDir(path, int(page), int(row), order, search)
+ return self.getDir(path, int(page), int(row), order, search)
def createFileApi(self):
file = request.form.get('path', '')
@@ -948,16 +945,64 @@ class files_api:
i += 1
return i
- def getAllDir(self, path, page=1, page_size=10, search=None):
+ def getAllDir(self, path, page=1, page_size=10, order='', search=None):
# print("search:", search)
data = {}
dirnames = []
filenames = []
+ info = {}
+
+ i = 0
+ n = 0
count = 0
max_limit = 3000
+ order_arr = order.split(' ')
+ if len(order_arr) < 2:
+ plist = mw.sortAllFileList(path, order_arr[0],'',search, max_limit)
+ else:
+ plist = mw.sortAllFileList(path, order_arr[0], order_arr[1], search,max_limit)
+
+ info['count'] = len(plist)
+ info['row'] = page_size
+ info['p'] = page
+ info['tojs'] = 'getFiles'
+ pageObj = mw.getPageObject(info, '1,2,3,4,5,6,7,8')
+ data['PAGE'] = pageObj[0]
+
+ for dst_file in plist:
+
+ if not os.path.exists(dst_file):
+ continue
+
+ i += 1
+ if n >= pageObj[1].ROW:
+ break
+ if i < pageObj[1].SHIFT:
+ continue
+
+ if os.path.isdir(dst_file):
+ dirnames.append(self.__get_stats(dst_file, path))
+ else:
+ filenames.append(self.__get_stats(dst_file, path))
+ n += 1
+
+ data['DIR'] = dirnames
+ data['FILES'] = filenames
+ data['PATH'] = path.replace('//', '/')
+
+ return mw.getJson(data)
+
+ #备份
+ def getAllDirBk(self, path, page=1, page_size=10, order='', search=None):
+ data = {}
+ dirnames = []
+ filenames = []
+ count = 0
+ max_limit = 3000
for d_list in os.walk(path):
+
if count >= max_limit:
break
@@ -996,7 +1041,7 @@ class files_api:
return mw.getJson(data)
- def getDir(self, path, page=1, page_size=10, search=None):
+ def getDir(self, path, page=1, page_size=10, order = '', search=None):
data = {}
dirnames = []
filenames = []
@@ -1011,7 +1056,14 @@ class files_api:
i = 0
n = 0
- for filename in os.listdir(path):
+
+ order_arr = order.split(' ')
+ if len(order_arr) < 2:
+ plist = mw.sortFileList(path, order_arr[0],'')
+ else:
+ plist = mw.sortFileList(path, order_arr[0],order_arr[1])
+
+ for filename in plist:
if search:
if filename.lower().find(search) == -1:
continue
@@ -1033,8 +1085,8 @@ class files_api:
n += 1
except Exception as e:
continue
- data['DIR'] = sorted(dirnames)
- data['FILES'] = sorted(filenames)
+ data['DIR'] = dirnames
+ data['FILES'] = filenames
data['PATH'] = path.replace('//', '/')
return mw.getJson(data)
@@ -1067,6 +1119,7 @@ cd %s
return mw.returnJson(status, mw.getNumLines(fileName, 200))
def __get_stats(self, filename, path=None):
+ # print(filename,path)
filename = filename.replace('//', '/')
try:
stat = os.stat(filename)
diff --git a/class/core/mw.py b/class/core/mw.py
index 4d12d2f25..d06be15d2 100755
--- a/class/core/mw.py
+++ b/class/core/mw.py
@@ -1598,6 +1598,63 @@ def checkCert(certPath='ssl/certificate.pem'):
return True
+def sortFileList(path, ftype = 'mtime', sort = 'desc'):
+ flist = os.listdir(path)
+ if ftype == 'mtime':
+ if sort == 'desc':
+ flist = sorted(flist, key=lambda f: os.path.getmtime(os.path.join(path,f)), reverse=True)
+ if sort == 'asc':
+ flist = sorted(flist, key=lambda f: os.path.getmtime(os.path.join(path,f)), reverse=False)
+
+ if ftype == 'size':
+ if sort == 'desc':
+ flist = sorted(flist, key=lambda f: os.path.getsize(os.path.join(path,f)), reverse=True)
+ if sort == 'asc':
+ flist = sorted(flist, key=lambda f: os.path.getsize(os.path.join(path,f)), reverse=False)
+ return flist
+
+
+def sortAllFileList(path, ftype = 'mtime', sort = 'desc', search = '',limit = 3000):
+ count = 0
+ flist = []
+ for d_list in os.walk(path):
+ if count >= limit:
+ break
+
+ for d in d_list[1]:
+ if count >= limit:
+ break
+ if d.lower().find(search) != -1:
+ filename = d_list[0] + '/' + d
+ if not os.path.exists(filename):
+ continue
+ count += 1
+ flist.append(filename)
+
+ for f in d_list[2]:
+ if count >= limit:
+ break
+
+ if f.lower().find(search) != -1:
+ filename = d_list[0] + '/' + f
+ if not os.path.exists(filename):
+ continue
+ count += 1
+ flist.append(filename)
+
+ if ftype == 'mtime':
+ if sort == 'desc':
+ flist = sorted(flist, key=lambda f: os.path.getmtime(f), reverse=True)
+ if sort == 'asc':
+ flist = sorted(flist, key=lambda f: os.path.getmtime(f), reverse=False)
+
+ if ftype == 'size':
+ if sort == 'desc':
+ flist = sorted(flist, key=lambda f: os.path.getsize(f), reverse=True)
+ if sort == 'asc':
+ flist = sorted(flist, key=lambda f: os.path.getsize(f), reverse=False)
+ return flist
+
def getPathSize(path):
# 取文件或目录大小
if not os.path.exists(path):
diff --git a/route/static/app/files.js b/route/static/app/files.js
index 415502ac8..958689358 100755
--- a/route/static/app/files.js
+++ b/route/static/app/files.js
@@ -26,15 +26,15 @@ function recycleBin(type){
if(shortwebname.length > 20) shortwebname = shortwebname.substring(0, 20) + "...";
if(shortpath.length > 20) shortpath = shortpath.substring(0, 20) + "...";
body += '
\
- '+shortwebname+' | \
- '+shortpath+' | \
- '+toSize(rdata.dirs[i].size)+' | \
- '+getLocalTime(rdata.dirs[i].time)+' | \
- \
- '+lan.files.recycle_bin_re+'\
- | '+lan.files.recycle_bin_del+'\
- | \
-
'
+ '+shortwebname+' | \
+ '+shortpath+' | \
+ '+toSize(rdata.dirs[i].size)+' | \
+ '+getLocalTime(rdata.dirs[i].time)+' | \
+ \
+ '+lan.files.recycle_bin_re+'\
+ | '+lan.files.recycle_bin_del+'\
+ | \
+ ';
}
for(var i=0;i 20) shortwebname = shortwebname.substring(0, 20) + "...";
if(shortpath.length > 20) shortpath = shortpath.substring(0, 20) + "...";
body += '\
- '+shortwebname.replace('BTDB_','')+' | \
- mysql://'+shortpath.replace('BTDB_','')+' | \
- - | \
- '+getLocalTime(rdata.files[i].time)+' | \
- \
- '+lan.files.recycle_bin_re+'\
- | '+lan.files.recycle_bin_del+'\
- | \
-
'
+ '+shortwebname.replace('BTDB_','')+' | \
+ mysql://'+shortpath.replace('BTDB_','')+' | \
+ - | \
+ '+getLocalTime(rdata.files[i].time)+' | \
+ \
+ '+lan.files.recycle_bin_re+'\
+ | '+lan.files.recycle_bin_del+'\
+ | \
+ ';
continue;
}
@@ -80,15 +80,15 @@ function recycleBin(type){
if(shortwebname.length > 20) shortwebname = shortwebname.substring(0, 20) + "...";
if(shortpath.length > 20) shortpath = shortpath.substring(0, 20) + "...";
body += '\
- '+shortwebname+' | \
- '+shortpath+' | \
- '+toSize(rdata.dirs[i].size)+' | \
- '+getLocalTime(rdata.dirs[i].time)+' | \
- \
- '+lan.files.recycle_bin_re+'\
- | '+lan.files.recycle_bin_del+'\
- | \
-
'
+ '+shortwebname+' | \
+ '+shortpath+' | \
+ '+toSize(rdata.dirs[i].size)+' | \
+ '+getLocalTime(rdata.dirs[i].time)+' | \
+ \
+ '+lan.files.recycle_bin_re+'\
+ | '+lan.files.recycle_bin_del+'\
+ | \
+ '
}
$("#RecycleBody").html(body);
return;
@@ -101,15 +101,15 @@ function recycleBin(type){
if(shortwebname.length > 20) shortwebname = shortwebname.substring(0, 20) + "...";
if(shortpath.length > 20) shortpath = shortpath.substring(0, 20) + "...";
body += '\
- '+shortwebname+' | \
- '+shortpath+' | \
- '+toSize(rdata.files[i].size)+' | \
- '+getLocalTime(rdata.files[i].time)+' | \
- \
- '+lan.files.recycle_bin_re+'\
- | '+lan.files.recycle_bin_del+'\
- | \
-
'
+ '+shortwebname+' | \
+ '+shortpath+' | \
+ '+toSize(rdata.files[i].size)+' | \
+ '+getLocalTime(rdata.files[i].time)+' | \
+ \
+ '+lan.files.recycle_bin_re+'\
+ | '+lan.files.recycle_bin_del+'\
+ | \
+ ';
}
$("#RecycleBody").html(body);
return;
@@ -122,15 +122,15 @@ function recycleBin(type){
if(shortwebname.length > 20) shortwebname = shortwebname.substring(0, 20) + "...";
if(shortpath.length > 20) shortpath = shortpath.substring(0, 20) + "...";
body += '\
- '+shortwebname+' | \
- '+shortpath+' | \
- '+toSize(rdata.files[i].size)+' | \
- '+getLocalTime(rdata.files[i].time)+' | \
- \
- '+lan.files.recycle_bin_re+'\
- | '+lan.files.recycle_bin_del+'\
- | \
-
'
+ '+shortwebname+' | \
+ '+shortpath+' | \
+ '+toSize(rdata.files[i].size)+' | \
+ '+getLocalTime(rdata.files[i].time)+' | \
+ \
+ '+lan.files.recycle_bin_re+'\
+ | '+lan.files.recycle_bin_del+'\
+ | \
+ ';
}
}
$("#RecycleBody").html(body);
@@ -222,6 +222,7 @@ function getFileName(name){
text = text[n];
return text;
}
+
//判断图片文件
function reisImage(fileName){
var exts = ['jpg','jpeg','png','bmp','gif','tiff','ico'];
@@ -328,87 +329,142 @@ function searchFile(p){
getFiles(p);
}
+//处理排序
+function listFileOrder(skey, obj){
+ var or = getCookie('file_order');
+ var orderType = 'desc';
+ if(or){
+ var or_arr = or.split('|');
+ if(or.split('|')[1] == 'desc'){
+ orderType = 'asc';
+ } else if (or_arr[1] == 'asc'){
+ orderType = 'none';
+ } else {
+ orderType = 'desc';
+ }
+ }
+ setCookie('file_order',skey + '|' + orderType);
+ getFiles(1);
+ // console.log(obj,orderType);
+ // if(orderType == 'desc'){
+ // $(obj).find(".glyphicon-triangle-top").remove();
+ // $(obj).append("");
+ // } else {
+ // $(obj).find(".glyphicon-triangle-bottom").remove();
+ // $(obj).append("");
+ // }
+}
+
+function makeFilePage(showRow, page = ''){
+ var rows = ['10','50','100','200','500','1000','2000'];
+ var rowOption = '';
+ for(var i=0;i'+rows[i]+'';
+ }
+
+ //分页
+ $("#filePage").html(page);
+ $("#filePage div").append("每页条");
+ $("#filePage .Pcount").css("left","16px");
+}
+
//取数据
function getFiles(Path) {
- var searchtype = Path;
if(isNaN(Path)){
var p = 1;
- Path = encodeURIComponent(Path);
} else {
var p = Path;
Path = getCookie('open_dir_path');
- Path = encodeURIComponent(Path);
- }
-
- var search = '';
- var searchV = $("#SearchValue").val();
- if(searchV.length > 1 && searchtype == '1'){
- search = "&search="+searchV;
}
- var showRow = getCookie('showRow');
- if(!showRow) {
- showRow = '100';
+
+ var args = {};
+ args['p'] = p;
+ var post = {};
+ post['path'] = Path;
+
+
+ var file_row = $.cookie('file_row');
+ if(!file_row) {
+ file_row = '100';
+ args['row'] = file_row;
}
+
var body = '';
- var data = 'path=' + Path;
var totalSize = 0;
+ var search = '';
+ var search_file = $("#search_file").val();
+
+ if(search_file.length > 0){
+ args['search'] = search_file;
+ }
+
var search_all = '';
var all = $('#search_all').hasClass('active');
if(all){
- search_all = "&all=yes";
+ args['all'] = 'yes';
}
+ var file_order = $.cookie('file_order');
+ if (file_order){
+ post['order'] = file_order.replace('|',' ');
+ }
+
+ var query_str = toUrlParam(args);
+
var loadT = layer.load();
- $.post('/files/get_dir?p=' + p + '&showRow=' + showRow + search + search_all, data, function(rdata) {
+ $.post('/files/get_dir?' + query_str, post, function(rdata) {
layer.close(loadT);
- var rows = ['10','50','100','200','500','1000','2000'];
- var rowOption = '';
- for(var i=0;i'+rows[i]+'';
+ //构建分页
+ makeFilePage(file_row,rdata.PAGE);
+
+ if(rdata.DIR == null) {
+ rdata.DIR = [];
}
-
- $("#filePage").html(rdata.PAGE);
- $("#filePage div").append("每页条");
- $("#filePage .Pcount").css("left","16px");
- if(rdata.DIR == null) rdata.DIR = [];
+
for (var i = 0; i < rdata.DIR.length; i++) {
+
var fmp = rdata.DIR[i].split(";");
var cnametext =fmp[0] + fmp[5];
+
fmp[0] = fmp[0].replace(/'/, "\\'");
if(cnametext.length>20){
cnametext = cnametext.substring(0,20) + '...';
}
+
if(isChineseChar(cnametext)){
if(cnametext.length>10){
cnametext = cnametext.substring(0,10) + '...';
}
}
+
var timetext ='--';
if(getCookie('rank') == 'a'){
- $("#set_list").addClass("active");
- $("#set_icon").removeClass("active");
- body += "\
- | \
- \
- " + cnametext + " | \
- "+toSize(fmp[1])+" | \
- "+getLocalTime(fmp[2])+" | \
- "+fmp[3]+" | \
- "+fmp[4]+" | \
- \
-
";
+ //列表展示
+ $("#set_list").addClass("active");
+ $("#set_icon").removeClass("active");
+ body += "\
+ | \
+ \
+ " + cnametext + " | \
+ "+toSize(fmp[1])+" | \
+ "+getLocalTime(fmp[2])+" | \
+ "+fmp[3]+" | \
+ "+fmp[4]+" | \
+ \
+
";
} else {
+ //图标展示
$("#set_icon").addClass("active");
$("#set_list").removeClass("active");
body += "