Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
W登峰造极
dr_py
提交
0a1ad630
dr_py
项目概览
W登峰造极
/
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,体验更适合开发者的 AI 搜索 >>
提交
0a1ad630
编写于
11月 21, 2022
作者:
H
hjdhnx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化源代理逻辑
上级
ed9e9a1d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
74 addition
and
13 deletion
+74
-13
controllers/admin.py
controllers/admin.py
+22
-2
controllers/home.py
controllers/home.py
+10
-7
controllers/vod.py
controllers/vod.py
+6
-1
js/007影视.js
js/007影视.js
+1
-0
utils/env.py
utils/env.py
+20
-0
utils/parser.py
utils/parser.py
+15
-3
未找到文件。
controllers/admin.py
浏览文件 @
0a1ad630
...
...
@@ -6,7 +6,7 @@
import
os
import
ujson
from
flask
import
Blueprint
,
request
,
render_template
,
jsonify
,
make_response
from
flask
import
Blueprint
,
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
...
...
@@ -14,6 +14,7 @@ from utils.log import logger
import
shutil
from
utils.update
import
getLocalVer
,
getOnlineVer
,
download_new_version
,
download_lives
,
copy_to_update
from
utils
import
parser
from
utils.env
import
get_env
from
utils.web
import
getParmas
,
verfy_token
from
js.rules
import
getRules
,
getCacheCount
from
utils.parser
import
runJScode
...
...
@@ -74,7 +75,26 @@ def admin_view_rule(name):
if
not
name
or
not
name
.
split
(
'.'
)[
-
1
]
in
[
'js'
,
'txt'
,
'py'
,
'json'
]:
return
R
.
error
(
f
'非法猥亵,未指定文件名。必须包含js|txt|json|py'
)
try
:
return
parser
.
toJs
(
name
,
'js'
)
env
=
get_env
()
# print(env)
if
env
.
get
(
'js_proxy'
):
js_proxy
=
env
[
'js_proxy'
]
burl
=
request
.
base_url
if
'=>'
in
js_proxy
:
oldsrc
=
js_proxy
.
split
(
'=>'
)[
0
]
if
oldsrc
in
burl
:
newsrc
=
js_proxy
.
split
(
'=>'
)[
1
]
# print(f'js1源代理已启用,全局替换{oldsrc}为{newsrc}')
rurl
=
burl
.
replace
(
oldsrc
,
newsrc
)
if
burl
!=
rurl
:
jscode
=
parser
.
getJs
(
name
,
'js'
)
rjscode
=
render_template_string
(
jscode
,
env
=
env
)
if
rjscode
.
strip
()
==
jscode
.
strip
():
# 无需渲染才代理
return
redirect
(
rurl
)
else
:
logger
.
info
(
f
'
{
name
}
由于存在环境变量无法被依赖代理'
)
return
parser
.
toJs
(
name
,
'js'
,
env
)
except
Exception
as
e
:
return
R
.
error
(
f
'非法猥亵
\n
{
e
}
'
)
...
...
controllers/home.py
浏览文件 @
0a1ad630
...
...
@@ -262,13 +262,16 @@ def config_render(mode):
# print(parses)
merged_config
[
'parses'
]
=
parses
config_text
=
json
.
dumps
(
merged_config
,
ensure_ascii
=
False
,
indent
=
1
)
if
js_proxy
:
# print('js_proxy:',js_proxy)
if
'=>'
in
js_proxy
:
oldsrc
=
js_proxy
.
split
(
'=>'
)[
0
]
newsrc
=
js_proxy
.
split
(
'=>'
)[
1
]
print
(
f
'js1源代理已启用,全局替换
{
oldsrc
}
为
{
newsrc
}
'
)
config_text
=
config_text
.
replace
(
oldsrc
,
newsrc
)
# 依赖代理逻辑修改,改为admin/view去动态代理
# if js_proxy:
# # print('js_proxy:',js_proxy)
# if '=>' in js_proxy:
# oldsrc = js_proxy.split('=>')[0]
# newsrc = js_proxy.split('=>')[1]
# print(f'js1源代理已启用,全局替换{oldsrc}为{newsrc}')
# config_text = config_text.replace(oldsrc,newsrc)
response
=
make_response
(
config_text
)
# response = make_response(str(merged_config))
response
.
headers
[
'Content-Type'
]
=
'application/json; charset=utf-8'
...
...
controllers/vod.py
浏览文件 @
0a1ad630
...
...
@@ -5,10 +5,11 @@
# Date : 2022/9/6
import
json
from
flask
import
Blueprint
,
abort
,
request
,
render_template
,
jsonify
,
make_response
,
redirect
from
flask
import
Blueprint
,
abort
,
request
,
render_template
,
render_template_string
,
jsonify
,
make_response
,
redirect
from
time
import
time
from
utils.web
import
getParmas
,
get_interval
from
utils.cfg
import
cfg
from
utils.env
import
get_env
from
js.rules
import
getRuleLists
,
getJxs
from
base.R
import
R
from
utils.log
import
logger
...
...
@@ -237,6 +238,10 @@ def vod_home():
try
:
with
open
(
js_path
,
encoding
=
'utf-8'
)
as
f2
:
jscode
=
f2
.
read
()
env
=
get_env
()
if
env
:
jscode
=
render_template_string
(
jscode
,
env
=
env
)
# print(jscode)
jscode
=
before
+
jscode
+
end_code
# print(jscode)
ctx
.
eval
(
jscode
)
...
...
js/007影视.js
浏览文件 @
0a1ad630
muban
.
首图2
.
二级
.
tabs
=
'
.nav-tabs.dpplay&&li
'
;
var
rule
=
Object
.
assign
(
muban
.
首图2
,{
title
:
'
007影视
'
,
ali_token
:
'
{{env.ali_token}}
'
,
host
:
'
https://www.007ts.me
'
,
url
:
'
/channel/fyclass-fypage.html
'
,
searchUrl
:
'
/search/**----------fypage---.html
'
,
...
...
utils/env.py
0 → 100644
浏览文件 @
0a1ad630
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File : env.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date : 2022/11/21
from
utils.cfg
import
cfg
from
controllers.service
import
storage_service
def
get_env
():
new_conf
=
cfg
lsg
=
storage_service
()
store_conf_dict
=
lsg
.
getStoreConfDict
()
new_conf
.
update
(
store_conf_dict
)
# print(new_conf)
env
=
{
'ali_token'
:
new_conf
.
ALI_TOKEN
,
'js_proxy'
:
new_conf
.
JS_PROXY
}
return
env
\ No newline at end of file
utils/parser.py
浏览文件 @
0a1ad630
...
...
@@ -8,7 +8,7 @@ import os
import
shutil
import
requests
from
flask
import
make_response
,
jsonify
from
flask
import
make_response
,
jsonify
,
render_template_string
from
functools
import
partial
# 这玩意儿能锁定一个函数的参数
import
subprocess
subprocess
.
Popen
=
partial
(
subprocess
.
Popen
,
encoding
=
"utf-8"
)
# 固定写法
...
...
@@ -77,18 +77,30 @@ def runJs(jsPath, before='', after='', ctx=None):
# loader.execute(jscode_to_run)
# return loader,js_code
def
toJs
(
jsPath
,
jsRoot
=
'cache'
):
def
toJs
(
jsPath
,
jsRoot
=
'cache'
,
env
=
None
):
base_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
)))
# 上级目录
js_path
=
os
.
path
.
join
(
base_path
,
f
'
{
jsRoot
}
/
{
jsPath
}
'
)
print
(
js_path
)
#
print(js_path)
if
not
os
.
path
.
exists
(
js_path
):
return
jsonify
({
'code'
:
-
2
,
'msg'
:
f
'非法猥亵,文件不存在'
})
with
open
(
js_path
,
'r'
,
encoding
=
'UTF-8'
)
as
fp
:
js
=
fp
.
read
()
if
env
:
js
=
render_template_string
(
js
,
env
=
env
)
response
=
make_response
(
js
)
response
.
headers
[
'Content-Type'
]
=
'text/javascript; charset=utf-8'
return
response
def
getJs
(
jsPath
,
jsRoot
=
'cache'
):
base_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
)))
# 上级目录
js_path
=
os
.
path
.
join
(
base_path
,
f
'
{
jsRoot
}
/
{
jsPath
}
'
)
# print(js_path)
if
not
os
.
path
.
exists
(
js_path
):
return
''
with
open
(
js_path
,
'r'
,
encoding
=
'UTF-8'
)
as
fp
:
js
=
fp
.
read
()
return
js
def
toHtml
(
jsPath
):
base_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
)))
# 上级目录
js_path
=
os
.
path
.
join
(
base_path
,
f
'cache/
{
jsPath
}
'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录