From 6a0683779b5d765eb88c67d1e3440d924525d6bd Mon Sep 17 00:00:00 2001 From: "donknap@gmail.com" Date: Fri, 29 Nov 2024 19:09:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcasaos=E5=95=86=E5=BA=97?= =?UTF-8?q?=E7=9A=84=E5=85=BC=E5=AE=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/http/controller/store.go | 2 +- app/common/logic/store.go | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/common/http/controller/store.go b/app/common/http/controller/store.go index 3d0568b0..7da3b37f 100644 --- a/app/common/http/controller/store.go +++ b/app/common/http/controller/store.go @@ -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 diff --git a/app/common/logic/store.go b/app/common/logic/store.go index 28819080..0cebdad8 100644 --- a/app/common/logic/store.go +++ b/app/common/logic/store.go @@ -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() @@ -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 @@ -296,12 +305,15 @@ 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", @@ -309,6 +321,11 @@ func (self Store) GetAppByCasaos(storePath string) ([]accessor.StoreAppItem, err 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 {