Skip to content

Commit

Permalink
fix: fix not store app in install custom app (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH committed Apr 2, 2024
1 parent 6570ad2 commit 6ca7318
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 19 deletions.
26 changes: 25 additions & 1 deletion api/app_management/openapi.yaml
Expand Up @@ -330,7 +330,7 @@ paths:
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
operationId: composeAppMainStableTag
tags:
- AppStore methods
parameters:
Expand All @@ -343,6 +343,30 @@ paths:
"500":
$ref: "#/components/responses/ResponseInternalServerError"

/apps/{id}/stable/{serviceName}:
get:
summary: Get server of app stable version from registered app stores
description: |
Get stable version(Official Store Tag) of main service of specific compose app.
operationId: composeAppServiceStableTag
tags:
- AppStore methods
parameters:
- $ref: "#/components/parameters/StoreAppIDString"
- name: serviceName
in: path
description: Service name of the compose app
required: true
schema:
type: string
responses:
"200":
$ref: "#/components/responses/ComposeAppStoreTagOK"
"404":
$ref: "#/components/responses/ResponseNotFound"
"500":
$ref: "#/components/responses/ResponseInternalServerError"


/apps/{id}/compose:
get:
Expand Down
50 changes: 35 additions & 15 deletions route/v2/appstore.go
Expand Up @@ -184,7 +184,7 @@ func (a *AppManagement) ComposeAppStoreInfo(ctx echo.Context, id codegen.StoreAp
})
}

func (a *AppManagement) ComposeAppStableTag(ctx echo.Context, id codegen.StoreAppIDString) error {
func (a *AppManagement) ComposeAppMainStableTag(ctx echo.Context, id codegen.StoreAppIDString) error {
composeApp, err := service.MyService.V2AppStore().ComposeApp(id)
if err != nil {
message := err.Error()
Expand All @@ -197,30 +197,50 @@ func (a *AppManagement) ComposeAppStableTag(ctx echo.Context, id codegen.StoreAp
})
}

// TODO refactor this with MainService
storeInfo, err := composeApp.StoreInfo(true)
mainService, err := composeApp.MainService()
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
_, tag := docker.ExtractImageAndTag(app.Image)
_, tag := docker.ExtractImageAndTag(mainService.Image)

return ctx.JSON(http.StatusOK, codegen.ComposeAppStoreTagOK{
Data: &codegen.ComposeAppStoreTag{
Tag: tag,
},
})
return ctx.JSON(http.StatusOK, codegen.ComposeAppStoreTagOK{
Data: &codegen.ComposeAppStoreTag{
Tag: tag,
},
})
}

func (a *AppManagement) ComposeAppServiceStableTag(ctx echo.Context, id codegen.StoreAppIDString, serviceName string) 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"),
})
}

service := composeApp.App(serviceName)
if service == nil {
return ctx.JSON(http.StatusInternalServerError, codegen.ResponseInternalServerError{
Message: utils.Ptr("service not found"),
})

}
}

return ctx.JSON(http.StatusInternalServerError, codegen.ResponseInternalServerError{
Message: utils.Ptr("app not main"),
_, tag := docker.ExtractImageAndTag(service.Image)

return ctx.JSON(http.StatusOK, codegen.ComposeAppStoreTagOK{
Data: &codegen.ComposeAppStoreTag{
Tag: tag,
},
})
}

Expand Down
5 changes: 4 additions & 1 deletion route/v2/compose_app.go
Expand Up @@ -117,12 +117,15 @@ func (a *AppManagement) IsNewComposeUncontrolled(newComposeApp *service.ComposeA
}

if StoreApp == nil {
return false, errors.New("store app not found")
logger.Error("store app not found", zap.String("composeAppID", newComposeApp.Name))
return false, nil
}

StableTag, err := StoreApp.MainTag()
if err != nil {
return false, err
}

if StableTag != newTag {
return true, nil
} else {
Expand Down
3 changes: 2 additions & 1 deletion service/compose_app.go
Expand Up @@ -350,6 +350,7 @@ func (a *ComposeApp) Update(ctx context.Context) error {
return nil
}

// TODO rename the function to service and add error return value
func (a *ComposeApp) App(name string) *App {
if name == "" {
return nil
Expand Down Expand Up @@ -381,7 +382,7 @@ func (a *ComposeApp) MainService() (*App, error) {
}

if storeInfo.Main == nil || *storeInfo.Main == "" {
return nil, ErrMainServiceNotFound
return nil, ErrMainServiceNotSpecified
}

return a.App(*storeInfo.Main), nil
Expand Down
2 changes: 1 addition & 1 deletion service/errs.go
Expand Up @@ -16,5 +16,5 @@ var (
ErrNotFoundInAppStore = fmt.Errorf("not found in app store")
ErrSetStoreAppID = fmt.Errorf("failed to set store app ID")
ErrStoreInfoNotFound = fmt.Errorf("store info not found")
ErrMainServiceNotFound = fmt.Errorf("main service not found")
ErrMainServiceNotSpecified = fmt.Errorf("main service not been specified")
)

0 comments on commit 6ca7318

Please sign in to comment.