fix file preview url
Build and Push Docker Container / build-and-push (push) Successful in 1m30s

This commit is contained in:
2026-04-11 11:35:39 +02:00
parent 1c58de68b6
commit 3d8d74785c
2 changed files with 16 additions and 3 deletions
+8 -2
View File
@@ -24,6 +24,12 @@ def find_file(files: list[dict], file_id: str):
return file_data
return None
def build_share_url(file_id: str) -> str:
scheme = (request.headers.get("X-Forwarded-Proto") or request.scheme or "http").split(",")[0].strip()
host = (request.headers.get("X-Forwarded-Host") or request.host).split(",")[0].strip()
root_path = request.root_path.rstrip("/")
return f"{scheme}://{host}{root_path}/-{file_id}"
@side_main_bp.route('/')
@LIMITER.limit("10 per minute;50 per hour")
async def index():
@@ -54,7 +60,7 @@ async def file_info(file_id, user):
abort(404)
access_data = await current_app.convex.get_file_access(file_id=file_id, user_id=user["sub"]) or []
share_url = request.url_root.rstrip("/") + f"/-{file_id}"
share_url = build_share_url(file_id)
return await render_template(
"views/webpage/files/info.htm",
file=file_data,
@@ -69,7 +75,7 @@ async def file_edit(file_id, user):
if not file_data:
abort(404)
share_url = request.url_root.rstrip("/") + f"/-{file_id}"
share_url = build_share_url(file_id)
return await render_template(
"views/webpage/files/edit.htm", file=file_data, share_url=share_url, file_id=file_id
)
+8 -1
View File
@@ -143,7 +143,14 @@
const previewBody = document.getElementById('previewBody');
if (!previewBody) return;
const url = '{{ share_url }}';
let url = '{{ share_url }}';
if (window.location.protocol === 'https:' && url.startsWith('http://')) {
const parsed = new URL(url);
if (parsed.host === window.location.host) {
parsed.protocol = 'https:';
url = parsed.toString();
}
}
try {
const response = await fetch(url, { method: 'GET' });
if (!response.ok) {