[+] Dockerize

This commit is contained in:
2024-12-17 01:07:23 -05:00
parent cd97f60b0e
commit 995025286b
5 changed files with 37 additions and 38 deletions
+17
View File
@@ -1,5 +1,6 @@
import json
import random
import tempfile
from fastapi.responses import RedirectResponse
import uvicorn
from subprocess import check_output
@@ -65,6 +66,22 @@ async def get_puzzle(id: str):
return json.loads(tf.read_text())
@app.post("/solve")
async def input_request(request: Request):
body = (await request.body()).decode().replace("\r\n", "\n")
# Write body to a file
with tempfile.TemporaryDirectory() as tmpdir:
tf = Path(tmpdir) / "puzzle.slk"
tf.write_text(body)
# Run the solver (example: ./slsolver mypuzzle.slk)
# Solver is https://github.com/davidjosepha/slitherlink
solver_path = src / "slsolver"
output = check_output([solver_path, str(tf)], cwd=src).decode()
return output
# Getting / redirects to main page
@app.get("/")
async def get_main():