Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
增加手动升级功能
Browse files Browse the repository at this point in the history
  • Loading branch information
hjdhnx committed Nov 18, 2023
1 parent 2ea87cd commit da1ecba
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .idea/dr_py.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
JS0_DISABLE = 0 # 禁用js0
JS0_PASSWORD = '' # js0密码
JS_MODE = 0 # js模式 0 drpy服务器解析 1 pluto本地解析
MAX_CONTENT_LENGTH = 1 * 1024 * 100 # 100 kB
# MAX_CONTENT_LENGTH = 1 * 1024 * 100 # 100 kB
MAX_CONTENT_LENGTH = 50 * 1024 * 1024 # 50mb
JS_MAX_LENGTH = 0.1 * 1024 * 1024 # 0.1mb
LIVE_MODE = 0 # 0 本地 1外网
# LIVE_URL = 'https://gitcode.net/bd/v/-/raw/main/live/zb.txt' # 初始化外网直播地址(后续在管理界面改)
# LIVE_URL = 'https://agit.ai/hu/hcr/raw/commit/f8e9c10309a533e5b06df133f859c45cb91f4731/0ER.txt' # 月光直播接口
Expand Down
56 changes: 54 additions & 2 deletions controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import os

import ujson
from flask import Blueprint, request, render_template, render_template_string, jsonify, make_response, redirect
from flask import Blueprint, abort, request, render_template, render_template_string, jsonify, make_response, redirect
from controllers.service import storage_service, rules_service, parse_service
from base.R import R
from base.database import db
from utils.log import logger
import shutil
from utils.update import getLocalVer, getOnlineVer, download_new_version, download_lives, copy_to_update
from utils.update import zipfile, getLocalVer, getOnlineVer, download_new_version, download_lives, copy_to_update
from utils import parser
from utils.env import get_env, update_env
from utils.web import getParmas, verfy_token
Expand Down Expand Up @@ -365,6 +365,7 @@ def admin_change_use_py():
msg = f'已修改的配置记录id为:{id},结果为{state}'
return R.success(msg)


@admin.route('/clear_drop')
def admin_clear_drop():
if not verfy_token():
Expand All @@ -385,6 +386,7 @@ def admin_clear_drop():
msg = f'清理完毕,本次共计清理{len(rm_list)}\n {rm_str}'
return R.success(msg)


# @admin.route('/get_use_py')
# def admin_get_use_py():
# if not verfy_token():
Expand All @@ -394,6 +396,23 @@ def admin_clear_drop():
# state = 1 if use_py else 0
# return R.success(state)

def get_size(fobj):
if fobj.content_length:
return fobj.content_length

try:
pos = fobj.tell()
fobj.seek(0, 2) # seek to end
size = fobj.tell()
fobj.seek(pos) # back to original position
return size
except (AttributeError, IOError):
pass

# in-memory file object that doesn't support seeking or tell
return 0


@admin.route('/upload', methods=['POST'])
def upload_file():
args = request.args
Expand All @@ -403,6 +422,12 @@ def upload_file():
if request.method == 'POST':
try:
file = request.files['file']
lsg = storage_service()
js_max_len = lsg.getItem('JS_MAX_LENGTH', 0.1 * 1024 * 1024)
if get_size(file) > float(js_max_len):
logger.info(f'文件体积过大,禁止上传。当前体积:{get_size(file)},源体积限制:{js_max_len}')
abort(413) # request entity too large

filename = secure_filename(file.filename)
logger.info(f'推荐安全文件命名:{filename}')
savePath = f'js/{file.filename}'
Expand Down Expand Up @@ -447,6 +472,33 @@ def upload_file():
return R.failed('文件上传失败')


@admin.route('/upload_update', methods=['POST'])
def upload_update():
args = request.args
force = args.get('force')
print('force:', force)
if not verfy_token():
return render_template('login.html')
if request.method == 'POST':
try:
file = request.files['file']
filename = secure_filename(file.filename)
logger.info(f'推荐安全文件命名:{filename}')
savePath = f'tmp/dr_py.zip'
file.seek(0) # 读取后变成空文件,重新赋能
file.save(savePath)
logger.info(f'开始解压文件:{savePath}')
f = zipfile.ZipFile(savePath, 'r') # 压缩文件位置
for file in f.namelist():
f.extract(file, 'tmp') # 解压位置
f.close()
# print('解压完毕,开始升级')
logger.info('解压完毕,开始升级')
# ret = copy_to_update()
return R.success('升级文件上传成功,请确认drpy目录内是否存在/tmp/dr_py-main/文件夹,如果ok你可以点击强制升级按钮升级刚才上传的文件')
except Exception as e:
return R.failed(f'升级文件上传失败!{e}')

@admin.route('/login', methods=['GET', 'POST'])
def login_api():
username = getParmas('username')
Expand Down
7 changes: 4 additions & 3 deletions controllers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self):
'LAZYPARSE_MODE', 'WALL_PAPER_ENABLE',
'WALL_PAPER', 'UNAME', 'PWD', 'LIVE_MODE', 'CATE_EXCLUDE', 'TAB_EXCLUDE', 'SEARCH_TIMEOUT',
'SEARCH_LIMIT', 'MULTI_MODE', 'XR_MODE', 'JS_PROXY', 'UPDATE_PROXY', 'ENV', 'ALI_TOKEN', 'OCR_API',
'SPECIAL','SPIDER_JAR', 'EXT_FUNC']
'SPECIAL', 'SPIDER_JAR', 'EXT_FUNC', 'JS_MAX_LENGTH']
for conf in conf_list:
if not self.hasItem(conf):
print(f'开始初始化{conf}')
Expand All @@ -38,11 +38,12 @@ def getStoreConf(self):
conf_list = ['LIVE_URL', 'LIVE_MODE', 'PLAY_URL', 'PID_URL', 'USE_PY', 'JS_MODE', 'JS0_DISABLE', 'JS0_PASSWORD',
'PLAY_DISABLE', 'LAZYPARSE_MODE', 'WALL_PAPER_ENABLE',
'WALL_PAPER', 'UNAME', 'PWD', 'CATE_EXCLUDE', 'TAB_EXCLUDE', 'SEARCH_TIMEOUT', 'SEARCH_LIMIT',
'MULTI_MODE', 'XR_MODE', 'JS_PROXY', 'UPDATE_PROXY', 'ENV', 'SPECIAL', 'SPIDER_JAR', 'EXT_FUNC', 'ALI_TOKEN', 'OCR_API']
'MULTI_MODE', 'XR_MODE', 'JS_PROXY', 'UPDATE_PROXY', 'ENV', 'SPECIAL', 'SPIDER_JAR',
'EXT_FUNC', 'JS_MAX_LENGTH', 'ALI_TOKEN', 'OCR_API']
conf_name_list = ['直播地址', '直播模式', '远程地址', '进程管理链接', '启用py源', 'js模式', '禁用js0',
'js0密码', '禁用免嗅', '免嗅模式', '启用壁纸', '壁纸链接', '管理账号',
'管理密码', '分类排除', '线路排除', '聚搜超时', '搜索条数', '多源模式', '仙人模式', '源代理',
'升级代理', '环境变量', '优选源', '挂载JAR', '辅助规则', '阿里tk', 'OCR接口']
'升级代理', '环境变量', '优选源', '挂载JAR', '辅助规则', '源体积', '阿里tk', 'OCR接口']
conf_lists = []
for i in range(len(conf_list)):
conf = conf_list[i]
Expand Down
4 changes: 4 additions & 0 deletions doc/更新日志.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
###### 2023/11/18
- [X] 修复腾云驾雾
- [X] 增加手动升级功能,手动上传升级文件.zip后进行强制升级即可

###### 2023/10/04
- [X] 关于rsa加解密的研究,js模块导入方式研究失败。请用蜜蜂壳子注入的函数实现
```js
Expand Down
2 changes: 1 addition & 1 deletion js/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.48beta23
3.9.48beta24
52 changes: 50 additions & 2 deletions templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,52 @@
}
});

$('#choose_update').click(function () {
$('#fileInput').click();
});

$('#fileInput').change(function () {
//获取选择的文件信息
let file = this.files[0];
//执行上传操作
if(file){
console.log(file);
if(file.name.includes('dr_py')||file.name.includes('drpy')){
if(confirm('已选择文件:'+file.name+',体积:'+(file.size/1024).toFixed(2)+'kb 进行手动升级,是否继续?')){
var name = file.name;
if (!name.endsWith('.zip')) {
alert('仅支持上传zip文件');
return false
}
let form_data = new FormData();
// 把所有表单信息
form_data.append("id", "001");
form_data.append("name", name);
form_data.append("file", file);
$.ajax({
type: "POST",
url: "/admin/upload_update?force=1",
dataType: "json",
processData: false, // 注意:让jQuery不要处理数据
contentType: false, // 注意:让jQuery不要设置contentType
data: form_data
}).success(function (ret) {
console.log(ret);
alert(ret.msg);
if(ret.msg && ret.msg.includes('文件上传成功')){
location.reload();
}
}).fail(function (ret) {
console.log(ret);
alert(ret.msg);
});
}
}else{
alert('你选择的文件:'+file.name+'看起来不像是drpy的升级文件压缩包。一般文件名长这样:dr_py-main.zip,请重新选择')
}
}
});

$('#use_py').click(function () {
$.get("/admin/change_use_py", function (data, status) {
console.log(data);
Expand Down Expand Up @@ -265,7 +311,7 @@

});
function getFileSize(fileObj) {
$('#file_size').text('文件大小为:' + fileObj.files[0].size / 1024 + 'kb');
$('#file_size').text('文件大小为:' + (fileObj.files[0].size / 1024).toFixed(2) + 'kb');
}
</script>
<div class="title">欢迎使用DR-PY管理界面<div><span class="ver_title">当前版本: {{ ver }}</span><span
Expand Down Expand Up @@ -301,6 +347,8 @@
<ul>
<li><a href="javascript:void(0);" class="funcbtn" id="checkUpdate">检测升级</a></li>
<li><a href="javascript:void(0);" class="funcbtn" id="force_update">强制升级</a></li>
<li><a href="javascript:void(0);" class="funcbtn" id="choose_update">手动升级</a></li>
<input type="file" id="fileInput" accept=".zip,.rar" style="display:none;">
</ul>
</li>

Expand All @@ -325,7 +373,7 @@

<form action="/admin/upload" method="POST" enctype="multipart/form-data">
<!-- <input type = "file" name = "file" class="btn" accept=".js" onchange="getFileSize(this)"/>-->
<input type="file" name="file" class="btn" onchange="getFileSize(this)" />
<input type="file" name="file" class="btn" onchange="getFileSize(this)" accept=".js,.jsd,.txt"/>
<!-- <input type = "submit" value="上传" class="btn"/>-->
<input type="button" id="upload" value="上传" class="btn" />
</form>
Expand Down

0 comments on commit da1ecba

Please sign in to comment.