diff --git a/class/core/files_api.py b/class/core/files_api.py
index d559951b9..6edd5d773 100755
--- a/class/core/files_api.py
+++ b/class/core/files_api.py
@@ -148,12 +148,16 @@ class files_api:
if not os.path.exists(path):
path = mw.getRootDir() + "/wwwroot"
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
+ # 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)
def createFileApi(self):
@@ -830,11 +834,59 @@ class files_api:
if search:
if name.lower().find(search) == -1:
continue
- # if name[0:1] == '.':
- # continue
+ if name == '.':
+ continue
i += 1
return i
+ def getAllDir(self, path, page=1, page_size=10, search=None):
+ # print("search:", search)
+ data = {}
+ dirnames = []
+ filenames = []
+
+ count = 0
+ max_limit = 3000
+
+ for d_list in os.walk(path):
+ if count >= max_limit:
+ break
+
+ for d in d_list[1]:
+ if count >= max_limit:
+ break
+ if d.lower().find(search) != -1:
+ filename = d_list[0] + '/' + d
+ if not os.path.exists(filename):
+ continue
+ dirnames.append(self.__get_stats(filename, path))
+ count += 1
+
+ for f in d_list[2]:
+ if count >= max_limit:
+ break
+
+ if f.lower().find(search) != -1:
+ filename = d_list[0] + '/' + f
+ if not os.path.exists(filename):
+ continue
+ filenames.append(self.__get_stats(filename, path))
+ count += 1
+
+ data['DIR'] = sorted(dirnames)
+ data['FILES'] = sorted(filenames)
+ data['PATH'] = path.replace('//', '/')
+
+ info = {}
+ info['count'] = len(dirnames) + len(filenames)
+ 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]
+
+ return mw.getJson(data)
+
def getDir(self, path, page=1, page_size=10, search=None):
data = {}
dirnames = []
@@ -861,31 +913,14 @@ class files_api:
continue
try:
filePath = path + '/' + filename
- link = ''
- if os.path.islink(filePath):
- filePath = os.readlink(filePath)
- link = ' -> ' + filePath
- if not os.path.exists(filePath):
- filePath = path + '/' + filePath
- if not os.path.exists(filePath):
- continue
-
- stat = os.stat(filePath)
- accept = str(oct(stat.st_mode)[-3:])
- mtime = str(int(stat.st_mtime))
- user = ''
- try:
- user = pwd.getpwuid(stat.st_uid).pw_name
- except Exception as ee:
- user = str(stat.st_uid)
+ if not os.path.exists(filePath):
+ continue
- size = str(stat.st_size)
+ file_stats = self.__get_stats(filePath, path)
if os.path.isdir(filePath):
- dirnames.append(filename + ';' + size + ';' +
- mtime + ';' + accept + ';' + user + ';' + link)
+ dirnames.append(file_stats)
else:
- filenames.append(filename + ';' + size + ';' +
- mtime + ';' + accept + ';' + user + ';' + link)
+ filenames.append(file_stats)
n += 1
except Exception as e:
continue
@@ -894,3 +929,26 @@ class files_api:
data['PATH'] = path.replace('//', '/')
return mw.getJson(data)
+
+ def __get_stats(self, filename, path=None):
+ try:
+ stat = os.stat(filename)
+ accept = str(oct(stat.st_mode)[-3:])
+ mtime = str(int(stat.st_mtime))
+ user = ''
+ try:
+ user = str(pwd.getpwuid(stat.st_uid).pw_name)
+ except:
+ user = str(stat.st_uid)
+ size = str(stat.st_size)
+ link = ''
+ if os.path.islink(filename):
+ link = ' -> ' + os.readlink(filename)
+ if path:
+ tmp_path = (path + '/').replace('//', '/')
+ if tmp_path != '/':
+ filename = filename.replace(tmp_path, '', 1)
+ return filename + ';' + size + ';' + mtime + ';' + accept + ';' + user + ';' + link
+ except Exception as e:
+ # print(e)
+ return ';;;;;'
diff --git a/route/static/app/files.js b/route/static/app/files.js
index 469474bb2..f47e2f892 100755
--- a/route/static/app/files.js
+++ b/route/static/app/files.js
@@ -289,7 +289,7 @@ function openFilename(obj){
var ext = getSuffixName(path);
// console.log(path,ext);
- if (inArray(ext,['html','htm','php','txt','md','js','css','scss','json','c','h','pl','py','java','log','conf'])){
+ if (inArray(ext,['html','htm','php','txt','md','js','css','scss','json','c','h','pl','py','java','log','conf','sh','json'])){
onlineEditFile(0, path);
}
@@ -317,6 +317,10 @@ function openFilename(obj){
}
}
+function searchFile(p){
+ getFiles(p);
+}
+
//取数据
function getFiles(Path) {
var searchtype = Path;
@@ -342,7 +346,14 @@ function getFiles(Path) {
var data = 'path=' + Path;
var loadT = layer.load();
var totalSize = 0;
- $.post('/files/get_dir?p=' + p + '&showRow=' + showRow + search, data, function(rdata) {
+
+ var search_all = '';
+ var all = $('#search_all').hasClass('active');
+ if(all){
+ search_all = "&all=yes";
+ }
+
+ $.post('/files/get_dir?p=' + p + '&showRow=' + showRow + search + search_all, data, function(rdata) {
layer.close(loadT);
var rows = ['10','50','100','200','500','1000','2000'];
@@ -444,8 +455,7 @@ function getFiles(Path) {
剪切 | \
重命名 | \
权限 | \
- 压缩 | \
- "+bodyZip+download+"\
+ 压缩 | "+bodyZip+download+"\
删除\
\
";
@@ -459,9 +469,9 @@ function getFiles(Path) {
";
}
}
- var dirInfo = '(共{1}个目录与{2}个文件,大小:'.replace('{1}',rdata.DIR.length+'').replace('{2}',rdata.DIR.length+'')+''
+ var dirInfo = '(共{1}个目录与{2}个文件,大小:'.replace('{1}',rdata.DIR.length+'').replace('{2}',rdata.FILES.length+'')+''
+ (toSize(totalSize))+'获取)';
- $("#DirInfo").html(dirInfo);
+ $("#dir_info").html(dirInfo);
if( getCookie('rank') == 'a' ){
var tablehtml = '\
\
@@ -791,7 +801,7 @@ function getSuffixName(fileName){
'gif','ico','jpeg','jpg','JPG','png','psd','webp','ape','avi','flv','mkv','mov','mp3','mp4','mpeg',
'mpg','rm','rmvb','swf','wav','webm','wma','wmv','doc','docm','dotx','dotm','dot','rtf','docx','pdf',
'fdf','ppt','pptm','pot','potm','pptx','txt','xls','csv','xlsm','xlsb','xlsx','7z','gz','cab','iso',
- 'rar','zip','bt','file','apk','css','scss','svg','pl','py','php','md'];
+ 'rar','zip','bt','file','apk','css','scss','svg','pl','py','php','md','json','sh'];
var extLastName = extArr[extArr.length - 1];
for(var i=0; i
-
+
@@ -93,5 +97,10 @@ $("#set_list").click(function() {
$(".refreshBtn").click(function() {
getFiles(getCookie('open_dir_path'));
})
+
+
+$('#search_all').click(function(){
+ $(this).toggleClass('active');
+});
{% endblock %}
\ No newline at end of file