1. 修复上传文件bug;2. 添加自定义选项

master
Abbey 5 years ago
parent 5afe79dec1
commit 0a2b6eb697
  1. 10
      app/admin/upload.py
  2. 67
      app/templates/admin/upload.html
  3. 4
      app/utils/upload_method.py
  4. 2
      config.py
  5. 4
      self_config.py.sample
  6. 9
      update.sh

@ -13,19 +13,19 @@ def upload():
return redirect(url_for('admin.upload'))
if os.path.isfile(local):
filelists=[local]
local='/'.join(local.split('/')[:-1])
else:
filelists=list_all_files(local)
if local.endswith('/'):
local=local[:-1]
for file in filelists:
print(file)
info={}
dir_,fname=os.path.dirname(file),os.path.basename(file)
remote_path=remote+'/'+dir_.replace(local,'')+'/'+fname
remote_path=remote_path.replace('//','/')
info['user']=user
info['localpath']=file
info['remote']=remote_path
info['remote']=remote_path.replace('//','/')
info['status']=''
info['speed']=''
info['id']=base64.b64encode(str(int(round(time.time())))+file)
@ -65,6 +65,12 @@ def UploadRPCserver():
subprocess.Popen(cmd,shell=True)
ret={'msg':'重启成功!'}
return jsonify(ret)
elif action=='delete_mode':
isdelete=request.form.get('isdelete','True')
set_config('delete_after_upload',isdelete)
redis_client.set('delete_after_upload',isdelete)
ret={'msg':'已设置!'}
return jsonify(ret)
ret=get_upload_tasks(page)
data={'code':1,'result':ret}
return jsonify(data)

@ -8,6 +8,11 @@
<div class="mdui-toolbar mdui-color-theme">
<button class="mdui-btn mdui-btn-icon" onclick="Restart()" mdui-tooltip="{{'{'}}content: '重启任务(因重启网站之后上传中断)'{{'}'}}"><i class="mdui-icon material-icons">&#xe863;</i></button>
<button class="mdui-btn mdui-btn-icon" onclick="ClearHist()" mdui-tooltip="{{'{'}}content: '清空任务'{{'}'}}"><i class="mdui-icon material-icons">&#xe0b8;</i></button>
<label class="mdui-switch" id="delete_mode_parent">
上传完成删除本地文件
<input type="checkbox" id="delete_mode" {%if GetConfig("delete_after_upload")=="True"%}checked{%endif%}/>
<i class="mdui-switch-icon"></i>
</label>
</div>
<div class="mdui-row">
<form action="" method="post">
@ -56,34 +61,65 @@
</div>
</div>
<script>
function ShowNotice(msg){
mdui.snackbar({
message: msg,
position: 'top'
});
}
$('#delete_mode').change(function(){
if($("#delete_mode").prop('checked')){
var index2 = layer.load(2, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
$.ajax({
type: "POST",
url: "{{url_for('admin.UploadRPCserver')}}",
data:{action:'delete_mode',isdelete:'True'},
dataType: "json",
success: function(data) {
ShowNotice(data.msg);
layer.close(index2);
}
});
}else{
var index2 = layer.load(2, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
$.ajax({
type: "POST",
url: "{{url_for('admin.UploadRPCserver')}}",
data:{action:'delete_mode',isdelete:'False'},
dataType: "json",
success: function(data) {
ShowNotice(data.msg);
layer.close(index2);
}
});
}
});
function ClearHist(){
layer.confirm('确定清除任务?', {
btn: ['确定','取消'] //按钮
},
function(index){
layer.close(index);
var index2 = layer.load(2, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
$.ajax({
type: "POST",
url: "{{url_for('admin.UploadRPCserver')}}",
data:{action:'ClearHist'},
dataType: "json",
beforeSend: function(xhr) {
var index2 = layer.load(2, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
},
success: function(data) {
ShowNotice(data.msg);
},
complete: function(xhr) {
$('#layui-layer-shade1').remove();
setTimeout("window.location.reload();",2000);
layer.close(index2);
}
});
}
@ -96,22 +132,17 @@ function Restart(){
},
function(index){
layer.close(index);
var index2 = layer.load(2, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
$.ajax({
type: "POST",
url: "{{url_for('admin.UploadRPCserver')}}",
data:{action:'Restart'},
dataType: "json",
beforeSend: function(xhr) {
var index2 = layer.load(2, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
},
success: function(data) {
ShowNotice(data.msg);
},
complete: function(xhr) {
$('#layui-layer-shade1').remove();
setTimeout("window.location.reload();",2000);
layer.close(index2);
}
});
}

@ -41,7 +41,6 @@ def StartUploadQueue():
})
queue=Queue()
for t in waiting_tasks:
print(t['localpath'])
queue.put((t['localpath'],t['remote'],t['user'],t['id']))
tasks=[]
for i in range(min(5,queue.qsize())):
@ -112,7 +111,8 @@ class MultiUploadQueue(Thread):
new_value['speed']=data.get('speed')
mon_db.upload_queue.find_one_and_update({'id':id},{'$set':new_value})
time.sleep(2)
os.remove(localpath)
if GetConfig('delete_after_upload')=='True':
os.remove(localpath)
break
mon_db.upload_queue.find_one_and_update({'id':id},{'$set':new_value})
except Exception as e:

@ -14,7 +14,7 @@ class config:
if REDIS_PASSWORD!='':
CACHE_REDIS_PASSWORD=REDIS_PASSWORD
SEND_FILE_MAX_AGE_DEFAULT=timedelta(seconds=1)
version='4.190726'
version='4.190729'
@staticmethod
def init_app(app):

@ -117,5 +117,5 @@ show_audio="ogg,mp3,wav,aac,flac,m4a"
show_code="html,htm,php,py,css,go,java,js,json,txt,sh,md"
show_redirect="exe"
#上传服务器文件完成之后是否删除文件
delete_after_upload="True"

@ -150,13 +150,19 @@ Disallow: /
echo 'show_doc="csv,doc,docx,odp,ods,odt,pot,potm,potx,pps,ppsx,ppsxm,ppt,pptm,pptx,rtf,xls,xlsx"' >> self_config.py
fi
value=`cat /root/.aria2/aria2.conf | grep "rpc-secret=" | sed -e 's/\(.*\)=\(.*\)/\2/g'`
if [[ $value == "" ]]; then
secret=`cat self_config.py | grep "ARIA2_SECRET=" | sed -e 's/\(.*\)=\"\(.*\)\"/\2/g'`
sed -i "s/rpc-secret=/rpc-secret=${secret}/g" /root/.aria2/aria2.conf
fi
num=`cat self_config.py | grep "delete_after_upload" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'delete_after_upload="False"' >> self_config.py
fi
}
@ -252,6 +258,7 @@ echo "2019.06.13更新版本:新增功能:文件展示设置"
echo "2019.06.14更新版本:稍微完善一下日志记录;分享页面取消token验证;修复开启下载验证之后,后台文件打开失败的bug;新增内嵌窗口"
echo "2019.07.24更新版本:1. 优化安装脚本,适应Centos7、Debian9+、Ubuntu16+等系统;2、优化安装流程"
echo "2019.07.26更新版本:修复若干bug"
echo "2019.07.29更新版本:1. 修复上传文件bug;2. 添加自定义选项"
echo "---------------------------------------------------------------"
echo "更新完成!"
echo "如果网站无法访问,请检查config.py!"

Loading…
Cancel
Save