backend: complete file uploading

This commit is contained in:
OleSTEEP 2025-10-05 20:18:05 +03:00
parent da077519fe
commit 23a00d2c06
3 changed files with 51 additions and 15 deletions

View file

@ -1,9 +1,8 @@
from typing import Annotated
from fastapi import FastAPI, File, UploadFile
from fastapi import FastAPI, File, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pathlib import Path
from vntypes import Novel, Mark
from vntypes import *
from utils import *
from db import VNDB
@ -23,24 +22,49 @@ app.add_middleware(
allow_headers=["*"],
)
@app.get("/api/queue")
def get_post_queue() -> list[FullNovel]:
raise HTTPException(status_code=501, detail="Method is not implemented yet!")
@app.get("/api/posts/{post_id}")
def get_post(post_id: int):
return "NOT IMPLEMENTED!"
raise HTTPException(status_code=501, detail="Method is not implemented yet!")
@app.post("/api/new_post")
def new_post(novel: Novel):
@app.post("/api/posts/{post_id}")
def new_post(novel: FullNovel):
print(novel)
return "yay!"
@app.post("/api/new_mark")
@app.patch("/api/posts/{post_id}")
def edit_post(novel: FullNovel):
print(novel)
return "yay!"
@app.post("/api/mark")
def new_mark(mark: Mark):
database.insert_mark(mark.type, mark.value)
return "yay!"
@app.post("/api/novel_thumb")
async def novel_thumb(thumb: Annotated[bytes, File()], filename: str):
return {"file_size": len(thumb)}
@app.post("/api/marks")
def search_marks(part: str):
raise HTTPException(status_code=501, detail="Method is not implemented yet!")
@app.post("/api/thumb")
async def upload_thumb(thumb: Annotated[bytes, File()], filename: str):
return {"file_size": save_image(thumb, "thumbs", filename)}
@app.post("/api/screenshot")
async def screenshot(scrshot: Annotated[bytes, File()], filename: str):
return {"file_size": save_image(scrshot, "screens", filename)}
async def upload_screenshot(scrshot: Annotated[bytes, File()], filename: str):
return {"file_size": save_image(scrshot, "screens", filename)}
@app.post("/api/file")
async def upload_file(file: Annotated[bytes, File()], filename: str):
return {"file_size": save_file(file, "files", filename)}