This commit is contained in:
2026-04-27 00:47:25 +09:00
parent d1ebb7928d
commit 6a4e3cb9e3
2 changed files with 11 additions and 0 deletions
+1
View File
@@ -8,6 +8,7 @@ version = "1.0.0"
requires-python = ">=3.8" requires-python = ">=3.8"
dependencies = [ dependencies = [
"resvg-py", "resvg-py",
"scour",
"rjsmin", "rjsmin",
"rcssmin", "rcssmin",
"mistune", "mistune",
+10
View File
@@ -1,6 +1,7 @@
import rjsmin import rjsmin
import rcssmin import rcssmin
import subprocess import subprocess
from scour import scour
from fastapi import Response from fastapi import Response
from fastapi.responses import PlainTextResponse from fastapi.responses import PlainTextResponse
from starlette.types import Scope, ASGIApp, Receive, Send from starlette.types import Scope, ASGIApp, Receive, Send
@@ -133,6 +134,15 @@ class Middleware:
response.body = rjsmin.jsmin(response.body.decode("utf-8", errors="replace")).encode("utf-8") response.body = rjsmin.jsmin(response.body.decode("utf-8", errors="replace")).encode("utf-8")
except Exception: except Exception:
pass pass
elif "image/svg+xml" in content_type:
try:
options = scour.generateDefaultOptions()
options.newlines = True
options.shorten_ids = True
options.strip_comments = True
response.body = scour.scourString(response.body.decode("utf-8", errors="replace"), options).encode("utf-8")
except Exception:
pass
response.headers["Content-Length"] = str(len(response.body)) response.headers["Content-Length"] = str(len(response.body))
await response(scope, receive, send) await response(scope, receive, send)