From a88a1a3e95119475288354a5ddb472508f3a5911 Mon Sep 17 00:00:00 2001 From: Daoud Clarke Date: Mon, 19 Dec 2022 21:51:26 +0000 Subject: [PATCH] Rename some parameters; return curation ID --- mwmbl/main.py | 9 +++++++++ mwmbl/platform/user.py | 14 +++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/mwmbl/main.py b/mwmbl/main.py index fa5e1c5..dcc64f5 100644 --- a/mwmbl/main.py +++ b/mwmbl/main.py @@ -7,6 +7,7 @@ from pathlib import Path import uvicorn from fastapi import FastAPI +from starlette.middleware.cors import CORSMiddleware from mwmbl import background from mwmbl.crawler import app as crawler @@ -66,6 +67,14 @@ def run(): # Initialize FastApi instance app = FastAPI() + app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], + ) + search_router = search.create_router(ranker) app.include_router(search_router) diff --git a/mwmbl/platform/user.py b/mwmbl/platform/user.py index 23fd6d2..678218d 100644 --- a/mwmbl/platform/user.py +++ b/mwmbl/platform/user.py @@ -36,16 +36,16 @@ class Curation(BaseModel): class CurateMove(Curation): - url_old_index: int - url_new_index: int + old_index: int + new_index: int class CurateDelete(Curation): - url_delete_index: int + delete_index: int class CurateAdd(Curation): - url_insert_index: int + insert_index: int url: str @@ -91,7 +91,11 @@ def create_router() -> APIRouter: "url": url, } request = requests.post(urljoin(LEMMY_URL, "api/v3/post"), json=create_post) - return Response(content=request.content, status_code=request.status_code, media_type="text/json") + if request.status_code != 200: + return Response(content=request.content, status_code=request.status_code, media_type="text/json") + data = request.json() + curation_id = data["post_view"]["post"]["id"] + return {"curation_id": curation_id} @router.post("/curation/move") def user_move_result(curate_move: CurateMove):