diff --git a/src/backend/server/main.py b/src/backend/server/main.py index 4c5b249..bca8364 100644 --- a/src/backend/server/main.py +++ b/src/backend/server/main.py @@ -110,7 +110,7 @@ async def all_settings(request: Request) -> PlainTextResponse: @app.post('/settings/{id_}', response_class=PlainTextResponse) -async def update_setting(request: Request, id_: int) -> PlainTextResponse: +async def update_setting(request: Request, id_: str) -> PlainTextResponse: response = PlainTextResponse() if not database.uuid_exists(request.cookies.get('auth_cookie')): response.status_code = 401 diff --git a/src/backend/utils/feature_build.py b/src/backend/utils/feature_build.py new file mode 100644 index 0000000..1e5e15b --- /dev/null +++ b/src/backend/utils/feature_build.py @@ -0,0 +1,69 @@ +from typing import List + +import logging + +from utils import config + +_FILE_OF_FEATURE = { + 'STATUS_IN_SETTINGS': 'routes/setting/+page.svelte' +} + + +def disable_feature(feature: str) -> None: + filename = _decode_feature_file(feature) + if len(filename) == 0: + return + lines = _read_file(filename) + line_num = _find_feature(feature, lines) + if line_num < 0: + return + lines[line_num].replace('-->', '') + _write_file(filename, lines) + + +def enable_feature(feature: str) -> None: + filename = _decode_feature_file(feature) + if len(filename) == 0: + return + lines = _read_file(filename) + line_num = _find_feature(feature, lines) + if line_num < 0: + return + if lines[-1] != feature[-1]: + logging.error(f'Corrupted feature definition for feature "{feature}"') + return + lines[line_num] += '-->' + _write_file(filename, lines) + + +def get_features() -> List[str]: + return list(_FILE_OF_FEATURE.keys()) + +def _decode_feature_file(feature: str) -> str: + filename = _FILE_OF_FEATURE.get(feature) + if not filename: + logging.error(f'Non-existing feature: "{feature}"') + return "" + path = config.get('frontend').get('path') + return f'{path}/{filename}' + + +def _find_feature(feature: str, lines: list) -> int: + for i, line in enumerate(lines): + if line.startswith(f'