mirror of
https://github.com/Casvt/MIND.git
synced 2026-02-19 11:54:46 -05:00
Fixed manifest updating for smaller url prefix
When the value of the URL prefix would be changed, if the resulting json would be smaller than the current json, it would create invalid json. Now we wipe the contents before writing to avoid this.
This commit is contained in:
@@ -5,7 +5,7 @@ Getting and setting settings
|
||||
"""
|
||||
|
||||
import logging
|
||||
from json import dumps, loads
|
||||
from json import dump, load
|
||||
from typing import Any
|
||||
|
||||
from backend.custom_exceptions import InvalidKeyValue, KeyNotFound
|
||||
@@ -67,7 +67,10 @@ def _format_setting(key: str, value):
|
||||
if not isinstance(value, str):
|
||||
raise InvalidKeyValue(key, value)
|
||||
|
||||
if value:
|
||||
if value == '/':
|
||||
value = ''
|
||||
|
||||
elif value:
|
||||
value = '/' + value.strip('/')
|
||||
|
||||
elif key == 'log_level' and not value in (logging.INFO, logging.DEBUG):
|
||||
@@ -171,12 +174,16 @@ def update_manifest(url_base: str) -> None:
|
||||
Args:
|
||||
url_base (str): The url base to use in the file.
|
||||
"""
|
||||
with open(folder_path('frontend', 'static', 'json', 'pwa_manifest.json'), 'r+') as f:
|
||||
manifest = loads(f.read())
|
||||
filename = folder_path('frontend', 'static', 'json', 'pwa_manifest.json')
|
||||
|
||||
with open(filename, 'r') as f:
|
||||
manifest = load(f)
|
||||
manifest['start_url'] = url_base + '/'
|
||||
manifest['icons'][0]['src'] = f'{url_base}/static/img/favicon.svg'
|
||||
f.seek(0)
|
||||
f.write(dumps(manifest, indent=4))
|
||||
|
||||
with open(filename, 'w') as f:
|
||||
dump(manifest, f, indent=4)
|
||||
|
||||
return
|
||||
|
||||
def backup_hosting_settings() -> None:
|
||||
@@ -228,5 +235,7 @@ def restore_hosting_settings() -> None:
|
||||
"UPDATE config SET value = ? WHERE key = ?",
|
||||
((v, k) for k, v in hosting_settings.items())
|
||||
)
|
||||
|
||||
|
||||
update_manifest(hosting_settings['url_prefix'])
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user