[image-service] Add middleware prefix
This commit is contained in:
parent
cb6261472a
commit
5faebd423f
2 changed files with 22 additions and 4 deletions
22
main.py
22
main.py
|
|
@ -1,4 +1,4 @@
|
|||
from fastapi import FastAPI, UploadFile, File, HTTPException, Query
|
||||
from fastapi import FastAPI, UploadFile, File, HTTPException, Query, Request
|
||||
from fastapi.responses import FileResponse
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
|
@ -39,6 +39,23 @@ ALLOWED_FOLDERS = {"page_drink",
|
|||
|
||||
ALLOWED_EXTENSIONS = {".jpg", ".jpeg", ".png", ".gif", ".webp"}
|
||||
|
||||
@app.middleware("http")
|
||||
async def strip_prefix_middleware(request: Request, call_next):
|
||||
path = request.scope["path"]
|
||||
|
||||
if path.startswith(PREFIX):
|
||||
new_path = path[len(PREFIX):]
|
||||
|
||||
if not new_path:
|
||||
new_path = "/"
|
||||
|
||||
request.scope["path"] = new_path
|
||||
|
||||
print(f"[Middleware] {path} -> {new_path}")
|
||||
|
||||
response = await call_next(request)
|
||||
return response
|
||||
|
||||
def validate_folder(folder: str):
|
||||
if folder not in ALLOWED_FOLDERS:
|
||||
raise HTTPException(400, f"folder must be {ALLOWED_FOLDERS}")
|
||||
|
|
@ -308,7 +325,8 @@ async def commit_files_to_git(
|
|||
commit_data = {
|
||||
"signature_username": display_name,
|
||||
"signature_email": email,
|
||||
"message": f"commit {folder} {country}"
|
||||
"message": f"commit {folder} {country}",
|
||||
"ref": SERVICE_NAME
|
||||
}
|
||||
|
||||
multipart_files = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue