Skip to content

Commit

Permalink
feat: add a api to get stable tag of app (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH authored Mar 8, 2024
1 parent e4612d3 commit 6cb3bc6
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
51 changes: 50 additions & 1 deletion api/app_management/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -667,7 +686,7 @@ components:
schema:
type: string
example: "syncthing"

StoreAppCategoryFilter:
name: category
description: Category of the store app
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
40 changes: 40 additions & 0 deletions route/v2/appstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 6cb3bc6

Please sign in to comment.