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)
|
@dataclass(frozen=True)
|
||||||
class FileNameLister:
|
class FileNameLister:
|
||||||
remote_path: str
|
remote_path: str
|
||||||
re: re.Pattern[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]:
|
async def __call__(self) -> Iterator[str]:
|
||||||
try:
|
try:
|
||||||
file_names = await webdav_list(self.remote_path)
|
file_names = await webdav_list(self.remote_path)
|
||||||
|
@ -30,7 +47,7 @@ class FileNameLister:
|
||||||
)
|
)
|
||||||
|
|
||||||
except RemoteResourceNotFound:
|
except RemoteResourceNotFound:
|
||||||
return iter(())
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
|
@ -46,6 +63,17 @@ class CalendarNameLister:
|
||||||
class PrefixFinder:
|
class PrefixFinder:
|
||||||
lister: NameLister
|
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]:
|
async def __call__(self, prefix: str) -> Iterator[str]:
|
||||||
return (
|
return (
|
||||||
file_name
|
file_name
|
||||||
|
@ -61,9 +89,7 @@ class PrefixUnique:
|
||||||
@property
|
@property
|
||||||
def responses(self) -> dict:
|
def responses(self) -> dict:
|
||||||
return {
|
return {
|
||||||
status.HTTP_200_OK: {
|
**_RESPONSE_OK,
|
||||||
"description": "Operation successful",
|
|
||||||
},
|
|
||||||
status.HTTP_404_NOT_FOUND: {
|
status.HTTP_404_NOT_FOUND: {
|
||||||
"description": "Prefix not found",
|
"description": "Prefix not found",
|
||||||
"content": None,
|
"content": None,
|
||||||
|
|
|
@ -23,14 +23,22 @@ _finder = PrefixFinder(_lister)
|
||||||
_unique = PrefixUnique(_finder)
|
_unique = PrefixUnique(_finder)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/list", response_model=list[str])
|
@router.get(
|
||||||
|
"/list",
|
||||||
|
response_model=list[str],
|
||||||
|
responses=_lister.responses,
|
||||||
|
)
|
||||||
async def list_images(
|
async def list_images(
|
||||||
names: Iterator[str] = Depends(_lister),
|
names: Iterator[str] = Depends(_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],
|
||||||
|
responses=_finder.responses,
|
||||||
|
)
|
||||||
async def find_images(
|
async def find_images(
|
||||||
names: Iterator[str] = Depends(_finder),
|
names: Iterator[str] = Depends(_finder),
|
||||||
) -> list[str]:
|
) -> 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(
|
async def list_texts(
|
||||||
names: Iterator[str] = Depends(_lister),
|
names: Iterator[str] = Depends(_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],
|
||||||
|
responses=_finder.responses,
|
||||||
|
)
|
||||||
async def find_texts(
|
async def find_texts(
|
||||||
names: Iterator[str] = Depends(_finder),
|
names: Iterator[str] = Depends(_finder),
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
|
|
Loading…
Reference in a new issue