Skip to content

Commit

Permalink
fix: catch error if settings template not found'
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintShit committed Jul 29, 2024
1 parent e611ed5 commit 582b2bb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
16 changes: 8 additions & 8 deletions app/subscription/clash.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
from random import choice

import yaml
from jinja2.exceptions import TemplateNotFound

from app.subscription.funcs import get_grpc_gun
from app.templates import render_template
from config import (
CLASH_SUBSCRIPTION_TEMPLATE,
CLASH_SETTINGS_TEMPLATE,
MUX_TEMPLATE,
USER_AGENT_TEMPLATE,
)
from config import (CLASH_SETTINGS_TEMPLATE, CLASH_SUBSCRIPTION_TEMPLATE,
MUX_TEMPLATE, USER_AGENT_TEMPLATE)


class ClashConfiguration(object):
Expand All @@ -31,7 +28,10 @@ def __init__(self):
else:
self.user_agent_list = []

self.settings = yaml.load(render_template(CLASH_SETTINGS_TEMPLATE), Loader=yaml.SafeLoader)
try:
self.settings = yaml.load(render_template(CLASH_SETTINGS_TEMPLATE), Loader=yaml.SafeLoader)
except TemplateNotFound:
self.settings = {}

del user_agent_data

Expand Down Expand Up @@ -93,7 +93,7 @@ def ws_config(
host="",
max_early_data=None,
early_data_header_name="",
is_httpupgrade: bool =False,
is_httpupgrade: bool = False,
random_user_agent: bool = False,
):
config = copy.deepcopy(self.settings.get("ws-opts", {}))
Expand Down
19 changes: 10 additions & 9 deletions app/subscription/singbox.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import json
from random import choice
from app.templates import render_template
from app.subscription.funcs import get_grpc_gun

from config import (
SINGBOX_SUBSCRIPTION_TEMPLATE,
SINGBOX_SETTINGS_TEMPLATE,
MUX_TEMPLATE,
USER_AGENT_TEMPLATE,
)
from jinja2.exceptions import TemplateNotFound

from app.subscription.funcs import get_grpc_gun
from app.templates import render_template
from config import (MUX_TEMPLATE, SINGBOX_SETTINGS_TEMPLATE,
SINGBOX_SUBSCRIPTION_TEMPLATE, USER_AGENT_TEMPLATE)


class SingBoxConfiguration(str):
Expand All @@ -24,7 +22,10 @@ def __init__(self):
else:
self.user_agent_list = []

self.settings = json.loads(render_template(SINGBOX_SETTINGS_TEMPLATE))
try:
self.settings = json.loads(render_template(SINGBOX_SETTINGS_TEMPLATE))
except TemplateNotFound:
self.settings = {}

del user_agent_data

Expand Down
48 changes: 24 additions & 24 deletions app/subscription/v2ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
from urllib.parse import quote
from uuid import UUID

from jinja2.exceptions import TemplateNotFound

from app.subscription.funcs import get_grpc_gun, get_grpc_multi
from app.templates import render_template
from config import (
MUX_TEMPLATE,
USER_AGENT_TEMPLATE,
V2RAY_SUBSCRIPTION_TEMPLATE,
V2RAY_SETTINGS_TEMPLATE,
GRPC_USER_AGENT_TEMPLATE,
EXTERNAL_CONFIG
)
from config import (EXTERNAL_CONFIG, GRPC_USER_AGENT_TEMPLATE, MUX_TEMPLATE,
USER_AGENT_TEMPLATE, V2RAY_SETTINGS_TEMPLATE,
V2RAY_SUBSCRIPTION_TEMPLATE)


class V2rayShareLink(str):
Expand Down Expand Up @@ -207,10 +204,10 @@ def vmess(
payload["maxConcurrentUploads"] = max_concurrent_uploads

return (
"vmess://"
+ base64.b64encode(
json.dumps(payload, sort_keys=True).encode("utf-8")
).decode()
"vmess://"
+ base64.b64encode(
json.dumps(payload, sort_keys=True).encode("utf-8")
).decode()
)

@classmethod
Expand Down Expand Up @@ -291,10 +288,10 @@ def vless(cls,
payload["spx"] = spx

return (
"vless://"
+ f"{id}@{address}:{port}?"
+ urlparse.urlencode(payload)
+ f"#{(urlparse.quote(remark))}"
"vless://"
+ f"{id}@{address}:{port}?"
+ urlparse.urlencode(payload)
+ f"#{(urlparse.quote(remark))}"
)

@classmethod
Expand Down Expand Up @@ -374,20 +371,20 @@ def trojan(cls,
payload["spx"] = spx

return (
"trojan://"
+ f"{urlparse.quote(password, safe=':')}@{address}:{port}?"
+ urlparse.urlencode(payload)
+ f"#{urlparse.quote(remark)}"
"trojan://"
+ f"{urlparse.quote(password, safe=':')}@{address}:{port}?"
+ urlparse.urlencode(payload)
+ f"#{urlparse.quote(remark)}"
)

@classmethod
def shadowsocks(
cls, remark: str, address: str, port: int, password: str, method: str
):
return (
"ss://"
+ base64.b64encode(f"{method}:{password}".encode()).decode()
+ f"@{address}:{port}#{urlparse.quote(remark)}"
"ss://"
+ base64.b64encode(f"{method}:{password}".encode()).decode()
+ f"@{address}:{port}#{urlparse.quote(remark)}"
)


Expand All @@ -411,7 +408,10 @@ def __init__(self):
else:
self.grpc_user_agent_data = []

self.settings = json.loads(render_template(V2RAY_SETTINGS_TEMPLATE))
try:
self.settings = json.loads(render_template(V2RAY_SETTINGS_TEMPLATE))
except TemplateNotFound:
self.settings = {}

del user_agent_data, grpc_user_agent_data

Expand Down

0 comments on commit 582b2bb

Please sign in to comment.