70 lines
1.6 KiB
Python
70 lines
1.6 KiB
Python
from typing import Annotated
|
|
from fastapi import FastAPI, File, HTTPException
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from vntypes import *
|
|
from utils import *
|
|
from db import VNDB
|
|
|
|
app = FastAPI()
|
|
database = VNDB()
|
|
|
|
origins = [
|
|
"http://localhost",
|
|
"http://localhost:5173",
|
|
]
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
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):
|
|
raise HTTPException(status_code=501, detail="Method is not implemented yet!")
|
|
|
|
|
|
@app.post("/api/posts/{post_id}")
|
|
def new_post(novel: FullNovel):
|
|
print(novel)
|
|
return "yay!"
|
|
|
|
|
|
@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/marks")
|
|
def search_marks(query: Mark):
|
|
return database.search_mark(query)
|
|
|
|
|
|
@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 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)}
|