46 lines
No EOL
1.1 KiB
Python
46 lines
No EOL
1.1 KiB
Python
from typing import Annotated
|
|
from fastapi import FastAPI, File, UploadFile
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from pathlib import Path
|
|
|
|
from vntypes import Novel, Mark
|
|
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/posts/{post_id}")
|
|
def get_post(post_id: int):
|
|
return "NOT IMPLEMENTED!"
|
|
|
|
@app.post("/api/new_post")
|
|
def new_post(novel: Novel):
|
|
print(novel)
|
|
return "yay!"
|
|
|
|
@app.post("/api/new_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/screenshot")
|
|
async def screenshot(scrshot: Annotated[bytes, File()], filename: str):
|
|
return {"file_size": save_image(scrshot, "screens", filename)} |