From 6cb3bc62f15179556f6cb9f3d93153ff3b693e51 Mon Sep 17 00:00:00 2001 From: CorrectRoad Date: Fri, 8 Mar 2024 17:35:27 +0800 Subject: [PATCH] feat: add a api to get stable tag of app (#162) --- api/app_management/openapi.yaml | 51 ++++++++++++++++++++++++++++++++- route/v2/appstore.go | 40 ++++++++++++++++++++++++++ service/app.go | 3 ++ 3 files changed, 93 insertions(+), 1 deletion(-) diff --git a/api/app_management/openapi.yaml b/api/app_management/openapi.yaml index 8b7df899..983c1349 100644 --- a/api/app_management/openapi.yaml +++ b/api/app_management/openapi.yaml @@ -325,6 +325,25 @@ paths: "500": $ref: "#/components/responses/ResponseInternalServerError" + /apps/{id}/stable: + get: + summary: Get app stable version from registered app stores + description: | + Get stable version(Official Store Tag) of main service of specific compose app. + operationId: composeAppStableTag + tags: + - AppStore methods + parameters: + - $ref: "#/components/parameters/StoreAppIDString" + responses: + "200": + $ref: "#/components/responses/ComposeAppStoreTagOK" + "404": + $ref: "#/components/responses/ResponseNotFound" + "500": + $ref: "#/components/responses/ResponseInternalServerError" + + /apps/{id}/compose: get: summary: Get compose details of an app from registered app stores @@ -667,7 +686,7 @@ components: schema: type: string example: "syncthing" - + StoreAppCategoryFilter: name: category description: Category of the store app @@ -922,6 +941,17 @@ components: data: $ref: "#/components/schemas/ComposeAppStoreInfoLists" + ComposeAppStoreTagOK: + description: OK + content: + application/json: + schema: + allOf: + - $ref: "#/components/schemas/BaseResponse" + - properties: + data: + $ref: "#/components/schemas/ComposeAppStoreTag" + ComposeAppStoreInfoOK: description: OK content: @@ -1163,6 +1193,15 @@ components: additionalProperties: $ref: "#/components/schemas/ComposeAppStoreInfo" + ComposeAppStoreTag: + required: + - tag + properties: + tag: + type: string + example: + en_us: "v10.2" + ComposeAppStoreInfo: required: - author @@ -1186,6 +1225,12 @@ components: type: string example: en_us: Syncthing + image: + type: object + additionalProperties: + type: string + example: + en_us: syncthing:latest description: type: object additionalProperties: @@ -1348,11 +1393,15 @@ components: description: |- > Do not mistake it as *information of AppStore* which does not exist. required: + - image - envs - ports - volumes - devices properties: + image: + type: string + example: "syncthing:latest" envs: type: array items: diff --git a/route/v2/appstore.go b/route/v2/appstore.go index 4c700ae0..63c811f2 100644 --- a/route/v2/appstore.go +++ b/route/v2/appstore.go @@ -183,6 +183,46 @@ func (a *AppManagement) ComposeAppStoreInfo(ctx echo.Context, id codegen.StoreAp }) } +func (a *AppManagement) ComposeAppStableTag(ctx echo.Context, id codegen.StoreAppIDString) error { + composeApp, err := service.MyService.V2AppStore().ComposeApp(id) + if err != nil { + message := err.Error() + return ctx.JSON(http.StatusInternalServerError, codegen.ResponseInternalServerError{Message: &message}) + } + + if composeApp == nil { + return ctx.JSON(http.StatusNotFound, codegen.ResponseNotFound{ + Message: utils.Ptr("app not found"), + }) + } + + storeInfo, err := composeApp.StoreInfo(true) + if err != nil { + return ctx.JSON(http.StatusInternalServerError, codegen.ResponseInternalServerError{ + Message: utils.Ptr(err.Error()), + }) + } + + for key, app := range *storeInfo.Apps { + if key == *storeInfo.Main { + // spilt by : ; example: linuxserver/jellyfin:10.8.13 + // get the last one + tag := strings.Split(app.Image, ":") + + return ctx.JSON(http.StatusOK, codegen.ComposeAppStoreTagOK{ + Data: &codegen.ComposeAppStoreTag{ + Tag: tag[len(tag)-1], + }, + }) + + } + } + + return ctx.JSON(http.StatusInternalServerError, codegen.ResponseInternalServerError{ + Message: utils.Ptr("app not main"), + }) +} + func (a *AppManagement) ComposeApp(ctx echo.Context, id codegen.StoreAppIDString) error { composeApp, err := service.MyService.V2AppStore().ComposeApp(id) if err != nil { diff --git a/service/app.go b/service/app.go index c50e7352..38ab3e24 100644 --- a/service/app.go +++ b/service/app.go @@ -17,6 +17,9 @@ func (a *App) StoreInfo() (codegen.AppStoreInfo, error) { return storeInfo, ErrComposeExtensionNameXCasaOSNotFound } + // add image to store info for check stable version function. + storeInfo.Image = a.Image + if err := loader.Transform(ex, &storeInfo); err != nil { return storeInfo, err }