优化pkg功能
This commit is contained in:
parent
6d8a3476a8
commit
383cdf1e02
1 changed files with 48 additions and 40 deletions
|
@ -59,7 +59,7 @@ func (a *Pkg) GetMsg() string {
|
|||
}
|
||||
defer req.Body.Close()
|
||||
|
||||
fmt.Println("aur url:", url)
|
||||
fmt.Println("aur suggest url:", url)
|
||||
re, err := io.ReadAll(req.Body)
|
||||
// fmt.Println(string(re))
|
||||
if err != nil {
|
||||
|
@ -70,7 +70,10 @@ func (a *Pkg) GetMsg() string {
|
|||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
if len(suggestions) > 0 {
|
||||
// println(len(suggestions))
|
||||
if len(suggestions) == 0 {
|
||||
return "没有找到相关软件"
|
||||
}
|
||||
searchUrl := "https://aur.archlinux.org/rpc/v5/search/" + suggestions[0] + "?by=name"
|
||||
searchReq, err := http.Get(searchUrl)
|
||||
if err != nil {
|
||||
|
@ -86,10 +89,12 @@ func (a *Pkg) GetMsg() string {
|
|||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
// 增加根据投票人数排序
|
||||
searchResults := searchMap["results"].([]interface{})
|
||||
// println("searchResults:", len(searchResults))
|
||||
maxVotes := 0.0
|
||||
var searchResult map[string]interface{}
|
||||
// 增加根据投票人数排序
|
||||
if len(searchResults) > 1 {
|
||||
for _, result := range searchResults {
|
||||
resultMap := result.(map[string]interface{})
|
||||
numVotes := resultMap["NumVotes"].(float64)
|
||||
|
@ -98,12 +103,18 @@ func (a *Pkg) GetMsg() string {
|
|||
searchResult = resultMap
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(len(searchResult))
|
||||
} else if len(searchResults) == 1 {
|
||||
searchResult = searchResults[0].(map[string]interface{})
|
||||
}
|
||||
maintainer, ok := searchResult["Maintainer"].(string)
|
||||
if !ok {
|
||||
maintainer = "孤儿包"
|
||||
}
|
||||
println("maintainer:", maintainer)
|
||||
// last_update := ''
|
||||
last_update := time.Unix(int64(searchResult["LastModified"].(float64)), 0).Format("2006-01-02 15:04:05")
|
||||
|
||||
var msg string
|
||||
msg += "仓库:AUR\n"
|
||||
msg += "包名:" + searchResult["Name"].(string) + "\n"
|
||||
|
@ -111,13 +122,10 @@ func (a *Pkg) GetMsg() string {
|
|||
msg += "描述:" + searchResult["Description"].(string) + "\n"
|
||||
msg += "维护者:" + maintainer + "\n"
|
||||
msg += "链接:" + searchResult["URL"].(string) + "\n"
|
||||
msg += "更新时间:" + last_update + "\n"
|
||||
msg += "更新时间:" + last_update
|
||||
|
||||
fmt.Println(msg)
|
||||
return msg
|
||||
} else {
|
||||
return "没有找到相关软件"
|
||||
}
|
||||
|
||||
}
|
||||
result := resultSlipe[0].(map[string]interface{})
|
||||
|
|
Loading…
Reference in a new issue