Skip to content

Commit

Permalink
🎨 集市支持已安装的包单独显示 #5678
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 1, 2022
1 parent 29021c8 commit 74b73d0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 68 deletions.
19 changes: 3 additions & 16 deletions kernel/bazaar/icon.go
Expand Up @@ -57,26 +57,13 @@ type Icon struct {

func Icons() (icons []*Icon) {
icons = []*Icon{}
result, err := util.GetRhyResult(false)
if nil != err {
return
}

bazaarIndex := getBazaarIndex()
bazaarHash := result["bazaar"].(string)
result = map[string]interface{}{}
request := httpclient.NewBrowserRequest()
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/icons.json"
resp, err := request.SetResult(&result).Get(u)
pkgIndex, err := getPkgIndex("icons")
if nil != err {
logging.LogErrorf("get community stage index [%s] failed: %s", u, err)
return
}
if 200 != resp.StatusCode {
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
return
}
repos := result["repos"].([]interface{})
bazaarIndex := getBazaarIndex()
repos := pkgIndex["repos"].([]interface{})
waitGroup := &sync.WaitGroup{}
lock := &sync.Mutex{}
p, _ := ants.NewPoolWithFunc(2, func(arg interface{}) {
Expand Down
40 changes: 40 additions & 0 deletions kernel/bazaar/package.go
Expand Up @@ -81,6 +81,46 @@ func ThemeJSON(themeDirName string) (ret map[string]interface{}, err error) {
return
}

func getPkgIndex(pkgType string) (ret map[string]interface{}, err error) {
ret, err = util.GetRhyResult(false)
if nil != err {
return
}

bazaarHash := ret["bazaar"].(string)
ret = map[string]interface{}{}
request := httpclient.NewBrowserRequest()
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/" + pkgType + ".json"
resp, reqErr := request.SetResult(&ret).Get(u)
if nil != reqErr {
logging.LogErrorf("get community stage index [%s] failed: %s", u, reqErr)
return
}
if 200 != resp.StatusCode {
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
return
}
return
}

func isOutdatedPkg(fullURL, version string, pkgIndex map[string]interface{}) bool {
if !strings.HasPrefix(fullURL, "https://github.com/") {
return false
}

url := strings.TrimPrefix(fullURL, "https://github.com/")
repos := pkgIndex["repos"].([]interface{})
for _, repo := range repos {
r := repo.(map[string]interface{})
repoURL := r["url"].(string)
repoVer := r["version"].(string)
if url == repoURL && version != repoVer {
return true
}
}
return false
}

func GetPackageREADME(repoURL, repoHash string, systemID string) (ret string) {
repoURLHash := repoURL + "@" + repoHash
data, err := downloadPackage(repoURLHash+"/README.md", false, systemID)
Expand Down
20 changes: 3 additions & 17 deletions kernel/bazaar/template.go
Expand Up @@ -59,27 +59,13 @@ type Template struct {

func Templates() (templates []*Template) {
templates = []*Template{}
result, err := util.GetRhyResult(false)

pkgIndex, err := getPkgIndex("templates")
if nil != err {
return
}

bazaarIndex := getBazaarIndex()
bazaarHash := result["bazaar"].(string)
result = map[string]interface{}{}
request := httpclient.NewBrowserRequest()
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/templates.json"
resp, reqErr := request.SetResult(&result).Get(u)
if nil != reqErr {
logging.LogErrorf("get community stage index [%s] failed: %s", u, reqErr)
return
}
if 200 != resp.StatusCode {
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
return
}

repos := result["repos"].([]interface{})
repos := pkgIndex["repos"].([]interface{})
waitGroup := &sync.WaitGroup{}
lock := &sync.Mutex{}
p, _ := ants.NewPoolWithFunc(2, func(arg interface{}) {
Expand Down
29 changes: 10 additions & 19 deletions kernel/bazaar/theme.go
Expand Up @@ -60,27 +60,13 @@ type Theme struct {

func Themes() (ret []*Theme) {
ret = []*Theme{}
result, err := util.GetRhyResult(false)

pkgIndex, err := getPkgIndex("themes")
if nil != err {
return
}

bazaarIndex := getBazaarIndex()
bazaarHash := result["bazaar"].(string)
result = map[string]interface{}{}
request := httpclient.NewBrowserRequest()
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/themes.json"
resp, reqErr := request.SetResult(&result).Get(u)
if nil != reqErr {
logging.LogErrorf("get community stage index [%s] failed: %s", u, reqErr)
return
}
if 200 != resp.StatusCode {
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
return
}

repos := result["repos"].([]interface{})
repos := pkgIndex["repos"].([]interface{})
waitGroup := &sync.WaitGroup{}
lock := &sync.Mutex{}
p, _ := ants.NewPoolWithFunc(8, func(arg interface{}) {
Expand All @@ -97,7 +83,7 @@ func Themes() (ret []*Theme) {
return
}
if 200 != innerResp.StatusCode {
logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, resp.StatusCode)
logging.LogErrorf("get bazaar package [%s] failed: %d", innerU, innerResp.StatusCode)
return
}

Expand Down Expand Up @@ -144,6 +130,11 @@ func InstalledThemes() (ret []*Theme) {
}
dir.Close()

pkgIndex, err := getPkgIndex("themes")
if nil != err {
return
}

for _, themeDir := range themeDirs {
if !themeDir.IsDir() {
continue
Expand Down Expand Up @@ -177,7 +168,7 @@ func InstalledThemes() (ret []*Theme) {
continue
}
theme.README = gulu.Str.FromBytes(readme)

theme.Outdated = isOutdatedPkg(theme.URL, theme.Version, pkgIndex)
ret = append(ret, theme)
}
return
Expand Down
19 changes: 3 additions & 16 deletions kernel/bazaar/widget.go
Expand Up @@ -57,27 +57,14 @@ type Widget struct {

func Widgets() (widgets []*Widget) {
widgets = []*Widget{}
result, err := util.GetRhyResult(false)
if nil != err {
return
}

bazaarIndex := getBazaarIndex()
bazaarHash := result["bazaar"].(string)
result = map[string]interface{}{}
request := httpclient.NewBrowserRequest()
u := util.BazaarOSSServer + "/bazaar@" + bazaarHash + "/stage/widgets.json"
resp, err := request.SetResult(&result).Get(u)
pkgIndex, err := getPkgIndex("widgets")
if nil != err {
logging.LogErrorf("get community stage index [%s] failed: %s", u, err)
return
}
if 200 != resp.StatusCode {
logging.LogErrorf("get community stage index [%s] failed: %d", u, resp.StatusCode)
return
}
bazaarIndex := getBazaarIndex()

repos := result["repos"].([]interface{})
repos := pkgIndex["repos"].([]interface{})
waitGroup := &sync.WaitGroup{}
lock := &sync.Mutex{}
p, _ := ants.NewPoolWithFunc(8, func(arg interface{}) {
Expand Down

0 comments on commit 74b73d0

Please sign in to comment.