Small cleanups
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
from pathlib import Path
|
||||
from src.config.config import Configuration
|
||||
from src.rendering.renderer import render_page, render_error_page
|
||||
from flask import send_file, request
|
||||
from src.rendering.image import generate_thumbnail
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from flask import request, send_file
|
||||
|
||||
from src.config.config import Configuration
|
||||
from src.rendering.image import generate_thumbnail
|
||||
from src.rendering.renderer import render_error_page, render_page
|
||||
|
||||
|
||||
class RouteManager:
|
||||
@ -32,7 +34,6 @@ class RouteManager:
|
||||
|
||||
for part in secure_path_parts:
|
||||
if part == "." or part == "..":
|
||||
print("Illegal path nice try")
|
||||
return None
|
||||
|
||||
# Reconstruct the secure path
|
||||
@ -45,13 +46,15 @@ class RouteManager:
|
||||
|
||||
for part in secure_path.parts:
|
||||
if part.startswith("___"):
|
||||
print("hidden file")
|
||||
raise Exception("Illegal path")
|
||||
|
||||
return secure_path
|
||||
|
||||
def _ensure_route(self, path: str):
|
||||
file_path: Path = self.config.content_dir / (path if path else "index.md")
|
||||
file_path: Path = self.config.content_dir / path
|
||||
if not path or file_path.is_dir():
|
||||
file_path = file_path / "index.md"
|
||||
|
||||
if file_path < self.config.content_dir:
|
||||
raise Exception("Illegal path")
|
||||
|
||||
@ -70,7 +73,9 @@ class RouteManager:
|
||||
"The requested resource was not found on this server.",
|
||||
self.config.templates_dir,
|
||||
)
|
||||
file_path: Path = self.config.content_dir / (path if path else "index.md")
|
||||
file_path: Path = self.config.content_dir / path
|
||||
if not path or file_path.is_dir():
|
||||
file_path = file_path / "index.md"
|
||||
return render_page(
|
||||
file_path,
|
||||
base_path=self.config.content_dir,
|
||||
@ -120,8 +125,10 @@ class RouteManager:
|
||||
return (
|
||||
thumbnail_bytes,
|
||||
200,
|
||||
{"Content-Type": f"image/{img_format.lower()}",
|
||||
"cache-control": "public, max-age=31536000"},
|
||||
{
|
||||
"Content-Type": f"image/{img_format.lower()}",
|
||||
"cache-control": "public, max-age=31536000",
|
||||
},
|
||||
)
|
||||
return send_file(file_path)
|
||||
else:
|
||||
|
Reference in New Issue
Block a user