generated from justuser-31/mrl_v1_license
Расширение возможностей CDN (+HTML)
This commit is contained in:
parent
5e42798d14
commit
23ddda7555
@ -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
|
||||
|
||||
13
handlers.py
13
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("<h1>File not found</h1>", 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)}"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user