--
This commit is contained in:
@@ -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",
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user