This commit is contained in:
Liang Ding 2023-05-05 23:07:06 +08:00
parent f5f5a1d428
commit 9e1dbd9b96
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
8 changed files with 129 additions and 159 deletions

View file

@ -32,25 +32,24 @@ import (
)
type Icon struct {
Package
*Package
}
func Icons() (icons []*Icon) {
icons = []*Icon{}
pkgIndex, err := getPkgIndex("icons")
stageIndex, err := getStageIndex("icons")
if nil != err {
return
}
bazaarIndex := getBazaarIndex()
repos := pkgIndex["repos"].([]interface{})
waitGroup := &sync.WaitGroup{}
lock := &sync.Mutex{}
p, _ := ants.NewPoolWithFunc(2, func(arg interface{}) {
defer waitGroup.Done()
repo := arg.(map[string]interface{})
repoURL := repo["url"].(string)
repo := arg.(*StageRepo)
repoURL := repo.URL
icon := &Icon{}
innerU := util.BazaarOSSServer + "/package/" + repoURL + "/icon.json"
@ -71,13 +70,13 @@ func Icons() (icons []*Icon) {
icon.PreviewURL = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageslim"
icon.PreviewURLThumb = util.BazaarOSSServer + "/package/" + repoURL + "/preview.png?imageView2/2/w/436/h/232"
icon.IconURL = util.BazaarOSSServer + "/package/" + repoURL + "/icon.png"
icon.Funding = parseFunding(repo["package"].(map[string]interface{}))
icon.Funding = repo.Package.Funding
icon.PreferredFunding = getPreferredFunding(icon.Funding)
icon.PreferredDesc = getPreferredDesc(icon.Description)
icon.Updated = repo["updated"].(string)
icon.Stars = int(repo["stars"].(float64))
icon.OpenIssues = int(repo["openIssues"].(float64))
icon.Size = int64(repo["size"].(float64))
icon.Updated = repo.Updated
icon.Stars = repo.Stars
icon.OpenIssues = repo.OpenIssues
icon.Size = repo.Size
icon.HSize = humanize.Bytes(uint64(icon.Size))
icon.HUpdated = formatUpdated(icon.Updated)
pkg := bazaarIndex[strings.Split(repoURL, "@")[0]]
@ -88,7 +87,7 @@ func Icons() (icons []*Icon) {
icons = append(icons, icon)
lock.Unlock()
})
for _, repo := range repos {
for _, repo := range stageIndex.Repos {
waitGroup.Add(1)
p.Invoke(repo)
}
@ -118,25 +117,18 @@ func InstalledIcons() (ret []*Icon) {
continue
}
iconConf, parseErr := IconJSON(dirName)
if nil != parseErr || nil == iconConf {
icon, parseErr := IconJSON(dirName)
if nil != parseErr || nil == icon {
continue
}
installPath := filepath.Join(util.IconsPath, dirName)
icon := &Icon{}
icon.Installed = true
icon.Name = iconConf["name"].(string)
icon.Author = iconConf["author"].(string)
icon.URL = iconConf["url"].(string)
icon.URL = strings.TrimSuffix(icon.URL, "/")
icon.Version = iconConf["version"].(string)
icon.RepoURL = icon.URL
icon.PreviewURL = "/appearance/icons/" + dirName + "/preview.png"
icon.PreviewURLThumb = "/appearance/icons/" + dirName + "/preview.png"
icon.IconURL = "/appearance/icons/" + dirName + "/icon.png"
icon.Funding = parseFunding(iconConf)
icon.PreferredFunding = getPreferredFunding(icon.Funding)
icon.PreferredDesc = getPreferredDesc(icon.Description)
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))