HTTP 404 if directory doesn't exist
This commit is contained in:
parent
972551d170
commit
d8ca1da9cb
3 changed files with 50 additions and 8 deletions
|
@ -14,11 +14,28 @@ class NameLister(Protocol):
|
|||
...
|
||||
|
||||
|
||||
_RESPONSE_OK = {
|
||||
status.HTTP_200_OK: {
|
||||
"description": "Operation successful",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class FileNameLister:
|
||||
remote_path: str
|
||||
re: re.Pattern[str]
|
||||
|
||||
@property
|
||||
def responses(self) -> dict:
|
||||
return {
|
||||
**_RESPONSE_OK,
|
||||
status.HTTP_404_NOT_FOUND: {
|
||||
"description": f"{self.remote_path!r} not found",
|
||||
"content": None,
|
||||
},
|
||||
}
|
||||
|
||||
async def __call__(self) -> Iterator[str]:
|
||||
try:
|
||||
file_names = await webdav_list(self.remote_path)
|
||||
|
@ -30,7 +47,7 @@ class FileNameLister:
|
|||
)
|
||||
|
||||
except RemoteResourceNotFound:
|
||||
return iter(())
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
@ -46,6 +63,17 @@ class CalendarNameLister:
|
|||
class PrefixFinder:
|
||||
lister: NameLister
|
||||
|
||||
@property
|
||||
def responses(self) -> dict:
|
||||
return {
|
||||
**_RESPONSE_OK,
|
||||
status.HTTP_404_NOT_FOUND: {
|
||||
"description": "Failure in lister " +
|
||||
repr(self.lister.__class__.__name__),
|
||||
"content": None,
|
||||
},
|
||||
}
|
||||
|
||||
async def __call__(self, prefix: str) -> Iterator[str]:
|
||||
return (
|
||||
file_name
|
||||
|
@ -61,9 +89,7 @@ class PrefixUnique:
|
|||
@property
|
||||
def responses(self) -> dict:
|
||||
return {
|
||||
status.HTTP_200_OK: {
|
||||
"description": "Operation successful",
|
||||
},
|
||||
**_RESPONSE_OK,
|
||||
status.HTTP_404_NOT_FOUND: {
|
||||
"description": "Prefix not found",
|
||||
"content": None,
|
||||
|
|
|
@ -23,14 +23,22 @@ _finder = PrefixFinder(_lister)
|
|||
_unique = PrefixUnique(_finder)
|
||||
|
||||
|
||||
@router.get("/list", response_model=list[str])
|
||||
@router.get(
|
||||
"/list",
|
||||
response_model=list[str],
|
||||
responses=_lister.responses,
|
||||
)
|
||||
async def list_images(
|
||||
names: Iterator[str] = Depends(_lister),
|
||||
) -> list[str]:
|
||||
return list(names)
|
||||
|
||||
|
||||
@router.get("/find/{prefix}", response_model=list[str])
|
||||
@router.get(
|
||||
"/find/{prefix}",
|
||||
response_model=list[str],
|
||||
responses=_finder.responses,
|
||||
)
|
||||
async def find_images(
|
||||
names: Iterator[str] = Depends(_finder),
|
||||
) -> list[str]:
|
||||
|
|
|
@ -55,14 +55,22 @@ async def get_ticker_content(
|
|||
)
|
||||
|
||||
|
||||
@router.get("/list", response_model=list[str])
|
||||
@router.get(
|
||||
"/list",
|
||||
response_model=list[str],
|
||||
responses=_lister.responses,
|
||||
)
|
||||
async def list_texts(
|
||||
names: Iterator[str] = Depends(_lister),
|
||||
) -> list[str]:
|
||||
return list(names)
|
||||
|
||||
|
||||
@router.get("/find/{prefix}", response_model=list[str])
|
||||
@router.get(
|
||||
"/find/{prefix}",
|
||||
response_model=list[str],
|
||||
responses=_finder.responses,
|
||||
)
|
||||
async def find_texts(
|
||||
names: Iterator[str] = Depends(_finder),
|
||||
) -> list[str]:
|
||||
|
|
Loading…
Reference in a new issue