Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
midoks committed Dec 11, 2018
1 parent 155ad33 commit 12a6687
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
58 changes: 48 additions & 10 deletions class/core/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ class file_api:
def __init__(self):
pass

def setFileAccept(self, filename):
auth = 'www:www'
if public.getOs() == 'darwin':
user = public.execShell(
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
auth = user + ':staff'
os.system('chown -R ' + auth + ' ' + filename)
os.system('chmod -R 755 ' + filename)

# 移动到回收站
def mvRecycleBin(self, path):
rPath = public.getRootDir() + '/recycle_bin/'
if not os.path.exists(rPath):
os.system('mkdir -p ' + rPath)

rFile = rPath + path.replace('/', '_mw_') + '_t_' + str(time.time())
try:
import shutil
shutil.move(path, rFile)
public.writeLog('TYPE_FILE', public.getInfo(
'移动文件[{1}]到回收站成功!', (path)))
return True
except:
public.writeLog('TYPE_FILE', public.getInfo(
'移动文件[{1}]到回收站失败!', (path)))
return False

def getBody(self, path):
if not os.path.exists(path):
return public.returnJson(False, '文件不存在', (path,))
Expand Down Expand Up @@ -92,15 +119,6 @@ def saveBody(self, path, data, encoding='utf-8'):
except Exception as ex:
return public.returnJson(False, 'FILE_SAVE_ERR:' + str(ex))

def setFileAccept(self, filename):
auth = 'www:www'
if public.getOs() == 'darwin':
user = public.execShell(
"who | sed -n '2, 1p' |awk '{print $1}'")[0].strip()
auth = user + ':staff'
os.system('chown -R ' + auth + ' ' + filename)
os.system('chmod -R 755 ' + filename)

def zip(self, sfile, dfile, stype, path):
if sfile.find(',') == -1:
if not os.path.exists(path + '/' + sfile):
Expand All @@ -125,7 +143,27 @@ def zip(self, sfile, dfile, stype, path):
except:
return public.returnJson(False, '文件压缩失败!')

# 计算文件数量
def delete(self, path):

if not os.path.exists(path):
return public.returnJson(False, '指定文件不存在!')

# 检查是否为.user.ini
if path.find('.user.ini') >= 0:
os.system("chattr -i '" + path + "'")

try:
if os.path.exists('data/recycle_bin.pl'):
if self.mvRecycleBin(path):
return public.returnJson(True, '已将文件移动到回收站!')
os.remove(path)
public.writeLog('TYPE_FILE', public.getInfo(
'删除文件[{1}]成功!', (path)))
return public.returnJson(True, '删除文件成功!')
except:
return public.returnJson(False, '删除文件失败!')

# 计算文件数量
def getFilesCount(self, path, search):
i = 0
for name in os.listdir(path):
Expand Down
1 change: 1 addition & 0 deletions data/recycle_bin.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
True
4 changes: 2 additions & 2 deletions route/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def zip():
return file_api.file_api().zip(sfile, dfile, stype, path)


@files.route('/zip', methods=['POST'])
@files.route('/delete', methods=['POST'])
def delete():
path = request.form.get('path', '').encode('utf-8')
pass
return file_api.file_api().delete(path)


@files.route('/get_dir', methods=['POST'])
Expand Down

0 comments on commit 12a6687

Please sign in to comment.