Mercurial > code > home > repos > video
annotate video.py @ 5:75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
author | drewp@bigasterisk.com |
---|---|
date | Thu, 30 Mar 2023 20:39:40 -0700 |
parents | c8a41359505c |
children | ccfea3625cf6 |
rev | line source |
---|---|
3 | 1 import logging |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
2 |
3 | 3 from prometheus_client import Gauge |
4 from starlette.applications import Starlette | |
5 from starlette.requests import Request | |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
6 from starlette.responses import HTMLResponse, JSONResponse |
3 | 7 from starlette.routing import Route |
8 from starlette_exporter import PrometheusMiddleware, handle_metrics | |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
9 |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
10 from video_service import findInDir, findSubdirs |
0 | 11 |
3 | 12 logging.basicConfig(level=logging.DEBUG) |
13 log = logging.getLogger() | |
0 | 14 |
15 | |
3 | 16 def root(req): |
17 return HTMLResponse("api") | |
0 | 18 |
19 | |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
20 def videos(req: Request) -> JSONResponse: |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
21 subdir = req.query_params.get('subdir', '/') # danger user input |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
22 return JSONResponse({ |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
23 "videos": [{ |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
24 'webRelPath': vf.webRelPath, |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
25 'label': vf.label, |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
26 } for vf in findInDir(subdir)], |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
27 "subdirs": |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
28 list(findSubdirs(subdir)), |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
29 }) |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
30 |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
31 |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
32 def main(): |
3 | 33 |
34 app = Starlette( | |
35 debug=True, | |
36 routes=[ | |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
37 Route('/video/api/', root), |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
38 Route('/video/api/videos', videos), |
3 | 39 ], |
40 ) | |
41 | |
42 app.add_middleware(PrometheusMiddleware, app_name='video_api') | |
43 app.add_route("/metrics", handle_metrics) | |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
44 return app |
3 | 45 |
46 | |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
3
diff
changeset
|
47 app = main() |