新增文件展示功能

master
Abbey 5 years ago
parent 1b4bff6d23
commit 5edae6f469
  1. 39
      app/admin/setting.py
  2. 20
      app/front/views.py
  3. 4
      app/templates/admin/layout.html
  4. 58
      app/templates/admin/setting/show_setting.html
  5. 37
      app/utils/common.py
  6. 6
      app/utils/header.py
  7. 2
      config.py
  8. 7
      install.sh
  9. 11
      self_config.py.sample
  10. 90
      update.sh

@ -150,3 +150,42 @@ def setCode():
return resp
resp=MakeResponse(render_template('admin/setCode/setCode.html'))
return resp
@admin.route('/show_setting',methods=['GET','POST'])
def show_setting():
if request.method=='POST':
show_redirect=request.form.get('show_redirect')
set('show_redirect',show_redirect)
redis_client.set('show_redirect',show_redirect)
show_doc=request.form.get('show_doc')
set('show_doc',show_doc)
redis_client.set('show_doc',show_doc)
show_image=request.form.get('show_image')
set('show_image',show_image)
redis_client.set('show_image',show_image)
show_video=request.form.get('show_video')
set('show_video',show_video)
redis_client.set('show_video',show_video)
show_dash=request.form.get('show_dash')
set('show_dash',show_dash)
redis_client.set('show_dash',show_dash)
show_audio=request.form.get('show_audio')
set('show_audio',show_audio)
redis_client.set('show_audio',show_audio)
show_code=request.form.get('show_code')
set('show_code',show_code)
redis_client.set('show_code',show_code)
flash('更新成功')
resp=MakeResponse(redirect(url_for('admin.show_setting')))
return resp
resp=MakeResponse(render_template('admin/setting/show_setting.html'))
return resp

@ -152,19 +152,22 @@ def show(fileid,user,action='download',token=None):
return abort(403)
if request.method=='POST' or action=='share':
InfoLogger().print_r(u'share page:{}'.format(path))
if ext in ['csv','doc','docx','odp','ods','odt','pot','potm','potx','pps','ppsx','ppsxm','ppt','pptm','pptx','rtf','xls','xlsx']:
if ext in GetConfig('show_redirect').split(','):
downloadUrl,play_url=GetDownloadUrl(fileid,user)
resp=MakeResponse(redirect(downloadUrl))
elif ext in GetConfig('show_doc').split(','):
downloadUrl,play_url=GetDownloadUrl(fileid,user)
url = 'https://view.officeapps.live.com/op/view.aspx?src='+urllib.quote(downloadUrl)
resp=MakeResponse(redirect(url))
elif ext in ['bmp','jpg','jpeg','png','gif']:
elif ext in GetConfig('show_image').split(','):
resp=MakeResponse(render_template('theme/{}/show/image.html'.format(GetConfig('theme')),url=url,inner_url=inner_url,path=path,cur_user=user,name=name))
elif ext in ['mp4','webm']:
elif ext in GetConfig('show_video').split(','):
resp=MakeResponse(render_template('theme/{}/show/video.html'.format(GetConfig('theme')),url=url,inner_url=inner_url,path=path,cur_user=user,name=name))
elif ext in ['avi','mpg', 'mpeg', 'rm', 'rmvb', 'mov', 'wmv', 'mkv', 'asf']:
elif ext in GetConfig('show_dash').split(','):
resp=MakeResponse(render_template('theme/{}/show/video2.html'.format(GetConfig('theme')),url=url,inner_url=inner_url,path=path,cur_user=user,name=name))
elif ext in ['ogg','mp3','wav']:
elif ext in GetConfig('show_audio').split(','):
resp=MakeResponse(render_template('theme/{}/show/audio.html'.format(GetConfig('theme')),url=url,inner_url=inner_url,path=path,cur_user=user,name=name))
elif CodeType(ext) is not None:
elif ext in GetConfig('show_code').split(','):
content=common._remote_content(fileid,user)
resp=MakeResponse(render_template('theme/{}/show/code.html'.format(GetConfig('theme')),content=content,url=url,inner_url=inner_url,language=CodeType(ext),path=path,cur_user=user,name=name))
elif name=='.password':
@ -180,11 +183,6 @@ def show(fileid,user,action='download',token=None):
downloadUrl,play_url=GetDownloadUrl(fileid,user)
if not downloadUrl.startswith('http'):
return MakeResponse(downloadUrl)
# if ext in ['webm','avi','mpg', 'mpeg', 'rm', 'rmvb', 'mov', 'wmv', 'mkv', 'asf']:
# if action=='play':
# resp=MakeResponse(redirect(play_url))
# else:
# resp=MakeResponse(redirect(downloadUrl))
else:
resp=MakeResponse(redirect(play_url))
else:

@ -145,6 +145,10 @@
<i class="mdui-list-item-icon mdui-icon material-icons">&#xe62a;</i>
<div class="mdui-list-item-content">系统设置</div>
</a>
<a href="{{url_for('admin.show_setting')}}" class="mdui-list-item">
<i class="mdui-list-item-icon mdui-icon material-icons">&#xe30a;</i>
<div class="mdui-list-item-content">文件展示</div>
</a>
<a href="{{url_for('admin.setCode')}}" class="mdui-list-item">
<i class="mdui-list-item-icon mdui-icon material-icons">&#xe8b8;</i>
<div class="mdui-list-item-content">自定义代码</div>

@ -0,0 +1,58 @@
{%extends 'admin/layout.html'%}
{%block content%}
<div class="mdui-container-fluid">
<div class="mdui-typo">
<h1> 展示设置 </h1>
<small>
<p>1. 可用于某些后缀的文件用那种窗口展示<font color="red">没设置的后缀直接下载</font></p>
<p>2. <font color="red">下方设置的顺序决定了文件展示的优先级</font>比如mp4格式在直接下载视频两类都出现了但是直接下载优先级更高因此mp4文件将直接下载</p>
<p>3. 后缀通过英文逗号(,)分隔无需加点(.)</p>
</small>
</div>
<form action="{{url_for('admin.show_setting')}}" method="POST">
<div class="mdui-textfield">
<h4>直接下载</h4>
<input class="mdui-textfield-input" type="text" name="show_redirect" value="{{GetConfig('show_redirect')}}"/>
</div>
<div class="mdui-textfield">
<h4>office文档</h4>
<input class="mdui-textfield-input" type="text" name="show_doc" value="{{GetConfig('show_doc')}}"/>
</div>
<div class="mdui-textfield">
<h4>图片</h4>
<input class="mdui-textfield-input" type="text" name="show_image" value="{{GetConfig('show_image')}}"/>
</div>
<div class="mdui-textfield">
<h4>视频</h4>
<input class="mdui-textfield-input" type="text" name="show_video" value="{{GetConfig('show_video')}}"/>
</div>
<div class="mdui-textfield">
<h4>dash视频</h4>
<input class="mdui-textfield-input" type="text" name="show_dash" value="{{GetConfig('show_dash')}}"/>
</div>
<div class="mdui-textfield">
<h4>音频</h4>
<input class="mdui-textfield-input" type="text" name="show_audio" value="{{GetConfig('show_audio')}}"/>
</div>
<div class="mdui-textfield">
<h4>代码</h4>
<input class="mdui-textfield-input" type="text" name="show_code" value="{{GetConfig('show_code')}}"/>
</div>
<button type="submit" class="mdui-btn mdui-color-theme-accent mdui-ripple mdui-float-right">
<i class="mdui-icon material-icons">&#xe161;</i> 保存
</button>
</form>
</div>
{%endblock content%}

@ -266,19 +266,22 @@ def CanEdit(filename):
def CodeType(ext):
code_type={}
code_type['html'] = 'html';
code_type['htm'] = 'html';
code_type['php'] = 'php';
code_type['py'] = 'python';
code_type['css'] = 'css';
code_type['go'] = 'golang';
code_type['java'] = 'java';
code_type['js'] = 'javascript';
code_type['json'] = 'json';
code_type['txt'] = 'Text';
code_type['sh'] = 'sh';
code_type['md'] = 'Markdown';
return code_type.get(ext.lower())
code_type['html'] = 'html'
code_type['htm'] = 'html'
code_type['php'] = 'php'
code_type['py'] = 'python'
code_type['css'] = 'css'
code_type['go'] = 'golang'
code_type['java'] = 'java'
code_type['js'] = 'javascript'
code_type['json'] = 'json'
code_type['txt'] = 'Text'
code_type['sh'] = 'sh'
code_type['md'] = 'Markdown'
if code_type.get(ext.lower()):
return code_type.get(ext.lower())
else:
return ext
def file_ico(item):
try:
@ -454,13 +457,7 @@ def get_od_user(admin=False):
config_path=os.path.join(config_dir,'self_config.py')
with open(config_path,'r') as f:
text=f.read()
key='users'
if redis_client.exists(key):
users=json.loads(redis_client.get(key))
else:
value=re.findall('od_users=([\w\W]*})',text)[0]
users=json.loads(value)
redis_client.set(key,value)
users=GetConfig('od_users')
ret=[]
for user,value in users.items():
if value.get('client_id')!='':

@ -69,12 +69,12 @@ def GetConfig(key):
else:
value=redis_client.get(key) if redis_client.exists(key) else eval(key)
#这里是为了储存
if key=='od_users' and isinstance(value,dict):
if key in ['od_users','show_dict'] and isinstance(value,dict):
value=json.dumps(value)
if not redis_client.exists(key):
redis_client.set(key,value)
#这里是为了转为字典
if key=='od_users':
if key in ['od_users','show_dict']:
value=json.loads(value)
return value
@ -396,7 +396,7 @@ class GetItemThread(Thread):
super(GetItemThread,self).__init__()
self.queue=queue
self.user=user
share_path=od_users.get(user).get('share_path')
share_path=GetConfig('od_users').get(user).get('share_path')
if share_path=='/':
self.share_path=share_path
else:

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

@ -6,7 +6,7 @@ function wget_exists(){
echo "wget exist"
else
echo "wget dose not exist"
yum install wget
yum install wget -y
fi
}
@ -17,7 +17,7 @@ function git_exists(){
echo "git exist"
else
echo "git dose not exist"
yum install git
yum install git -y
fi
}
#安装pip
@ -112,7 +112,8 @@ config_file
auto_boot
install_aria2
open_port
yum install lsof
yum install gcc libffi-devel python-devel openssl-devel -y
yum install lsof -y
mkdir logs
echo "---------------------------------------------------------------"
echo "一键脚本运行完成!请检查以下文件:"

@ -108,3 +108,14 @@ od_users={
}
show_doc="csv,doc,docx,odp,ods,odt,pot,potm,potx,pps,ppsx,ppsxm,ppt,pptm,pptx,rtf,xls,xlsx"
show_image="bmp,jpg,jpeg,png,gif"
show_video="mp4,webm"
show_dash="avi,mpg,mpeg,rm,rmvb,mov,wmv,mkv,asf"
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"

@ -15,109 +15,79 @@ update_sp(){
#2019.01.18
update_config(){
num=`cat self_config.py | grep "MONGO_HOST" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'MONGO_HOST="localhost"' >> self_config.py
fi
num=`cat self_config.py | grep "MONGO_PORT" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'MONGO_PORT="27017"' >> self_config.py
fi
num=`cat self_config.py | grep "MONGO_USER" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'MONGO_USER=""' >> self_config.py
fi
num=`cat self_config.py | grep "MONGO_PASSWORD" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'MONGO_PASSWORD=""' >> self_config.py
fi
num=`cat self_config.py | grep "MONGO_DB" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'MONGO_DB="three"' >> self_config.py
fi
num=`cat self_config.py | grep "REDIS_HOST" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'REDIS_HOST="localhost"' >> self_config.py
fi
num=`cat self_config.py | grep "REDIS_PORT" | wc -l`
num=`cat self_config.py | grep "balance" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'REDIS_PORT="6379"' >> self_config.py
echo 'balance="False"' >> self_config.py
fi
num=`cat self_config.py | grep "REDIS_PASSWORD" | wc -l`
num=`cat self_config.py | grep "robots" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'REDIS_PASSWORD=""' >> self_config.py
echo 'robots="""
User-agent: *
Disallow: /
"""' >> self_config.py
fi
num=`cat self_config.py | grep "REDIS_DB" | wc -l`
num=`cat self_config.py | grep "admin_prefix" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'REDIS_DB="0"' >> self_config.py
echo 'admin_prefix="admin"' >> self_config.py
fi
num=`cat self_config.py | grep "default_sort" | wc -l`
num=`cat self_config.py | grep "thread_num" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'default_sort="lastModtime"' >> self_config.py
echo 'thread_num="5"' >> self_config.py
fi
num=`cat self_config.py | grep "order_m" | wc -l`
num=`cat self_config.py | grep "verify_url" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'order_m="desc"' >> self_config.py
echo 'verify_url="False"' >> self_config.py
fi
num=`cat self_config.py | grep "default_pan" | wc -l`
num=`cat self_config.py | grep "show_redirect" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'default_pan="A"' >> self_config.py
echo 'show_redirect="exe"' >> self_config.py
fi
num=`cat self_config.py | grep "balance" | wc -l`
num=`cat self_config.py | grep "show_image" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'balance="False"' >> self_config.py
echo 'show_image="bmp,jpg,jpeg,png,gif"' >> self_config.py
fi
num=`cat self_config.py | grep "robots" | wc -l`
num=`cat self_config.py | grep "show_video" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'robots="""
User-agent: *
Disallow: /
"""' >> self_config.py
echo 'show_video="mp4,webm"' >> self_config.py
fi
num=`cat self_config.py | grep "admin_prefix" | wc -l`
num=`cat self_config.py | grep "show_dash" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'admin_prefix="admin"' >> self_config.py
echo 'show_dash="avi,mpg,mpeg,rm,rmvb,mov,wmv,mkv,asf"' >> self_config.py
fi
num=`cat self_config.py | grep "thread_num" | wc -l`
num=`cat self_config.py | grep "show_audio" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'thread_num="5"' >> self_config.py
echo 'show_audio="ogg,mp3,wav,aac,flac,m4a"' >> self_config.py
fi
num=`cat self_config.py | grep "verify_url" | wc -l`
num=`cat self_config.py | grep "show_code" | wc -l`
if [ $num == 0 ]; then
echo '' >> self_config.py
echo 'verify_url="False"' >> self_config.py
echo 'show_code="html,htm,php,py,css,go,java,js,json,txt,sh,md"' >> self_config.py
fi
}
@ -137,13 +107,14 @@ upgrade(){
touch .install
fi
update_config
yum install gcc libffi-devel python-devel openssl-devel -y
pip install -r requirements.txt
which lsof > /dev/null 2>&1
if [ $? == 0 ]; then
echo "lsof exist"
else
echo "lsof dose not exist"
yum install lsof
yum install lsof -y
fi
}
@ -202,6 +173,7 @@ echo "2019.05.25更新版本:参考olaindex,视频和音频出错自动加
echo "2019.05.28更新版本:修复开启负债均衡之后,文件名有特殊符号播放不了的bug"
echo "2019.05.29更新版本:支持自定义线程数"
echo "2019.05.31更新版本:新增功能:1)下载链接验证开关;优化:1)aria2信息不对时,无法添加任务"
echo "2019.06.13更新版本:新增功能:文件展示设置"
echo "---------------------------------------------------------------"
echo "更新完成!"
echo "如果网站无法访问,请检查config.py!"

Loading…
Cancel
Save