Skip to content

Commit 191a993

Browse files
committed
feat: 新增反代
1 parent b4da9db commit 191a993

File tree

5 files changed

+887
-420
lines changed

5 files changed

+887
-420
lines changed

core/cluster.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -836,16 +836,19 @@ async def start(self):
836836
self.storage_manager.init()
837837
logger.tdebug("cluster.debug.base_url", base_url=config.const.base_url)
838838

839-
certificates = await self.get_certificates()
840-
for cert in certificates:
841-
await web.start_private_server(
842-
cert.cert, cert.key
843-
)
844-
# start web ssl
845-
public_port = config.const.public_port
846-
public_host = cert.host
839+
if not config.const.proxy:
840+
certificates = await self.get_certificates()
841+
for cert in certificates:
842+
await web.start_private_server(
843+
cert.cert, cert.key
844+
)
845+
# start web ssl
846+
public_port = config.const.public_port
847+
public_host = cert.host
847848

848-
logger.tdebug("cluster.debug.public_host", host=public_host, port=public_port, domain=cert.domain)
849+
logger.tdebug("cluster.debug.public_host", host=public_host, port=public_port, domain=cert.domain)
850+
else:
851+
public_host = config.const.host
849852

850853
# check files
851854
await self.file_manager.sync()
@@ -1384,7 +1387,7 @@ def get(self, interval: int = 1) -> list[BandwidthList]:
13841387
]
13851388
BANDWIDTH_COUNTER = BandwidthCounter()
13861389
routes = web.routes
1387-
aweb = web.web
1390+
aweb = web.aiohttp_web
13881391
clusters = ClusterManager()
13891392

13901393
def convert_file_to_storage_file(file: File) -> SFile:

core/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"web": {
2727
"port": -1,
2828
"public_port": 6543,
29-
"x_forwarded_for": 0,
3029
"backlog": 1024,
31-
"sockets": 8
30+
"sockets": 8,
31+
"proxy": False
3232
},
3333
"clusters": [
3434
{
@@ -151,9 +151,9 @@ def sync_interval(self):
151151
return max(Config.get("advanced.sync_interval", 600) or 600, 600)
152152

153153
@property
154-
def xff(self):
155-
return Config.get("web.x_forwarded_for") or 0
156-
154+
def proxy(self) -> bool:
155+
return Config.get("web.proxy") or False
156+
157157
@property
158158
def auto_sync_assets(self):
159159
return bool(Config.get("advanced.auto_sync_assets", True))

core/logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def warning(self, *args, **kwargs):
4343
def success(self, *args, **kwargs):
4444
self._log_with_args("SUCCESS", *args, **kwargs)
4545
def traceback(self, *args, **kwargs):
46-
if args and kwargs:
46+
if args or kwargs:
4747
self._log_with_args("ERROR", *args, **kwargs)
4848
self._log_with_args("ERROR", "\n" + traceback.format_exc())
4949

@@ -68,7 +68,7 @@ def tsuccess(self, key: str, *args, **kwargs):
6868
key, *args, **kwargs
6969
))
7070
def ttraceback(self, key: str, *args, **kwargs):
71-
if args and kwargs:
71+
if args or kwargs:
7272
self._log_with_args("ERROR", locale.t(
7373
key, *args, **kwargs
7474
))

0 commit comments

Comments
 (0)