Skip to content

Commit

Permalink
init admin changes for HTTP prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie Taylor committed Oct 29, 2024
1 parent 2b0d056 commit 5e5d428
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 13 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ def set_winner(pic_id: int, password: Annotated[str | None, Cookie()] = None):

raise HTTPException(status_code=404, detail="Pic not found")

@app.post("/prompt")
async def create_prompt(request: Request, password: Annotated[str | None, Cookie()] = None) -> RedirectResponse:
if not is_logged_in(password):
raise HTTPException(status_code=401, detail="Unauthorized")

body = await request.form()
prompt = str(body.get("prompt"))
if prompt is None:
raise HTTPException(status_code=400, detail="No prompt provided")

db.create_prompt(prompt)

return RedirectResponse(url="/admin", status_code=303)

def is_logged_in(password: str | None):
return password is not None and password == settings.admin_pass
7 changes: 3 additions & 4 deletions templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ <h1>Admin Shit</h1>
</header>
<main class="container">
<section>
<div class="grid">
<form action="/prompt" method="post" class="grid">
<input type="text" id="prompt" placeholder="Send prompt" name="prompt" />
<button type="submit">Send</button>
</div>
<input type="submit" value="Send"></input>
</form>
</section>
<section>
<h2>Editor's Choice</h2>
Expand All @@ -33,7 +33,6 @@ <h2>Editor's Choice</h2>
</li>
{% endfor %}
</ul>

</section>
</main>
<footer class="container">
Expand Down

0 comments on commit 5e5d428

Please sign in to comment.