From 3525abf99fa3e6f41028cb7e93c8e58eb3f0a9c6 Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Thu, 18 Jun 2026 15:45:40 +0800 Subject: initial commit working --- __pycache__/main.cpython-314.pyc | Bin 0 -> 2884 bytes index.html | 19 ++++++++++++ main.py | 64 +++++++++++++++++++++++++++++++++++++++ script.js | 0 style.css | 0 5 files changed, 83 insertions(+) create mode 100644 __pycache__/main.cpython-314.pyc create mode 100644 index.html create mode 100644 main.py create mode 100644 script.js create mode 100644 style.css diff --git a/__pycache__/main.cpython-314.pyc b/__pycache__/main.cpython-314.pyc new file mode 100644 index 0000000..933130a Binary files /dev/null and b/__pycache__/main.cpython-314.pyc differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..8736890 --- /dev/null +++ b/index.html @@ -0,0 +1,19 @@ + + + + + + + + altaf-files + + + +
+ {{content}} +
+ + diff --git a/main.py b/main.py new file mode 100644 index 0000000..dae6661 --- /dev/null +++ b/main.py @@ -0,0 +1,64 @@ +import fastapi +from fastapi.middleware.cors import CORSMiddleware +import fastapi.staticfiles +import fastapi.responses +from pydantic import BaseModel +from pathlib import Path +import os +import html + +print("Hello, world!") + +FOLDER_PATH = Path("/Users/altaf/").resolve() +# FOLDER_PATH = "/var/files" + +app = fastapi.FastAPI(title="altaf-files", decscription="altaf-files backend", version="1.0") + +origins = [ + "http://localhost", + "http://localhost:9092", + "https://files.altafcreator.com", +] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + + +@app.get("/{path:path}") +def folder(path: str): + target_path = (FOLDER_PATH / path).resolve() + + if FOLDER_PATH not in target_path.parents and target_path != FOLDER_PATH: + return fastapi.responses.Response(status_code=403, content="Access denied.") + + is_file = False + + if target_path.is_file(): + is_file = True + return fastapi.responses.FileResponse(target_path) + elif not target_path.is_dir(): + return fastapi.responses.Response(status_code=404) + + content = f"

/{path}

../
" + + for item in sorted(target_path.iterdir()): + safe_child_path = html.escape(item.name) + + href_path = "" + if path == "": + href_path = f"/{safe_child_path}" + else: + href_path = f"/{path.rstrip('/')}/{safe_child_path}" + + filetype_string = "📂" + if (target_path / safe_child_path).resolve().is_file(): + filetype_string = "📄" + + content += f"{filetype_string} {safe_child_path}
" + + return fastapi.responses.Response(content=content, media_type="text/html", status_code=200) diff --git a/script.js b/script.js new file mode 100644 index 0000000..e69de29 diff --git a/style.css b/style.css new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3