1
1
import io
2
+ from enum import Enum
2
3
from pathlib import Path
3
4
from typing import Annotated
4
5
11
12
app = FastAPI ()
12
13
13
14
15
+ class Color (str , Enum ):
16
+ BLACK = "B"
17
+ WHITE = "W"
18
+
19
+
14
20
@app .get ("/health_check/" )
15
21
def health_check ():
16
22
return {"message" : "Healthy!" }
17
23
18
24
19
25
@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
+ ):
21
30
output_file = io .StringIO ()
22
- process_image (image .file , output_file )
31
+ process_image (image .file , output_file , to_play )
23
32
output_file .seek (0 )
24
33
return {
25
34
"sgf" : output_file .read (),
@@ -29,10 +38,14 @@ def capture(image: Annotated[UploadFile, File()]):
29
38
30
39
@app .post ("/capture_async/" )
31
40
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 ,
33
44
):
34
45
filename = Path (image .filename )
35
46
output_path = settings .IMAGES_DIR / filename
36
47
with output_path .open ("wb" ) as output_file :
37
48
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