update
This commit is contained in:
parent
cf7323cf12
commit
c1607752b2
|
|
@ -19,6 +19,8 @@ from flask import send_from_directory
|
|||
from werkzeug.utils import secure_filename
|
||||
|
||||
from admin.user_login_check import panel_login_required
|
||||
from admin import session
|
||||
|
||||
import core.mw as mw
|
||||
import utils.file as file
|
||||
import thisdb
|
||||
|
|
@ -31,9 +33,43 @@ def index():
|
|||
return render_template('%s/files.html' % name)
|
||||
|
||||
# 获取文件内容
|
||||
@blueprint.route('/get_body', endpoint='get_file_body', methods=['POST'])
|
||||
@blueprint.route('/check_exists_files', endpoint='check_exists_files', methods=['POST'])
|
||||
@panel_login_required
|
||||
def get_file_body():
|
||||
def check_exists_files():
|
||||
dfile = request.form.get('dfile', '')
|
||||
filename = request.form.get('filename', '')
|
||||
data = []
|
||||
filesx = []
|
||||
if filename == '':
|
||||
filesx = json.loads(session['selected']['data'])
|
||||
else:
|
||||
filesx.append(filename)
|
||||
|
||||
for fn in filesx:
|
||||
if fn == '.':
|
||||
continue
|
||||
filename = dfile + '/' + fn
|
||||
if os.path.exists(filename):
|
||||
tmp = {}
|
||||
stat = os.stat(filename)
|
||||
tmp['filename'] = fn
|
||||
tmp['size'] = os.path.getsize(filename)
|
||||
tmp['mtime'] = str(int(stat.st_mtime))
|
||||
data.append(tmp)
|
||||
return mw.returnData(True, 'ok', data)
|
||||
|
||||
# 获取文件内容
|
||||
@blueprint.route('/copy_file', endpoint='copy_file', methods=['POST'])
|
||||
@panel_login_required
|
||||
def copy_file():
|
||||
sfile = request.form.get('sfile', '')
|
||||
dfile = request.form.get('dfile', '')
|
||||
return file.copyFile(sfile, dfile)
|
||||
|
||||
# 获取文件内容
|
||||
@blueprint.route('/get_body', endpoint='get_body', methods=['POST'])
|
||||
@panel_login_required
|
||||
def get_body():
|
||||
path = request.form.get('path', '')
|
||||
return file.getFileBody(path)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,45 @@ import shutil
|
|||
import core.mw as mw
|
||||
import thisdb
|
||||
|
||||
def copyDir(src_file, dst_file):
|
||||
if not os.path.exists(src_file):
|
||||
return mw.returnData(False, '指定目录不存在!')
|
||||
|
||||
if os.path.exists(dst_file):
|
||||
return mw.returnData(False, '指定目录已存在!')
|
||||
|
||||
import shutil
|
||||
try:
|
||||
shutil.copytree(src_file, dst_file)
|
||||
stat = os.stat(src_file)
|
||||
os.chown(dst_file, stat.st_uid, stat.st_gid)
|
||||
msg = mw.getInfo('复制目录[{1}]到[{2}]成功!', (src_file, dst_file))
|
||||
mw.writeLog('文件管理', msg)
|
||||
return mw.returnData(True, '目录复制成功!')
|
||||
except:
|
||||
return mw.returnData(False, '目录复制失败!')
|
||||
|
||||
def copyFile(src_file, dst_file):
|
||||
if src_file == dst_file:
|
||||
return mw.returnJson(False, '源与目的一致!')
|
||||
|
||||
if not os.path.exists(src_file):
|
||||
return mw.returnJson(False, '指定文件不存在!')
|
||||
|
||||
if os.path.isdir(src_file):
|
||||
return copyDir(src_file, dst_file)
|
||||
|
||||
try:
|
||||
import shutil
|
||||
shutil.copyfile(src_file, dst_file)
|
||||
msg = mw.getInfo('复制文件[{1}]到[{2}]成功!', (src_file, dst_file,))
|
||||
mw.writeLog('文件管理', msg)
|
||||
stat = os.stat(src_file)
|
||||
os.chown(dst_file, stat.st_uid, stat.st_gid)
|
||||
return mw.returnData(True, '文件复制成功!')
|
||||
except:
|
||||
return mw.returnData(False, '文件复制失败!')
|
||||
|
||||
def setFileAccept(filename):
|
||||
auth = 'www:www'
|
||||
if mw.getOs() == 'darwin':
|
||||
|
|
|
|||
Loading…
Reference in New Issue