10000 Add to_play query parameter · codeguru42/go-capture-api@9d2e57b · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d2e57b

Browse files
committed
Add to_play query parameter
1 parent 2245448 commit 9d2e57b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

main.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
from enum import Enum
23
from pathlib import Path
34
from typing import Annotated
45

@@ -11,15 +12,23 @@
1112
app = FastAPI()
1213

1314

15+
class Color(str, Enum):
16+
BLACK = "B"
17+
WHITE = "W"
18+
19+
1420
@app.get("/health_check/")
1521
def health_check():
1622
return {"message": "Healthy!"}
1723

1824

1925
@app.post("/capture/")
20-
def capture(image: Annotated[UploadFile, File()]):
26+
def capture(
27+
image: Annotated[UploadFile, File()],
28+
to_play: Annotated[Color, Form()] = Color.BLACK,
29+
):
2130
output_file = io.StringIO()
22-
process_image(image.file, output_file)
31+
process_image(image.file, output_file, to_play)
2332
output_file.seek(0)
2433
return {
2534
"sgf": output_file.read(),
@@ -29,10 +38,14 @@ def capture(image: Annotated[UploadFile, File()]):
2938

3039
@app.post("/capture_async/")
3140
def capture_async(
32-
image: Annotated[UploadFile, File()], fcm_registration_token: Annotated[str, Form()]
41+
image: Annotated[UploadFile, File()],
42+
fcm_registration_token: Annotated[str, Form()],
43+
to_play: Annotated[Color, Form()] = Color.BLACK,
3344
):
3445
filename = Path(image.filename)
3546
output_path = settings.IMAGES_DIR / filename
3647
with output_path.open("wb") as output_file:
3748
output_file.write(image.file.read())
38-
process_image_task.delay(str(output_path.absolute()), fcm_registration_token)
49+
process_image_task.delay(
50+
str(output_path.absolute()), fcm_registration_token, to_play
51+
)

0 commit comments

Comments
 (0)
0