From 0f14a33c7354df57054c7c1b56dc0746ec4fce3e Mon Sep 17 00:00:00 2001 From: Anderson Shindy Oki Date: Mon, 8 Jul 2024 10:32:11 +0900 Subject: [PATCH] Fixed pwa assets files not served (#2568) --- bazarr/app/ui.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bazarr/app/ui.py b/bazarr/app/ui.py index 81a949035..79649e30e 100644 --- a/bazarr/app/ui.py +++ b/bazarr/app/ui.py @@ -20,9 +20,10 @@ from .config import settings, base_url from .database import System from .get_args import args +frontend_build_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'frontend', 'build') + ui_bp = Blueprint('ui', __name__, - template_folder=os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), - 'frontend', 'build'), + template_folder=frontend_build_path, static_folder=os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'frontend', 'build', 'assets'), static_url_path='/assets') @@ -38,13 +39,15 @@ static_bp = Blueprint('images', __name__, static_folder=static_directory, static ui_bp.register_blueprint(static_bp) - mimetypes.add_type('application/javascript', '.js') mimetypes.add_type('text/css', '.css') mimetypes.add_type('font/woff2', '.woff2') mimetypes.add_type('image/svg+xml', '.svg') mimetypes.add_type('image/png', '.png') mimetypes.add_type('image/x-icon', '.ico') +mimetypes.add_type('application/manifest+json', '.webmanifest') + +pwa_assets = ['registerSW.js', 'manifest.webmanifest', 'sw.js'] def check_login(actual_method): @@ -70,6 +73,10 @@ def catch_all(path): # login page has been accessed when no authentication is enabled return redirect(base_url or "/", code=302) + # PWA Assets are returned from frontend root folder + if path in pwa_assets or path.startswith('workbox-'): + return send_file(os.path.join(frontend_build_path, path)) + auth = True if settings.auth.type == 'basic': auth = request.authorization @@ -186,7 +193,8 @@ def proxy(protocol, url): elif result.status_code == 401: return dict(status=False, error='Access Denied. Check API key.', code=result.status_code) elif result.status_code == 404: - return dict(status=False, error='Cannot get version. Maybe unsupported legacy API call?', code=result.status_code) + return dict(status=False, error='Cannot get version. Maybe unsupported legacy API call?', + code=result.status_code) elif 300 <= result.status_code <= 399: return dict(status=False, error='Wrong URL Base.', code=result.status_code) else: