25
25
FrameMetricsResponse , FrameImageLinkResponse , FrameStateResponse ,
26
26
FrameAssetsResponse , FrameCreateRequest , FrameUpdateRequest
27
27
)
28
- from app .api .auth import ALGORITHM , SECRET_KEY , get_current_user
28
+ from app .api .auth import ALGORITHM , SECRET_KEY
29
29
from app .utils .network import is_safe_host
30
30
from app .redis import get_redis
31
- from . import private_api , public_api
31
+ from app .config import Config , get_config
32
+ from . import api_with_auth , api_no_auth
32
33
33
34
34
- @private_api .get ("/frames" , response_model = FramesListResponse )
35
+ @api_with_auth .get ("/frames" , response_model = FramesListResponse )
35
36
async def api_frames_list (db : Session = Depends (get_db )):
36
37
frames = db .query (Frame ).all ()
37
38
frames_list = [frame .to_dict () for frame in frames ]
38
39
return {"frames" : frames_list }
39
40
40
41
41
- @private_api .get ("/frames/{id:int}" , response_model = FrameResponse )
42
+ @api_with_auth .get ("/frames/{id:int}" , response_model = FrameResponse )
42
43
async def api_frame_get (id : int , db : Session = Depends (get_db )):
43
44
frame = db .get (Frame , id )
44
45
if frame is None :
45
46
raise HTTPException (status_code = HTTPStatus .NOT_FOUND , detail = "Frame not found" )
46
47
return {"frame" : frame .to_dict ()}
47
48
48
49
49
- @private_api .get ("/frames/{id:int}/logs" , response_model = FrameLogsResponse )
50
+ @api_with_auth .get ("/frames/{id:int}/logs" , response_model = FrameLogsResponse )
50
51
async def api_frame_get_logs (id : int , db : Session = Depends (get_db )):
51
52
frame = db .get (Frame , id )
52
53
if frame is None :
@@ -55,8 +56,8 @@ async def api_frame_get_logs(id: int, db: Session = Depends(get_db)):
55
56
return {"logs" : logs }
56
57
57
58
58
- @private_api .get ("/frames/{id:int}/image_link" , response_model = FrameImageLinkResponse )
59
- async def get_image_link (id : int , user = Depends (get_current_user )):
59
+ @api_with_auth .get ("/frames/{id:int}/image_link" , response_model = FrameImageLinkResponse )
60
+ async def get_image_link (id : int , config : Config = Depends (get_config )):
60
61
expire_minutes = 5
61
62
now = datetime .utcnow ()
62
63
expire = now + timedelta (minutes = expire_minutes )
@@ -66,11 +67,11 @@ async def get_image_link(id: int, user=Depends(get_current_user)):
66
67
expires_in = int ((expire - now ).total_seconds ())
67
68
68
69
return {
69
- "url" : f"/api/frames/{ id } /image?token={ token } " ,
70
+ "url" : config . base_path + f"/api/frames/{ id } /image?token={ token } " ,
70
71
"expires_in" : expires_in
71
72
}
72
73
73
- @public_api .get ("/frames/{id:int}/image" )
74
+ @api_no_auth .get ("/frames/{id:int}/image" )
74
75
async def api_frame_get_image (id : int , token : str , request : Request , db : Session = Depends (get_db ), redis : Redis = Depends (get_redis )):
75
76
try :
76
77
payload = jwt .decode (token , SECRET_KEY , algorithms = [ALGORITHM ])
@@ -109,7 +110,7 @@ async def api_frame_get_image(id: int, token: str, request: Request, db: Session
109
110
raise HTTPException (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = str (e ))
110
111
111
112
112
- @private_api .get ("/frames/{id:int}/state" , response_model = FrameStateResponse )
113
+ @api_with_auth .get ("/frames/{id:int}/state" , response_model = FrameStateResponse )
113
114
async def api_frame_get_state (id : int , db : Session = Depends (get_db ), redis : Redis = Depends (get_redis )):
114
115
frame = db .get (Frame , id )
115
116
if frame is None :
@@ -145,7 +146,7 @@ async def api_frame_get_state(id: int, db: Session = Depends(get_db), redis: Red
145
146
raise HTTPException (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = str (e ))
146
147
147
148
148
- @private_api .post ("/frames/{id:int}/event/{event}" )
149
+ @api_with_auth .post ("/frames/{id:int}/event/{event}" )
149
150
async def api_frame_event (id : int , event : str , request : Request , db : Session = Depends (get_db )):
150
151
frame = db .get (Frame , id )
151
152
if frame is None :
@@ -177,7 +178,7 @@ async def api_frame_event(id: int, event: str, request: Request, db: Session = D
177
178
raise HTTPException (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = str (e ))
178
179
179
180
180
- @private_api .get ("/frames/{id:int}/scene_source/{scene}" )
181
+ @api_with_auth .get ("/frames/{id:int}/scene_source/{scene}" )
181
182
async def api_frame_scene_source (id : int , scene : str , db : Session = Depends (get_db )):
182
183
frame = db .get (Frame , id )
183
184
if frame is None :
@@ -189,7 +190,7 @@ async def api_frame_scene_source(id: int, scene: str, db: Session = Depends(get_
189
190
raise HTTPException (status_code = HTTPStatus .NOT_FOUND , detail = f"Scene { scene } not found" )
190
191
191
192
192
- @private_api .get ("/frames/{id:int}/assets" , response_model = FrameAssetsResponse )
193
+ @api_with_auth .get ("/frames/{id:int}/assets" , response_model = FrameAssetsResponse )
193
194
async def api_frame_get_assets (id : int , db : Session = Depends (get_db ), redis : Redis = Depends (get_redis )):
194
195
frame = db .get (Frame , id )
195
196
if frame is None :
@@ -216,7 +217,7 @@ async def api_frame_get_assets(id: int, db: Session = Depends(get_db), redis: Re
216
217
return {"assets" : assets }
217
218
218
219
219
- @private_api .get ("/frames/{id:int}/asset" )
220
+ @api_with_auth .get ("/frames/{id:int}/asset" )
220
221
async def api_frame_get_asset (id : int , request : Request , db : Session = Depends (get_db ), redis : Redis = Depends (get_redis )):
221
222
frame = db .get (Frame , id )
222
223
if frame is None :
@@ -279,7 +280,7 @@ async def api_frame_get_asset(id: int, request: Request, db: Session = Depends(g
279
280
raise HTTPException (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = str (e ))
280
281
281
282
282
- @private_api .post ("/frames/{id:int}/reset" )
283
+ @api_with_auth .post ("/frames/{id:int}/reset" )
283
284
async def api_frame_reset_event (id : int , redis : Redis = Depends (get_redis )):
284
285
try :
285
286
from app .tasks import reset_frame
@@ -289,7 +290,7 @@ async def api_frame_reset_event(id: int, redis: Redis = Depends(get_redis)):
289
290
raise HTTPException (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = str (e ))
290
291
291
292
292
- @private_api .post ("/frames/{id:int}/restart" )
293
+ @api_with_auth .post ("/frames/{id:int}/restart" )
293
294
async def api_frame_restart_event (id : int , redis : Redis = Depends (get_redis )):
294
295
try :
295
296
from app .tasks import restart_frame
@@ -299,7 +300,7 @@ async def api_frame_restart_event(id: int, redis: Redis = Depends(get_redis)):
299
300
raise HTTPException (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = str (e ))
300
301
301
302
302
- @private_api .post ("/frames/{id:int}/stop" )
303
+ @api_with_auth .post ("/frames/{id:int}/stop" )
303
304
async def api_frame_stop_event (id : int , redis : Redis = Depends (get_redis )):
304
305
try :
305
306
from app .tasks import stop_frame
@@ -309,7 +310,7 @@ async def api_frame_stop_event(id: int, redis: Redis = Depends(get_redis)):
309
310
raise HTTPException (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = str (e ))
310
311
311
312
312
- @private_api .post ("/frames/{id:int}/deploy" )
313
+ @api_with_auth .post ("/frames/{id:int}/deploy" )
313
314
async def api_frame_deploy_event (id : int , redis : Redis = Depends (get_redis )):
314
315
try :
315
316
from app .tasks import deploy_frame
@@ -319,7 +320,7 @@ async def api_frame_deploy_event(id: int, redis: Redis = Depends(get_redis)):
319
320
raise HTTPException (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = str (e ))
320
321
321
322
322
- @private_api .post ("/frames/{id:int}" )
323
+ @api_with_auth .post ("/frames/{id:int}" )
323
324
async def api_frame_update_endpoint (
324
325
id : int ,
325
326
data : FrameUpdateRequest ,
@@ -356,7 +357,7 @@ async def api_frame_update_endpoint(
356
357
return {"message" : "Frame updated successfully" }
357
358
358
359
359
- @private_api .post ("/frames/new" , response_model = FrameResponse )
360
+ @api_with_auth .post ("/frames/new" , response_model = FrameResponse )
360
361
async def api_frame_new (data : FrameCreateRequest , db : Session = Depends (get_db ), redis : Redis = Depends (get_redis )):
361
362
try :
362
363
frame = await new_frame (db , redis , data .name , data .frame_host , data .server_host , data .device , data .interval )
@@ -365,7 +366,7 @@ async def api_frame_new(data: FrameCreateRequest, db: Session = Depends(get_db),
365
366
raise HTTPException (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = str (e ))
366
367
367
368
368
- @private_api .delete ("/frames/{frame_id}" )
369
+ @api_with_auth .delete ("/frames/{frame_id}" )
369
370
async def api_frame_delete (
370
371
frame_id : int ,
371
372
db : Session = Depends (get_db ),
@@ -378,7 +379,7 @@ async def api_frame_delete(
378
379
raise HTTPException (status_code = 404 , detail = "Frame not found" )
379
380
380
381
381
- @private_api .get ("/frames/{id:int}/metrics" , response_model = FrameMetricsResponse )
382
+ @api_with_auth .get ("/frames/{id:int}/metrics" , response_model = FrameMetricsResponse )
382
383
async def api_frame_metrics (id : int , db : Session = Depends (get_db )):
383
384
frame = db .get (Frame , id )
384
385
if frame is None :
0 commit comments