Mercurial > code > home > repos > video
changeset 20:cf6842952e13
serve api/folderTree
author | drewp@bigasterisk.com |
---|---|
date | Mon, 17 Apr 2023 00:42:59 -0700 |
parents | f0a773084a2e |
children | 111a41817968 |
files | video.py video_file_store.py |
diffstat | 2 files changed, 25 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/video.py Mon Apr 17 00:42:27 2023 -0700 +++ b/video.py Mon Apr 17 00:42:59 2023 -0700 @@ -38,6 +38,10 @@ }) +def folderTree(req: Request) -> JSONResponse: + return JSONResponse(store.folderTree()) + + async def ingestVideoUrl(req: Request) -> Response: url = await req.body() await svc.ingestUrl(url.decode('utf8')) @@ -70,6 +74,7 @@ routes=[ Route('/video/api/', root), Route('/video/api/videos', videos), + Route('/video/api/folderTree', folderTree), Route('/video/api/ingest/videoUpload', ingestVideoUpload, methods=['POST']),
--- a/video_file_store.py Mon Apr 17 00:42:27 2023 -0700 +++ b/video_file_store.py Mon Apr 17 00:42:59 2023 -0700 @@ -1,10 +1,13 @@ import asyncio import hashlib import re +import os from dataclasses import dataclass from pathlib import Path from typing import Iterable, Iterator, NewType +IGNORE = {'_thumb'} + @dataclass class VideoFile: @@ -43,7 +46,7 @@ if subdir[0] != '/': raise ValueError here = self.top / subdir[1:] for p in here.iterdir(): - if p.is_dir() and p.name not in {'_thumb'}: + if p.is_dir() and p.name not in IGNORE: yield { 'label': p.name, 'path': '/' + str(p.relative_to(self.top)) @@ -74,3 +77,19 @@ for c in chunks: data += c p.write_bytes(data) + + def folderTree(self): + out = {'name': 'TOP'} + + def fill(node: dict, pathToHere: Path): + for subName in sorted(os.listdir(pathToHere)): + if subName in IGNORE: + continue + subDir = pathToHere / subName + if subDir.is_dir(): + subNode = {'name': subName} + node.setdefault('children', []).append(subNode) + fill(subNode, subDir) + + fill(out, self.top) + return out \ No newline at end of file