Skip to content

Commit

Permalink
Fix missing images issue when serving via Flask
Browse files Browse the repository at this point in the history
  • Loading branch information
LASER-Yi committed Jun 18, 2022
1 parent e1d6f2d commit 4b71b8a
Show file tree
Hide file tree
Showing 14 changed files with 11 additions and 21 deletions.
26 changes: 8 additions & 18 deletions bazarr/app/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
template_folder=os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
'frontend', 'build'),
static_folder=os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'frontend',
'build', 'static'),
static_url_path=base_url.rstrip('/') + '/static')
'build', 'assets'),
static_url_path='/assets')

static_bp = Blueprint('images', __name__,
static_folder=os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'frontend',
'build', 'images'), static_url_path='/images')

ui_bp.register_blueprint(static_bp)


def check_login(actual_method):
Expand Down Expand Up @@ -75,22 +81,6 @@ def catch_all(path):
return render_template("index.html", BAZARR_SERVER_INJECT=inject, baseUrl=template_url)


@ui_bp.route('/assets/<path:filename>')
def web_assets(filename):
# forcing mimetypes to prevent bad configuration in Windows registry to prevent Bazarr UI from showing
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')

# send_from_directory needs an absolute path then we'll use realpath() here
path = os.path.realpath(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'frontend',
'build', 'assets'))
return send_from_directory(path, filename)


@check_login
@ui_bp.route('/bazarr.log')
def download_log():
Expand Down
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Bazarr</title>
<base href="{{baseUrl}}" />
<meta charset="utf-8" />
<link rel="icon" type="image/x-icon" href="./static/favicon.ico" />
<link rel="icon" type="image/x-icon" href="./favicon.ico" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"
Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion frontend/src/App/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const AppHeader: FunctionComponent = () => {
<Avatar
alt="brand"
size={32}
src={`${Environment.baseUrl}/static/logo64.png`}
src={`${Environment.baseUrl}/images/logo64.png`}
></Avatar>
</Anchor>
</MediaQuery>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Authentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Authentication: FunctionComponent = () => {
<Avatar
mx="auto"
size={64}
src={`${Environment.baseUrl}/static/logo128.png`}
src={`${Environment.baseUrl}/images/logo128.png`}
></Avatar>
<Divider></Divider>
<form onSubmit={form.onSubmit(login)}>
Expand Down

0 comments on commit 4b71b8a

Please sign in to comment.