|
@@ -5,17 +5,7 @@ from fastapi.responses import HTMLResponse, RedirectResponse
|
|
|
from fastapi.templating import Jinja2Templates
|
|
from fastapi.templating import Jinja2Templates
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
|
|
|
|
-# =====================================================================
|
|
|
|
|
-# MODIFICATION START: REMOVED ROOT_PATH
|
|
|
|
|
-# Reason: We removed the `root_path="/patch-manager"` argument.
|
|
|
|
|
-# Because Nginx already strips the prefix before passing traffic to
|
|
|
|
|
-# this container, setting it here was causing FastAPI to double-process
|
|
|
|
|
-# the route and throw internal 404s. Standard FastAPI initialization is best.
|
|
|
|
|
-# =====================================================================
|
|
|
|
|
app = FastAPI()
|
|
app = FastAPI()
|
|
|
-# =====================================================================
|
|
|
|
|
-# MODIFICATION END
|
|
|
|
|
-# =====================================================================
|
|
|
|
|
|
|
|
|
|
# Failsafe: Create the directory inside the container if it somehow gets missed
|
|
# Failsafe: Create the directory inside the container if it somehow gets missed
|
|
|
os.makedirs("static", exist_ok=True)
|
|
os.makedirs("static", exist_ok=True)
|
|
@@ -29,12 +19,23 @@ OVERLAY_DIR = "/srv"
|
|
|
@app.get("/", response_class=HTMLResponse)
|
|
@app.get("/", response_class=HTMLResponse)
|
|
|
async def index(request: Request):
|
|
async def index(request: Request):
|
|
|
files = []
|
|
files = []
|
|
|
|
|
+ dirs = set([""]) # Always include the root directory as an option
|
|
|
if os.path.exists(OVERLAY_DIR):
|
|
if os.path.exists(OVERLAY_DIR):
|
|
|
- for root, dirs, filenames in os.walk(OVERLAY_DIR):
|
|
|
|
|
|
|
+ for root, dirnames, filenames in os.walk(OVERLAY_DIR):
|
|
|
|
|
+ # Calculate the relative directory path
|
|
|
|
|
+ rel_root = os.path.relpath(root, OVERLAY_DIR)
|
|
|
|
|
+ if rel_root != ".":
|
|
|
|
|
+ dirs.add(rel_root)
|
|
|
|
|
+
|
|
|
for filename in filenames:
|
|
for filename in filenames:
|
|
|
rel_path = os.path.relpath(os.path.join(root, filename), OVERLAY_DIR)
|
|
rel_path = os.path.relpath(os.path.join(root, filename), OVERLAY_DIR)
|
|
|
files.append(rel_path)
|
|
files.append(rel_path)
|
|
|
- return templates.TemplateResponse("index.html", {"request": request, "files": sorted(files)})
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return templates.TemplateResponse("index.html", {
|
|
|
|
|
+ "request": request,
|
|
|
|
|
+ "files": sorted(files),
|
|
|
|
|
+ "dirs": sorted(list(dirs)) # Pass the sorted directories to the template dropdown
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
@app.post("/upload")
|
|
@app.post("/upload")
|
|
|
async def upload_file(file: UploadFile = File(...), target_path: str = Form("")):
|
|
async def upload_file(file: UploadFile = File(...), target_path: str = Form("")):
|
|
@@ -44,17 +45,13 @@ async def upload_file(file: UploadFile = File(...), target_path: str = Form(""))
|
|
|
with open(file_location, "wb+") as file_object:
|
|
with open(file_location, "wb+") as file_object:
|
|
|
shutil.copyfileobj(file.file, file_object)
|
|
shutil.copyfileobj(file.file, file_object)
|
|
|
|
|
|
|
|
- # =====================================================================
|
|
|
|
|
- # MODIFICATION START: EXPLICIT NGINX REDIRECTS
|
|
|
|
|
- # Reason: Since we removed root_path, we must explicitly tell the
|
|
|
|
|
- # user's browser to redirect back to the Nginx URL ("/patch-manager/")
|
|
|
|
|
- # after a successful action, otherwise it redirects to the internal "/"
|
|
|
|
|
- # and gets lost on the main ArduPilot page.
|
|
|
|
|
- # =====================================================================
|
|
|
|
|
return RedirectResponse(url="/patch-manager/", status_code=303)
|
|
return RedirectResponse(url="/patch-manager/", status_code=303)
|
|
|
- # =====================================================================
|
|
|
|
|
- # MODIFICATION END
|
|
|
|
|
- # =====================================================================
|
|
|
|
|
|
|
+
|
|
|
|
|
+@app.post("/create_folder")
|
|
|
|
|
+async def create_folder(folder_path: str = Form(...)):
|
|
|
|
|
+ save_dir = os.path.join(OVERLAY_DIR, folder_path.strip("/"))
|
|
|
|
|
+ os.makedirs(save_dir, exist_ok=True)
|
|
|
|
|
+ return RedirectResponse(url="/patch-manager/", status_code=303)
|
|
|
|
|
|
|
|
@app.post("/delete")
|
|
@app.post("/delete")
|
|
|
async def delete_file(filepath: str = Form(...)):
|
|
async def delete_file(filepath: str = Form(...)):
|