File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
examples/as_app/to_gif/lib Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change 3
3
import tempfile
4
4
from contextlib import asynccontextmanager
5
5
from os import path
6
+ from typing import Annotated
6
7
7
8
import cv2
8
9
import imageio
9
10
import numpy
10
- from fastapi import BackgroundTasks , FastAPI
11
+ from fastapi import BackgroundTasks , Depends , FastAPI
11
12
from pygifsicle import optimize
12
13
from requests import Response
13
14
16
17
AppAPIAuthMiddleware ,
17
18
LogLvl ,
18
19
UiActionFileInfo ,
20
+ nc_app ,
19
21
run_app ,
20
22
set_handlers ,
21
23
)
@@ -31,8 +33,7 @@ async def lifespan(app: FastAPI):
31
33
APP .add_middleware (AppAPIAuthMiddleware )
32
34
33
35
34
- def convert_video_to_gif (input_file : FsNode ):
35
- nc = NextcloudApp ()
36
+ def convert_video_to_gif (input_file : FsNode , nc : NextcloudApp ):
36
37
save_path = path .splitext (input_file .user_path )[0 ] + ".gif"
37
38
nc .log (LogLvl .WARNING , f"Processing:{ input_file .user_path } -> { save_path } " )
38
39
try :
@@ -77,9 +78,10 @@ def convert_video_to_gif(input_file: FsNode):
77
78
@APP .post ("/video_to_gif" )
78
79
async def video_to_gif (
79
80
file : UiActionFileInfo ,
81
+ nc : Annotated [NextcloudApp , Depends (nc_app )],
80
82
background_tasks : BackgroundTasks ,
81
83
):
82
- background_tasks .add_task (convert_video_to_gif , file .to_fs_node ())
84
+ background_tasks .add_task (convert_video_to_gif , file .to_fs_node (), nc )
83
85
return Response ()
84
86
85
87
You can’t perform that action at this time.
0 commit comments