Skip to content

Commit f10009a

Browse files
committed
v1.16
- feat: new hook named pic2webp, tks @hiBlunt - fix: jinja2 PackageLoader ValueError for single module - hook package persistence(alpha test)
1 parent 9727ac2 commit f10009a

File tree

8 files changed

+132
-62
lines changed

8 files changed

+132
-62
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ jobs:
3535
3636
- name: Test & upload report to coverage
3737
run: |
38-
cd src && coverage run -m unittest discover -p "test_*.py" && codecov -t ${{ secrets.CODECOV_TOKEN }}
38+
cd src && coverage run -m unittest discover -p "test_*.py" && codecov --token ${{ secrets.CODECOV_TOKEN }}

src/app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"""
1111

1212
from flask import Flask, g, request, render_template, jsonify
13+
from werkzeug.middleware.proxy_fix import ProxyFix
14+
from sys import path
1315
from views import front_bp, api_bp
1416
from utils.tool import (
1517
Attribute,
@@ -35,7 +37,6 @@
3537
from libs.hook import HookManager
3638
from config import GLOBAL
3739
from version import __version__
38-
from werkzeug.middleware.proxy_fix import ProxyFix
3940

4041
__author__ = "staugur"
4142
__email__ = "[email protected]"
@@ -55,6 +56,8 @@
5556
)
5657
if GLOBAL["ProxyFix"]:
5758
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
59+
if GLOBAL["HookPkgStorageDir"]:
60+
path.insert(1, GLOBAL["HookPkgStorageDir"])
5861

5962
hm = HookManager(app)
6063
app.register_blueprint(front_bp)

src/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
# 站点设置部分参数额外允许的HTML标签的属性
4141
"AllowStyles": envs.get("sapic_allowstyles", ""),
4242
# 站点设置部分参数额外允许的HTML标签的样式
43+
"HookPkgStorageDir": "",
44+
# 第三方扩展包持久化目录
4345
}
4446

4547

src/libs/hook.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,14 @@ def add_third_hook(self, third_hook_module_name):
367367
if third_hook_module_name:
368368
self.__third_hooks = third_hook_module_name
369369
if hasattr(self, "app"):
370-
self.app.jinja_loader.loaders.append(
371-
PackageLoader(third_hook_module_name)
372-
)
370+
try:
371+
self.app.jinja_loader.loaders.append(
372+
PackageLoader(third_hook_module_name)
373+
)
374+
except ValueError:
375+
self.app.jinja_loader.loaders.append(
376+
PackageLoader(third_hook_module_name, "")
377+
)
373378
self.reload()
374379

375380
def remove_third_hook(self, third_hook_name):

src/sapicd.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@ def delete_hookloadtime():
1313
del s["hookloadtime"]
1414

1515

16-
IS_RUN = (
17-
True
18-
if (getenv("sapic_isrun") or getenv("picbed_isrun")) == "true"
19-
else False
20-
)
21-
22-
CPU_COUNT = int(
23-
envs.get("sapic_cpucount") or envs.get("picbed_cpucount") or cpu_count()
24-
)
16+
IS_RUN = True if getenv("sapic_isrun") == "true" else False
17+
18+
CPU_COUNT = int(envs.get("sapic_cpucount") or cpu_count())
2519

2620
LOGSDIR = join(dirname(abspath(__file__)), "logs")
2721
if not exists(LOGSDIR):

src/utils/web.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import imghdr
1414
from posixpath import basename, splitext
1515
from os import remove
16-
from os.path import join as pathjoin, getsize
16+
from os.path import join as pathjoin, getsize, isdir
1717
from io import BytesIO
1818
from functools import wraps
1919
from base64 import urlsafe_b64decode as b64decode, b64decode as pic64decode
@@ -69,6 +69,7 @@
6969
b64size,
7070
)
7171
from ._compat import text_type, urlsplit, parse_qs
72+
from config import GLOBAL
7273
from threading import Thread
7374
from functools import reduce
7475

@@ -673,8 +674,11 @@ def get_upload_method(class_name):
673674

674675

675676
def _pip_install(pkg, index=None, upgrade=None):
676-
"""使用pip安装模块到用户目录$HOME/.local"""
677+
"""使用pip安装模块到指定目标或默认用户目录$HOME/.local"""
678+
tgt = GLOBAL["HookPkgStorageDir"]
677679
cmd = [executable, "-m", "pip", "install", "-q"]
680+
if tgt:
681+
cmd.extend(("-t", tgt))
678682
if not is_venv():
679683
cmd.append("--user")
680684
if upgrade:
@@ -700,6 +704,10 @@ def _pip_list(fmt=None, no_fresh=True):
700704
else:
701705
cmd = [executable, "-m", "pip", "list", "--format", "json"]
702706
data = json.loads(check_output(cmd))
707+
tgt = GLOBAL["HookPkgStorageDir"]
708+
if tgt and isdir(tgt):
709+
cmd.extend(("--path", tgt))
710+
data.extend(json.loads(check_output(cmd)))
703711
pipe = rc.pipeline()
704712
pipe.set(key, json.dumps(data))
705713
pipe.expire(key, 3600)

src/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.15.0"
1+
__version__ = "1.16.0"

0 commit comments

Comments
 (0)