--
This commit is contained in:
@@ -8,6 +8,7 @@ version = "1.0.0"
|
||||
requires-python = ">=3.8"
|
||||
dependencies = [
|
||||
"resvg-py",
|
||||
"scour",
|
||||
"rjsmin",
|
||||
"rcssmin",
|
||||
"mistune",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import rjsmin
|
||||
import rcssmin
|
||||
import subprocess
|
||||
from scour import scour
|
||||
from fastapi import Response
|
||||
from fastapi.responses import PlainTextResponse
|
||||
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")
|
||||
except Exception:
|
||||
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))
|
||||
|
||||
await response(scope, receive, send)
|
||||
|
||||
Reference in New Issue
Block a user