From 23ddda75552d90b9708c91fecfaa67baf3855df3 Mon Sep 17 00:00:00 2001 From: justuser-31 Date: Wed, 4 Feb 2026 17:54:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=88=D0=B8=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B5=D0=B9=20CDN=20(+HTML)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 2 +- handlers.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/config.py b/config.py index 1f86752..b1d8382 100644 --- a/config.py +++ b/config.py @@ -10,7 +10,7 @@ server: host: 127.0.0.1 port: 8000 session_timeout: 3600 # Seconds - video_and_image_preview: true # Use as "CDN" or not + use_as_cdn: true # Use as "CDN" or not (show image, play video+audio, load htmls) security: api_token: "test" # Change this in production diff --git a/handlers.py b/handlers.py index 10cac98..4ce2576 100644 --- a/handlers.py +++ b/handlers.py @@ -3,7 +3,7 @@ import os import sqlite3 from datetime import datetime from http.server import BaseHTTPRequestHandler -from urllib.parse import parse_qs, unquote, urlparse +from urllib.parse import parse_qs, quote, unquote, urlparse import database from config import get_storage_root, load_config @@ -295,7 +295,6 @@ class FileServerHandler(BaseHTTPRequestHandler): user_dir = os.path.join(get_storage_root(), username) filepath = os.path.join(user_dir, decoded_filename) - print(filepath) if not os.path.exists(filepath) or not os.path.isfile(filepath): self.send_html("

File not found

", 404) @@ -306,9 +305,13 @@ class FileServerHandler(BaseHTTPRequestHandler): mime_type = "application/octet-stream" # Maybe you don't want to transform your FS into CDN? - if CONFIG.get("server", {}).get("video_and_image_preview", True): - # Determine if the file should be displayed inline or downloaded - if mime_type.startswith(("image/", "video/", "audio/")): + if CONFIG.get("server", {}).get("use_as_cdn", True): + # Check if it's an HTML file + if decoded_filename.endswith(".html") or decoded_filename.endswith(".htm"): + mime_type = "text/html" + disposition = "inline" # Ensure it opens in browser as a webpage + # Check if media + elif mime_type.startswith(("image/", "video/", "audio/")): disposition = "inline" else: disposition = f"attachment; filename*=UTF-8''{quote(decoded_filename)}"