utility object naming
This commit is contained in:
parent
e193410725
commit
ea85164063
4 changed files with 41 additions and 35 deletions
|
@ -13,37 +13,43 @@ from ovdashboard_api.config import Config
|
||||||
|
|
||||||
from ..dav_calendar import CalEvent, DavCalendar
|
from ..dav_calendar import CalEvent, DavCalendar
|
||||||
from ._common import CalAggregateLister, PrefixFinder, PrefixUnique
|
from ._common import CalAggregateLister, PrefixFinder, PrefixUnique
|
||||||
|
from .calendar import calendar_unique
|
||||||
|
|
||||||
router = APIRouter(prefix="/aggregate", tags=["calendar"])
|
router = APIRouter(prefix="/aggregate", tags=["calendar"])
|
||||||
|
|
||||||
_lister = CalAggregateLister()
|
cal_aggregate_lister = CalAggregateLister()
|
||||||
_finder = PrefixFinder(_lister)
|
cal_aggregate_finder = PrefixFinder(cal_aggregate_lister)
|
||||||
_unique = PrefixUnique(_finder)
|
cal_aggregate_unique = PrefixUnique(cal_aggregate_finder)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/list", response_model=list[str])
|
@router.get("/list", response_model=list[str])
|
||||||
async def list_aggregate_calendars(
|
async def list_aggregate_calendars(
|
||||||
names: Iterator[str] = Depends(_lister),
|
names: Iterator[str] = Depends(cal_aggregate_lister),
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
return list(names)
|
return list(names)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/find/{prefix}", response_model=list[str])
|
@router.get("/find/{prefix}", response_model=list[str])
|
||||||
async def find_aggregate_calendars(
|
async def find_aggregate_calendars(
|
||||||
names: Iterator[str] = Depends(_finder),
|
names: Iterator[str] = Depends(cal_aggregate_finder),
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
return list(names)
|
return list(names)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/get/{prefix}", response_model=list[CalEvent])
|
@router.get("/get/{prefix}", response_model=list[CalEvent])
|
||||||
async def get_aggregate_calendar(
|
async def get_aggregate_calendar(
|
||||||
name: Iterator[str] = Depends(_unique),
|
name: str = Depends(cal_aggregate_unique),
|
||||||
) -> list[CalEvent]:
|
) -> list[CalEvent]:
|
||||||
cfg = await Config.get()
|
cfg = await Config.get()
|
||||||
aggregate = cfg.calendar.aggregate[name]
|
aggregate = cfg.calendar.aggregate[name]
|
||||||
|
|
||||||
|
calendars = (
|
||||||
|
DavCalendar(await calendar_unique(cal_prefix))
|
||||||
|
for cal_prefix in aggregate
|
||||||
|
)
|
||||||
|
|
||||||
return sorted([
|
return sorted([
|
||||||
event
|
event
|
||||||
for calendar_name in aggregate
|
async for calendar in calendars
|
||||||
for event in (await DavCalendar(calendar_name).events)
|
for event in (await calendar.events)
|
||||||
])
|
])
|
||||||
|
|
|
@ -15,27 +15,27 @@ from ._common import CalendarNameLister, PrefixFinder, PrefixUnique
|
||||||
|
|
||||||
router = APIRouter(prefix="/calendar", tags=["calendar"])
|
router = APIRouter(prefix="/calendar", tags=["calendar"])
|
||||||
|
|
||||||
_lister = CalendarNameLister()
|
calendar_lister = CalendarNameLister()
|
||||||
_finder = PrefixFinder(_lister)
|
calendar_finder = PrefixFinder(calendar_lister)
|
||||||
_unique = PrefixUnique(_finder)
|
calendar_unique = PrefixUnique(calendar_finder)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/list", response_model=list[str])
|
@router.get("/list", response_model=list[str])
|
||||||
async def list_calendars(
|
async def list_calendars(
|
||||||
names: Iterator[str] = Depends(_lister),
|
names: Iterator[str] = Depends(calendar_lister),
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
return list(names)
|
return list(names)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/find/{prefix}", response_model=list[str])
|
@router.get("/find/{prefix}", response_model=list[str])
|
||||||
async def find_calendars(
|
async def find_calendars(
|
||||||
names: Iterator[str] = Depends(_finder),
|
names: Iterator[str] = Depends(calendar_finder),
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
return list(names)
|
return list(names)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/get/{prefix}", response_model=list[CalEvent])
|
@router.get("/get/{prefix}", response_model=list[CalEvent])
|
||||||
async def get_calendar(
|
async def get_calendar(
|
||||||
name: str = Depends(_unique),
|
name: str = Depends(calendar_unique),
|
||||||
) -> list[CalEvent]:
|
) -> list[CalEvent]:
|
||||||
return list(await DavCalendar(name).events)
|
return list(await DavCalendar(name).events)
|
||||||
|
|
|
@ -20,7 +20,7 @@ from ._common import FileNameLister, PrefixFinder, PrefixUnique
|
||||||
|
|
||||||
router = APIRouter(prefix="/image", tags=["image"])
|
router = APIRouter(prefix="/image", tags=["image"])
|
||||||
|
|
||||||
_lister = FileNameLister(
|
image_lister = FileNameLister(
|
||||||
remote_path="img",
|
remote_path="img",
|
||||||
re=re.compile(
|
re=re.compile(
|
||||||
r"\.(gif|jpe?g|tiff?|png|bmp)$",
|
r"\.(gif|jpe?g|tiff?|png|bmp)$",
|
||||||
|
@ -28,17 +28,17 @@ _lister = FileNameLister(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
_finder = PrefixFinder(_lister)
|
image_finder = PrefixFinder(image_lister)
|
||||||
_unique = PrefixUnique(_finder)
|
image_unique = PrefixUnique(image_finder)
|
||||||
|
|
||||||
|
|
||||||
@router.get(
|
@router.get(
|
||||||
"/list",
|
"/list",
|
||||||
response_model=list[str],
|
response_model=list[str],
|
||||||
responses=_lister.responses,
|
responses=image_lister.responses,
|
||||||
)
|
)
|
||||||
async def list_images(
|
async def list_images(
|
||||||
names: Iterator[str] = Depends(_lister),
|
names: Iterator[str] = Depends(image_lister),
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
return list(names)
|
return list(names)
|
||||||
|
|
||||||
|
@ -46,10 +46,10 @@ async def list_images(
|
||||||
@router.get(
|
@router.get(
|
||||||
"/find/{prefix}",
|
"/find/{prefix}",
|
||||||
response_model=list[str],
|
response_model=list[str],
|
||||||
responses=_finder.responses,
|
responses=image_finder.responses,
|
||||||
)
|
)
|
||||||
async def find_images(
|
async def find_images(
|
||||||
names: Iterator[str] = Depends(_finder),
|
names: Iterator[str] = Depends(image_finder),
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
return list(names)
|
return list(names)
|
||||||
|
|
||||||
|
@ -57,15 +57,15 @@ async def find_images(
|
||||||
@router.get(
|
@router.get(
|
||||||
"/get/{prefix}",
|
"/get/{prefix}",
|
||||||
response_class=StreamingResponse,
|
response_class=StreamingResponse,
|
||||||
responses=_unique.responses,
|
responses=image_unique.responses,
|
||||||
)
|
)
|
||||||
async def get_image(
|
async def get_image(
|
||||||
prefix: str,
|
prefix: str,
|
||||||
name: str = Depends(_unique),
|
name: str = Depends(image_unique),
|
||||||
) -> str:
|
) -> str:
|
||||||
cfg = await Config.get()
|
cfg = await Config.get()
|
||||||
|
|
||||||
dav_file = DavFile(f"{_lister.remote_path}/{name}")
|
dav_file = DavFile(f"{image_lister.remote_path}/{name}")
|
||||||
img = Image.open(
|
img = Image.open(
|
||||||
BytesIO(await dav_file.bytes)
|
BytesIO(await dav_file.bytes)
|
||||||
).convert(
|
).convert(
|
||||||
|
|
|
@ -21,7 +21,7 @@ from ._common import FileNameLister, PrefixFinder, PrefixUnique
|
||||||
|
|
||||||
router = APIRouter(prefix="/text", tags=["text"])
|
router = APIRouter(prefix="/text", tags=["text"])
|
||||||
|
|
||||||
_lister = FileNameLister(
|
text_lister = FileNameLister(
|
||||||
remote_path="text",
|
remote_path="text",
|
||||||
re=re.compile(
|
re=re.compile(
|
||||||
r"\.(txt|md)$",
|
r"\.(txt|md)$",
|
||||||
|
@ -29,8 +29,8 @@ _lister = FileNameLister(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
_finder = PrefixFinder(_lister)
|
text_finder = PrefixFinder(text_lister)
|
||||||
_unique = PrefixUnique(_finder)
|
text_unique = PrefixUnique(text_finder)
|
||||||
|
|
||||||
|
|
||||||
async def get_ticker_lines() -> Iterator[str]:
|
async def get_ticker_lines() -> Iterator[str]:
|
||||||
|
@ -82,10 +82,10 @@ async def get_raw_ticker(
|
||||||
@router.get(
|
@router.get(
|
||||||
"/list",
|
"/list",
|
||||||
response_model=list[str],
|
response_model=list[str],
|
||||||
responses=_lister.responses,
|
responses=text_lister.responses,
|
||||||
)
|
)
|
||||||
async def list_texts(
|
async def list_texts(
|
||||||
names: Iterator[str] = Depends(_lister),
|
names: Iterator[str] = Depends(text_lister),
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
return list(names)
|
return list(names)
|
||||||
|
|
||||||
|
@ -93,24 +93,24 @@ async def list_texts(
|
||||||
@router.get(
|
@router.get(
|
||||||
"/find/{prefix}",
|
"/find/{prefix}",
|
||||||
response_model=list[str],
|
response_model=list[str],
|
||||||
responses=_finder.responses,
|
responses=text_finder.responses,
|
||||||
)
|
)
|
||||||
async def find_texts(
|
async def find_texts(
|
||||||
names: Iterator[str] = Depends(_finder),
|
names: Iterator[str] = Depends(text_finder),
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
return list(names)
|
return list(names)
|
||||||
|
|
||||||
|
|
||||||
async def get_text_content(
|
async def get_text_content(
|
||||||
name: str = Depends(_unique),
|
name: str = Depends(text_unique),
|
||||||
) -> str:
|
) -> str:
|
||||||
return await DavFile(f"{_lister.remote_path}/{name}").string
|
return await DavFile(f"{text_lister.remote_path}/{name}").string
|
||||||
|
|
||||||
|
|
||||||
@router.get(
|
@router.get(
|
||||||
"/get/html/{prefix}",
|
"/get/html/{prefix}",
|
||||||
response_model=str,
|
response_model=str,
|
||||||
responses=_unique.responses,
|
responses=text_unique.responses,
|
||||||
)
|
)
|
||||||
async def get_text(
|
async def get_text(
|
||||||
text: str = Depends(get_text_content),
|
text: str = Depends(get_text_content),
|
||||||
|
@ -121,7 +121,7 @@ async def get_text(
|
||||||
@router.get(
|
@router.get(
|
||||||
"/get/raw/{prefix}",
|
"/get/raw/{prefix}",
|
||||||
response_model=str,
|
response_model=str,
|
||||||
responses=_unique.responses,
|
responses=text_unique.responses,
|
||||||
)
|
)
|
||||||
async def get_raw_text(
|
async def get_raw_text(
|
||||||
text: str = Depends(get_text_content),
|
text: str = Depends(get_text_content),
|
||||||
|
|
Loading…
Reference in a new issue