Add configuration
This commit is contained in:
parent
4487003558
commit
2b75aac67c
3 changed files with 23 additions and 9 deletions
|
@ -5,3 +5,8 @@ services:
|
||||||
build: .
|
build: .
|
||||||
volumes:
|
volumes:
|
||||||
- .:/app
|
- .:/app
|
||||||
|
environment:
|
||||||
|
- IWM_SERVER="http://make.fangam.es"
|
||||||
|
- IWM_THUMBNAILS="https://images.make.fangam.es"
|
||||||
|
- IMGPROXY_URL="http://127.0.0.1:8080"
|
||||||
|
- IMGPROXY_PARAMS="{\"extension\":\"webp\",\"advanced\":[\"q:50\"]}"
|
||||||
|
|
|
@ -13,7 +13,7 @@ from . import __version__
|
||||||
|
|
||||||
basedir = os.path.dirname(__file__)
|
basedir = os.path.dirname(__file__)
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI(openapi_url=None)
|
||||||
app.mount("/static", StaticFiles(directory=basedir + "/static"), name="static")
|
app.mount("/static", StaticFiles(directory=basedir + "/static"), name="static")
|
||||||
|
|
||||||
template_env = jinja2.Environment(
|
template_env = jinja2.Environment(
|
||||||
|
@ -26,15 +26,13 @@ template_env.globals["convert_times"] = utils.convert_times
|
||||||
template_env.globals["generate_thumbnail_url"] = utils.generate_thumbnail_url
|
template_env.globals["generate_thumbnail_url"] = utils.generate_thumbnail_url
|
||||||
template_env.globals["__version__"] = __version__
|
template_env.globals["__version__"] = __version__
|
||||||
|
|
||||||
BASE_URL = "http://make.fangam.es"
|
BASE_URL = utils.config_value("IWM_SERVER", "http://make.fangam.es")
|
||||||
THUMB_URL = "https://images.make.fangam.es"
|
THUMB_URL = utils.config_value("IWM_THUMBNAILS", "https://images.make.fangam.es")
|
||||||
utils.global_imgproxy_url = (
|
utils.global_imgproxy_url = utils.config_value("IMGPROXY_URL", None)
|
||||||
"http://127.0.0.1:8080" # Set it to None to disable the proxy
|
utils.global_imgproxy_params = json.loads(utils.config_value("IMGPROXY_PARAMS", '''{
|
||||||
)
|
|
||||||
utils.global_imgproxy_params = {
|
|
||||||
"extension": "webp",
|
"extension": "webp",
|
||||||
"advanced": ["q:50"],
|
"advanced": ["q:50"],
|
||||||
} # Set it to None to disable the proxy params
|
}''')) # Set it to None to disable the proxy params
|
||||||
|
|
||||||
# Matches level code.
|
# Matches level code.
|
||||||
# \S[A-Z0-9]{4}\-[A-Z0-9]{4} = With dash, no whitespace
|
# \S[A-Z0-9]{4}\-[A-Z0-9]{4} = With dash, no whitespace
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from imgproxy import ImgProxy
|
from imgproxy import ImgProxy
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
def convert_times(time):
|
def convert_times(time):
|
||||||
# Not sure if it's the right way to do that, but it seems to work.
|
# Not sure if it's the right way to do that, but it seems to work.
|
||||||
|
@ -15,6 +16,16 @@ def convert_times(time):
|
||||||
|
|
||||||
return (hours, minutes, seconds)
|
return (hours, minutes, seconds)
|
||||||
|
|
||||||
|
def config_value(key: str, default_value=None):
|
||||||
|
"""Searches for environ value for the specified key,
|
||||||
|
or returns the default value.
|
||||||
|
|
||||||
|
The value must be in json format!"""
|
||||||
|
if key in os.environ:
|
||||||
|
return json.loads(os.environ[key])
|
||||||
|
else:
|
||||||
|
return default_value
|
||||||
|
|
||||||
|
|
||||||
# Specify default imgproxy instance.
|
# Specify default imgproxy instance.
|
||||||
global_imgproxy_url = None
|
global_imgproxy_url = None
|
||||||
|
|
Loading…
Reference in a new issue