Skip to content

Commit

Permalink
Fixed manifest updating for smaller url prefix
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Casvt committed Mar 10, 2024
1 parent 37cec53 commit 99d59cd
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

import logging
from json import dumps, loads
from json import dump, load
from typing import Any

from backend.custom_exceptions import InvalidKeyValue, KeyNotFound
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 99d59cd

Please sign in to comment.