mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-14 18:38:11 +02:00
Added proper resolving for https.
This commit is contained in:
1 parent
ea1c444c49
commit
6743dd7626
1 file changed
+21
-1
+21
-1
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -691,6 +692,23 @@ def GetPublicMediaEndpoint(RootName: str, FilePath: str, request: Request):
|
|||||||
return StreamBinaryFile(ResolvedPath, request.headers.get("range"))
|
return StreamBinaryFile(ResolvedPath, request.headers.get("range"))
|
||||||
|
|
||||||
|
|
||||||
|
def GetForwardedScheme(request: Request) -> str:
|
||||||
|
ForwardedProto = request.headers.get("x-forwarded-proto")
|
||||||
|
if ForwardedProto:
|
||||||
|
return ForwardedProto.split(",")[0].strip()
|
||||||
|
|
||||||
|
CfVisitor = request.headers.get("cf-visitor")
|
||||||
|
if CfVisitor:
|
||||||
|
try:
|
||||||
|
ParsedScheme = json.loads(CfVisitor).get("scheme")
|
||||||
|
if ParsedScheme:
|
||||||
|
return ParsedScheme
|
||||||
|
except (json.JSONDecodeError, AttributeError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
return request.url.scheme
|
||||||
|
|
||||||
|
|
||||||
FrontendDist = ApplicationDirectory.parent / "Frontend" / "dist"
|
FrontendDist = ApplicationDirectory.parent / "Frontend" / "dist"
|
||||||
|
|
||||||
if FrontendDist.is_dir():
|
if FrontendDist.is_dir():
|
||||||
@@ -708,7 +726,9 @@ if FrontendDist.is_dir():
|
|||||||
Segments = [Segment for Segment in FullPath.split("/") if Segment]
|
Segments = [Segment for Segment in FullPath.split("/") if Segment]
|
||||||
|
|
||||||
if Segments:
|
if Segments:
|
||||||
BaseUrl = f"{request.url.scheme}://{request.url.netloc}"
|
Scheme = GetForwardedScheme(request)
|
||||||
|
Host = request.headers.get("x-forwarded-host", request.url.netloc)
|
||||||
|
BaseUrl = f"{Scheme}://{Host}"
|
||||||
OgTags = (
|
OgTags = (
|
||||||
BuildOgTags(Segments[0], "/".join(Segments[1:]), FullPath.endswith("/"), BaseUrl)
|
BuildOgTags(Segments[0], "/".join(Segments[1:]), FullPath.endswith("/"), BaseUrl)
|
||||||
or ""
|
or ""
|
||||||
|
|||||||
Reference in new issue
Block a user