Skip to content

Commit

Permalink
Revert "create on unknown URL request"
Browse files Browse the repository at this point in the history
This reverts commit 8880182.
  • Loading branch information
machado2 committed Jul 1, 2024
1 parent cd574a1 commit 3d21d21
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions app/get_content.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
from uuid import uuid4

import markdown_it
from fastapi import APIRouter, HTTPException, Request, BackgroundTasks
from starlette.responses import HTMLResponse, RedirectResponse
from fastapi import APIRouter, HTTPException, Request
from starlette.responses import HTMLResponse

from app.create import create_article_and_remove_task
from app.models import Content
from app.template import render_template
from app.wait import background_ids

router = APIRouter()

markdown = markdown_it.MarkdownIt()


@router.get("/{slug}", response_class=HTMLResponse)
async def get_content(request: Request, background_tasks: BackgroundTasks, slug: str):
async def get_content(request: Request, slug: str):
content = await Content.filter(slug=slug).first()
if content is None:
identifier = str(uuid4())
background_ids[identifier] = True
background_tasks.add_task(create_article_and_remove_task, identifier, slug)
return RedirectResponse(url=f"/wait/{identifier}", status_code=303)
raise HTTPException(status_code=404, detail="Content not found")
html = markdown.render(content.markdown or "")
return render_template(
"content.html", request,
Expand Down

0 comments on commit 3d21d21

Please sign in to comment.