reformat
This commit is contained in:
parent
6a3638438a
commit
607213f1c4
2 changed files with 12 additions and 6 deletions
|
@ -104,14 +104,17 @@ async def upload(
|
||||||
detail = "File is already in the archive"
|
detail = "File is already in the archive"
|
||||||
raise HTTPException(status_code=400, detail=detail)
|
raise HTTPException(status_code=400, detail=detail)
|
||||||
conn.refresh(orig)
|
conn.refresh(orig)
|
||||||
data = {"id": orig.id, "path": orig.filepath,
|
data = {
|
||||||
"url": CONFIG['public']['baseurl'] + "/dl/" + orig.filepath
|
"id": orig.id,
|
||||||
}
|
"path": orig.filepath,
|
||||||
|
"url": CONFIG["public"]["baseurl"] + "/dl/" + orig.filepath,
|
||||||
|
}
|
||||||
if "application/json" in request.headers.get("accept", ""):
|
if "application/json" in request.headers.get("accept", ""):
|
||||||
return data
|
return data
|
||||||
else:
|
else:
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
name="ok.html", request=request, context=data)
|
name="ok.html", request=request, context=data
|
||||||
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
Path(temp.name).unlink()
|
Path(temp.name).unlink()
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -49,8 +49,11 @@ async def get_file(path: str):
|
||||||
final_path = Path(CONFIG["general"]["files"]) / original.filepath
|
final_path = Path(CONFIG["general"]["files"]) / original.filepath
|
||||||
if final_path.exists():
|
if final_path.exists():
|
||||||
return FileResponse(
|
return FileResponse(
|
||||||
# XXX: avoid it being an attachment
|
# XXX: avoid it being an attachment
|
||||||
final_path, media_type=original.mime, filename=original.name
|
final_path,
|
||||||
|
media_type=original.mime,
|
||||||
|
filename=original.name,
|
||||||
|
headers={"X-sha256": original.sha256},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return 404
|
return 404
|
||||||
|
|
Loading…
Reference in a new issue