add proxy support
This commit is contained in:
parent
e6c8ed5504
commit
fc3323faa5
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from blib import Url
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Generic, TypeVar
|
from typing import Any, Generic, TypeVar
|
||||||
|
@ -96,6 +97,17 @@ class Config(dict[str, dict[str, Any]]):
|
||||||
self.path.parent.mkdir(exist_ok = True, parents = True)
|
self.path.parent.mkdir(exist_ok = True, parents = True)
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def proxy_url(self) -> Url:
|
||||||
|
return Url(
|
||||||
|
domain = self.proxy_host,
|
||||||
|
proto = self.proxy_type,
|
||||||
|
port = self.proxy_port,
|
||||||
|
username = self.proxy_user,
|
||||||
|
password = self.proxy_pass
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sqlite_path(self) -> Path:
|
def sqlite_path(self) -> Path:
|
||||||
return self.path.parent.joinpath("database.sqlite3")
|
return self.path.parent.joinpath("database.sqlite3")
|
||||||
|
|
|
@ -20,6 +20,7 @@ from .translations import Translations
|
||||||
|
|
||||||
from basgi import (
|
from basgi import (
|
||||||
Application as App,
|
Application as App,
|
||||||
|
Client,
|
||||||
Request,
|
Request,
|
||||||
Response,
|
Response,
|
||||||
Template,
|
Template,
|
||||||
|
@ -40,6 +41,10 @@ class Application(App[Request, RequestState, AppState]):
|
||||||
|
|
||||||
self.state.setup(cfg_path, language)
|
self.state.setup(cfg_path, language)
|
||||||
self.error_handlers[HttpError] = self.handle_http_exception
|
self.error_handlers[HttpError] = self.handle_http_exception
|
||||||
|
|
||||||
|
if self.state.config.proxy_enabled:
|
||||||
|
self.client = Client(self.name, self.state.config.proxy_url)
|
||||||
|
|
||||||
self.client.useragent = f"BarksharkSocial/{__version__} (https://{self.config.web_host})"
|
self.client.useragent = f"BarksharkSocial/{__version__} (https://{self.config.web_host})"
|
||||||
|
|
||||||
self.add_static(
|
self.add_static(
|
||||||
|
|
Loading…
Reference in a new issue