Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
iqingyuan
dr_py
提交
5968b75c
dr_py
项目概览
iqingyuan
/
dr_py
与 Fork 源项目一致
Fork自
晚风拂柳颜 / dr_py
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
dr_py
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5968b75c
编写于
9月 06, 2022
作者:
H
hjdhnx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加了检测升级
上级
bd0d96eb
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
127 addition
and
5 deletion
+127
-5
app.py
app.py
+26
-1
js/version.txt
js/version.txt
+1
-1
templates/admin.html
templates/admin.html
+44
-1
utils/update.py
utils/update.py
+56
-2
未找到文件。
app.py
浏览文件 @
5968b75c
...
...
@@ -18,6 +18,7 @@ from werkzeug.utils import secure_filename
from
js.rules
import
getRuleLists
from
utils
import
error
,
parser
from
utils.web
import
*
from
utils.update
import
checkUpdate
,
getOnlineVer
,
getLocalVer
,
download_new_version
import
sys
import
codecs
from
classes.cms
import
CMS
,
logger
...
...
@@ -115,7 +116,7 @@ def admin_home(): # 管理员界面
if
not
verfy_token
(
token
):
return
render_template
(
'login.html'
)
# return jsonify(error.success('登录成功'))
return
render_template
(
'admin.html'
,
rules
=
getRules
(
'js'
))
return
render_template
(
'admin.html'
,
rules
=
getRules
(
'js'
)
,
ver
=
getLocalVer
()
)
@
app
.
route
(
'/api/login'
,
methods
=
[
'GET'
,
'POST'
])
def
login_api
():
...
...
@@ -160,6 +161,30 @@ def admin_clear_rule(name):
os
.
remove
(
file_path
)
return
jsonify
(
error
.
success
(
'成功删除文件:'
+
file_path
))
@
app
.
route
(
'/admin/get_ver'
)
def
admin_get_ver
():
cookies
=
request
.
cookies
# print(cookies)
token
=
cookies
.
get
(
'token'
,
''
)
# print(f'mytoken:{token}')
if
not
verfy_token
(
token
):
# return render_template('login.html')
return
jsonify
(
error
.
failed
(
'请登录后再试'
))
return
jsonify
({
'local_ver'
:
getLocalVer
(),
'online_ver'
:
getOnlineVer
()})
@
app
.
route
(
'/admin/update_ver'
)
def
admin_update_ver
():
cookies
=
request
.
cookies
# print(cookies)
token
=
cookies
.
get
(
'token'
,
''
)
# print(f'mytoken:{token}')
if
not
verfy_token
(
token
):
# return render_template('login.html')
return
jsonify
(
error
.
failed
(
'请登录后再试'
))
msg
=
download_new_version
()
return
jsonify
(
error
.
success
(
msg
))
@
app
.
route
(
'/upload'
,
methods
=
[
'GET'
,
'POST'
])
def
upload_file
():
cookies
=
request
.
cookies
...
...
js/version.txt
浏览文件 @
5968b75c
3.1.3
\ No newline at end of file
3.1.2
\ No newline at end of file
templates/admin.html
浏览文件 @
5968b75c
...
...
@@ -63,6 +63,17 @@
/*li a {*/
/* display: block !important;*/
/*}*/
.ver_title
{
font-size
:
15px
;
margin-left
:
20px
}
.ver
{
font-size
:
16px
;
margin-left
:
5px
;
color
:
#ea7d7d
;
}
a
.funcbtn
{
margin-left
:
10px
;
}
</style>
<body>
<script>
...
...
@@ -79,6 +90,34 @@
location
.
href
=
'
/vod?rule=
'
+
rule
;
});
$
(
"
#checkUpdate
"
).
click
(
function
(){
console
.
log
(
'
开始检查升级...
'
);
$
.
get
(
"
/admin/get_ver
"
,
function
(
data
,
status
){
console
.
log
(
"
数据:
"
+
data
+
"
\n
状态:
"
+
status
);
if
(
data
.
msg
){
alert
(
data
.
msg
);
return
false
}
else
{
if
(
data
.
local_ver
&&
data
.
online_ver
){
if
(
data
.
local_ver
!==
data
.
online_ver
){
msg
=
`本地版本:
${
data
.
local_ver
}
\n线上版本:
${
data
.
online_ver
}
\n是否立即执行升级?`
;
if
(
confirm
(
msg
)){
$
.
get
(
"
/admin/update_ver
"
,
function
(
data
,
status
){
console
.
log
(
data
);
alert
(
data
.
msg
||
'
未知数据,具体到数据控制台查看
'
);
return
false
});
}
}
else
{
alert
(
'
已经是最新版,无需升级!
'
)
}
}
else
{
alert
(
'
已经是最新版,无需升级!
'
)
}
}
});
});
$
(
"
.clear
"
).
click
(
function
(){
// location.reload();
// let rule = this.innerText.trim();
...
...
@@ -138,7 +177,11 @@
}
</script>
<h2
class=
"title"
>
欢迎使用drpy管理员界面
</h2><h4><a
href=
"/index"
>
返回首页
</a></h4>
<h2
class=
"title"
>
欢迎使用drpy管理员界面
<span
class=
"ver_title"
>
当前版本:
</span><span
class=
"ver"
>
{{ ver }}
</span></h2>
<h4>
<a
href=
"/index"
class=
"funcbtn"
>
返回首页
</a>
<a
href=
"javascript:void(0);"
class=
"funcbtn"
id=
"checkUpdate"
>
检测升级
</a>
</h4>
<p>
你可以在此页面在线上传规则文件到js目录或者删除js目录的文件
</p>
<form
action =
"/upload"
method =
"POST"
enctype =
"multipart/form-data"
>
<!-- <input type = "file" name = "file" class="btn" accept=".js" onchange="getFileSize(this)"/>-->
...
...
utils/update.py
浏览文件 @
5968b75c
...
...
@@ -6,6 +6,7 @@
import
requests
import
os
import
zipfile
def
getLocalVer
():
base_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
)))
# 上级目录
...
...
@@ -22,8 +23,61 @@ def getLocalVer():
def
getOnlineVer
():
ver
=
'1.0.1'
try
:
r
=
requests
.
get
(
''
,
timeout
=
(
2
,
2
))
r
=
requests
.
get
(
'
https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/version.txt
'
,
timeout
=
(
2
,
2
))
ver
=
r
.
text
except
Exception
as
e
:
print
(
f
'
{
e
}
'
)
return
ver
def
checkUpdate
():
local_ver
=
getLocalVer
()
online_ver
=
getOnlineVer
()
if
local_ver
!=
online_ver
:
return
True
return
False
def
del_file
(
filepath
):
"""
删除execl目录下的所有文件或文件夹
:param filepath: 路径
:return:
"""
del_list
=
os
.
listdir
(
filepath
)
for
f
in
del_list
:
file_path
=
os
.
path
.
join
(
filepath
,
f
)
if
os
.
path
.
isfile
(
file_path
):
os
.
remove
(
file_path
)
def
download_new_version
():
base_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
)))
# 上级目录
tmp_path
=
os
.
path
.
join
(
base_path
,
f
'tmp'
)
os
.
makedirs
(
tmp_path
,
exist_ok
=
True
)
url
=
'https://gitcode.net/qq_32394351/dr_py/-/archive/master/dr_py-master.zip'
# tmp_files = os.listdir(tmp_path)
# for tp in tmp_files:
# print(f'清除缓存文件:{tp}')
# os.remove(os.path.join(tmp_path, tp))
del_file
(
tmp_path
)
headers
=
{
'Referer'
:
'https://gitcode.net/'
,
'user-agent'
:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36'
,
}
msg
=
''
try
:
print
(
f
'开始下载:
{
url
}
'
)
r
=
requests
.
get
(
url
,
headers
=
headers
,
timeout
=
(
20
,
20
))
rb
=
r
.
content
download_path
=
os
.
path
.
join
(
tmp_path
,
'dr_py.zip'
)
with
open
(
download_path
,
mode
=
'wb+'
)
as
f
:
f
.
write
(
rb
)
print
(
f
'开始解压文件:
{
download_path
}
'
)
f
=
zipfile
.
ZipFile
(
download_path
,
'r'
)
# 压缩文件位置
for
file
in
f
.
namelist
():
f
.
extract
(
file
,
tmp_path
)
# 解压位置
f
.
close
()
print
(
'解压完毕'
)
msg
=
'下载成功'
except
Exception
as
e
:
msg
=
f
'下载失败:
{
e
}
'
return
msg
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录