mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-06-07 11:45:35 +00:00
fix: safari compression bug (untested)
This commit is contained in:
parent
1d71ba856b
commit
cad0651f5e
32
manage.py
32
manage.py
@ -3,6 +3,8 @@ This file is used to run the application.
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
import os
|
||||||
|
from flask import request
|
||||||
|
|
||||||
import setproctitle
|
import setproctitle
|
||||||
|
|
||||||
@ -37,25 +39,31 @@ app = create_api()
|
|||||||
app.static_folder = get_home_res_path("client")
|
app.static_folder = get_home_res_path("client")
|
||||||
|
|
||||||
|
|
||||||
# @app.route("/", defaults={"path": ""})
|
|
||||||
@app.route("/<path:path>")
|
@app.route("/<path:path>")
|
||||||
def serve_client_files(path: str):
|
def serve_client_files(path: str):
|
||||||
"""
|
"""
|
||||||
Serves the static files in the client folder.
|
Serves the static files in the client folder.
|
||||||
"""
|
"""
|
||||||
# js_or_css = path.endswith(".js") or path.endswith(".css")
|
js_or_css = path.endswith(".js") or path.endswith(".css")
|
||||||
# if not js_or_css:
|
if not js_or_css:
|
||||||
# return app.send_static_file(path)
|
return app.send_static_file(path)
|
||||||
|
|
||||||
# gzipped_path = path + ".gz"
|
gzipped_path = path + ".gz"
|
||||||
|
user_agent = request.headers.get("User-Agent")
|
||||||
|
|
||||||
|
is_safari = user_agent.find("Safari") >= 0 and user_agent.find("Chrome") < 0
|
||||||
|
|
||||||
|
if is_safari:
|
||||||
|
return app.send_static_file(path)
|
||||||
|
|
||||||
|
accepts_gzip = request.headers.get("Accept-Encoding", "").find("gzip") >= 0
|
||||||
|
|
||||||
|
if accepts_gzip:
|
||||||
|
if os.path.exists(os.path.join(app.static_folder, gzipped_path)):
|
||||||
|
response = app.make_response(app.send_static_file(gzipped_path))
|
||||||
|
response.headers["Content-Encoding"] = "gzip"
|
||||||
|
return response
|
||||||
|
|
||||||
# if request.headers.get("Accept-Encoding", "").find("gzip") >= 0:
|
|
||||||
# if os.path.exists(os.path.join(app.static_folder, gzipped_path)):
|
|
||||||
# response = app.make_response(app.send_static_file(gzipped_path))
|
|
||||||
# response.headers["Content-Encoding"] = "gzip"
|
|
||||||
# return response
|
|
||||||
# else:
|
|
||||||
# return app.send_static_file(path)
|
|
||||||
return app.send_static_file(path)
|
return app.send_static_file(path)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user