提交 e16b6518 编写于 作者: H hjdhnx

增加了自定义配置并升级版本

上级 72a2acd3
# 这是一个自定义的额外用户爬虫配置
# 自动附加到config/mode 对应的在线源里
# 可以使用Python的 # 单行注释
{
"sites":[
{
"key":"t4",
"name":"T4",
"type":4,
"api":"https://t4.secan.icu/vod?sites=all&ali_token=xxxxxxxxx&timeout=10",
# "api":"http://[ip]:[port]/vod?sites=all&ali_token=3xx9cfxxxx509bxx&timeout=5",
"searchable":1,
"quickSearch":1,
"filterable":0
}
]
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ from flask import Blueprint,abort,render_template,url_for,redirect,make_response
from controllers.service import storage_service
from controllers.classes import getClasses,getClassInfo
from utils.web import getParmas
from utils.files import getPics
from utils.files import getPics,custom_merge
from js.rules import getRules
from base.R import R
from utils.system import cfg,getHost,is_linux
......@@ -18,6 +18,7 @@ from utils import parser
from utils.log import logger
from utils.files import getAlist,get_live_url
from utils.update import getLocalVer
from utils.encode import parseText
from js.rules import getJxs
import random
......@@ -125,6 +126,17 @@ def get_liveslib():
@home.route('/config/<int:mode>')
def config_render(mode):
# print(dict(app.config))
customFile = 'base/custom.conf'
if not os.path.exists(customFile):
with open(customFile,'w+',encoding='utf-8') as f:
f.write('{}')
customConfig = False
try:
with open(customFile,'r',encoding='utf-8') as f:
customConfig = parseText(f.read())
except Exception as e:
logger.info(f'用户自定义配置加载失败:{e}')
if mode == 1:
jyw_ip = getHost(mode)
logger.info(jyw_ip)
......@@ -136,7 +148,11 @@ def config_render(mode):
live_url = get_live_url(new_conf,mode)
# html = render_template('config.txt',rules=getRules('js'),host=host,mode=mode,jxs=jxs,base64Encode=base64Encode,config=new_conf)
html = render_template('config.txt',rules=getRules('js'),host=host,mode=mode,jxs=jxs,alists=alists,alists_str=alists_str,live_url=live_url,config=new_conf)
response = make_response(html)
merged_config = custom_merge(parseText(html),customConfig)
# print(merged_config)
# response = make_response(html)
response = make_response(json.dumps(merged_config,ensure_ascii=False,indent=1))
# response = make_response(str(merged_config))
response.headers['Content-Type'] = 'application/json; charset=utf-8'
return response
......
3.2.8
\ No newline at end of file
3.2.9
\ No newline at end of file
......@@ -46,6 +46,8 @@
[dockerfile教程](https://blog.csdn.net/qq_46158060/article/details/125718218)
[获取本地设备信息](https://blog.csdn.net/cui_yonghua/article/details/125508991)
[获取本地设备信息](https://m.jb51.net/article/140716.htm)
###### 2022/09/08
- [X] 1.升级到3.2.9,支持自动合并自定义用户配置(内置t4测试源)
###### 2022/09/07
- [X] 1.优化后台管理登录界面,升级更新脚本
- [X] 2.增加了镜像合并脚本(三合一直接拉 hjdhnx/drpy 即可)
......
......@@ -17,6 +17,7 @@ import requests.utils
from time import sleep
import os
from utils.web import UC_UA,PC_UA
from ast import literal_eval
def getPreJs():
base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目
......@@ -222,4 +223,8 @@ def buildUrl(url,obj=None):
url += '&'
url = (url + prs).replace('"','').replace("'",'')
# print(url)
return url
\ No newline at end of file
return url
def parseText(text:str):
text = text.replace('false','False').replace('true','True').replace('null','None')
return literal_eval(text)
\ No newline at end of file
......@@ -51,4 +51,29 @@ def getAlist():
})
alists.append(obj)
print(f'共计{len(alists)}条alist记录')
return alists
\ No newline at end of file
return alists
def custom_merge(original:dict,custom:dict):
"""
合并用户配置
:param original: 原始配置
:param custom: 自定义配置
:return:
"""
if not custom or len(custom.keys()) < 1:
return original
new_keys = custom.keys()
updateObj = {}
extend_obj = {}
for key in ['wallpaper','spider','homepage']:
if key in new_keys:
updateObj[key] = custom[key]
for key in ['drives','sites','flags','lives','ads']:
if key in new_keys:
extend_obj[key] = custom[key]
original.update(updateObj)
for key in extend_obj.keys():
original[key].extend(extend_obj[key])
return original
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册