refactor: move logic to static method get_extension_release
This commit is contained in:
parent
980267cb51
commit
d146a45b59
|
@ -725,22 +725,14 @@ async def websocket_update_get(item_id: str, data: str):
|
|||
async def api_install_extension(
|
||||
data: CreateExtension, user: User = Depends(check_admin)
|
||||
):
|
||||
# ext_info: InstallableExtension = await InstallableExtension.get_extension_info(
|
||||
# data.ext_id, data.archive
|
||||
# )
|
||||
|
||||
all_releases: List[
|
||||
ExtensionRelease
|
||||
] = await InstallableExtension.get_extension_releases(data.ext_id)
|
||||
selected_release = [
|
||||
r
|
||||
for r in all_releases
|
||||
if r.archive == data.archive and r.source_repo == data.source_repo
|
||||
]
|
||||
if len(selected_release) == 0:
|
||||
raise Exception("uuuuuuu")
|
||||
|
||||
installed_release = selected_release[0]
|
||||
installed_release = await InstallableExtension.get_extension_release(
|
||||
data.ext_id, data.source_repo, data.archive
|
||||
)
|
||||
if not installed_release:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Release not found"
|
||||
)
|
||||
ext_info = InstallableExtension(
|
||||
id=data.ext_id, name=data.ext_id, installed_release=installed_release
|
||||
)
|
||||
|
|
|
@ -387,6 +387,21 @@ class InstallableExtension(BaseModel):
|
|||
|
||||
return extension_releases
|
||||
|
||||
@classmethod
|
||||
async def get_extension_release(
|
||||
cls, ext_id: str, source_repo: str, archive: str
|
||||
) -> Optional["ExtensionRelease"]:
|
||||
all_releases: List[
|
||||
ExtensionRelease
|
||||
] = await InstallableExtension.get_extension_releases(ext_id)
|
||||
selected_release = [
|
||||
r
|
||||
for r in all_releases
|
||||
if r.archive == archive and r.source_repo == source_repo
|
||||
]
|
||||
|
||||
return selected_release[0] if len(selected_release) != 0 else None
|
||||
|
||||
|
||||
class InstalledExtensionMiddleware:
|
||||
def __init__(self, app: ASGIApp) -> None:
|
||||
|
|
Loading…
Reference in New Issue
Block a user