Skip to content

Commit

Permalink
修复casaos商店的兼容问题
Browse files Browse the repository at this point in the history
  • Loading branch information
donknap committed Nov 29, 2024
1 parent f094002 commit 6a06837
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/common/http/controller/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (self Store) Sync(http *gin.Context) {
return
}
} else if params.Type == accessor.StoreTypeCasaOs {
err = logic.Store{}.SyncByZip(storeRootPath, params.Url)
err = logic.Store{}.SyncByZip(storeRootPath, params.Url, "Apps")
if err != nil {
self.JsonResponseWithError(http, err, 500)
return
Expand Down
23 changes: 20 additions & 3 deletions app/common/logic/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (self Store) SyncByGit(path, gitUrl string) error {
return nil
}

func (self Store) SyncByZip(path, zipUrl string) error {
func (self Store) SyncByZip(path, zipUrl string, root string) error {
zipTempFile, _ := os.CreateTemp("", "dpanel-store")
defer func() {
_ = zipTempFile.Close()
Expand Down Expand Up @@ -89,6 +89,15 @@ func (self Store) SyncByZip(path, zipUrl string) error {
continue
}
targetFilePath := filepath.Join(path, file.Name)
if root != "" {
if before, after, exists := strings.Cut(file.Name, root); exists {
if before != "" {
targetFilePath = filepath.Join(path, root, after)
}
} else {
continue
}
}
err = os.MkdirAll(filepath.Dir(targetFilePath), os.ModePerm)
if err != nil {
return err
Expand Down Expand Up @@ -296,19 +305,27 @@ func (self Store) GetAppByCasaos(storePath string) ([]accessor.StoreAppItem, err
if err != nil {
return err
}
storeItem.Description = yamlData.GetString("x-casaos.description.zh_cn")
storeItem.Description = yamlData.GetString("x-casaos.description.zh_cn") + "\n" + yamlData.GetString("x-casaos.description.en_us")
storeItem.Tag = []string{
yamlData.GetString("x-casaos.category"),
}
storeItem.Logo = yamlData.GetString("x-casaos.icon")
storeItem.Content = "markdown://" + yamlData.GetString("x-casaos.tips.before_install.zh_cn")
readme := yamlData.GetString("x-casaos.tips.before_install.zh_cn")
if readme != "" {
storeItem.Content = "markdown://" + yamlData.GetString("x-casaos.tips.before_install.zh_cn")
}
versionPath, _ := filepath.Rel(filepath.Dir(filepath.Dir(storePath)), path)
storeItem.Version["latest"] = accessor.StoreAppVersionItem{
Name: "latest",
ComposeFile: versionPath,
Environment: make([]accessor.EnvItem, 0),
}
}

if strings.HasSuffix(relPath, "README.md") {
readmePath, _ := filepath.Rel(filepath.Dir(filepath.Dir(storePath)), path)
storeItem.Content = fmt.Sprintf("markdown-file://%s", readmePath)
}
return nil
})
if err != nil {
Expand Down

0 comments on commit 6a06837

Please sign in to comment.