feat: 修改软件包搜索逻辑以获取更多信息
This commit is contained in:
parent
6b8d132620
commit
b91b18f29c
1 changed files with 51 additions and 29 deletions
|
@ -73,43 +73,63 @@ func (a *Pkg) GetMsg() string {
|
|||
if len(suggestions) == 0 {
|
||||
return "没有找到相关软件"
|
||||
}
|
||||
searchUrl := "https://aur.archlinux.org/rpc/v5/search/" + suggestions[0] + "?by=name"
|
||||
_, body, errs = request.Get(searchUrl).End()
|
||||
if len(errs) > 0 {
|
||||
fmt.Println("searchUrl err:", errs)
|
||||
}
|
||||
var searchMap map[string]interface{}
|
||||
err = json.Unmarshal([]byte(body), &searchMap)
|
||||
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)
|
||||
if numVotes > maxVotes {
|
||||
maxVotes = numVotes
|
||||
searchResult = resultMap
|
||||
}
|
||||
if len(suggestions) == 1 {
|
||||
searchUrl := "https://aur.archlinux.org/rpc/v5/info/" + suggestions[0]
|
||||
_, body, errs = request.Get(searchUrl).End()
|
||||
|
||||
if len(errs) > 0 {
|
||||
fmt.Println("searchUrl err:", errs)
|
||||
|
||||
return "服务器网络错误!"
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(body), &searchMap)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("解析失败:", err)
|
||||
}
|
||||
searchResult = searchMap["results"].([]interface{})[0].(map[string]interface{})
|
||||
|
||||
} else {
|
||||
searchUrl := "https://aur.archlinux.org/rpc/v5/search/" + suggestions[0] + "?by=name"
|
||||
_, body, errs = request.Get(searchUrl).End()
|
||||
if len(errs) > 0 {
|
||||
fmt.Println("searchUrl err:", errs)
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(body), &searchMap)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
searchResults := searchMap["results"].([]interface{})
|
||||
// println("searchResults:", len(searchResults))
|
||||
maxVotes := 0.0
|
||||
|
||||
// 增加根据投票人数排序
|
||||
if len(searchResults) > 1 {
|
||||
for _, result := range searchResults {
|
||||
resultMap := result.(map[string]interface{})
|
||||
numVotes := resultMap["NumVotes"].(float64)
|
||||
if numVotes > maxVotes {
|
||||
maxVotes = numVotes
|
||||
searchResult = resultMap
|
||||
}
|
||||
}
|
||||
// fmt.Println(len(searchResult))
|
||||
}
|
||||
// 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")
|
||||
|
||||
OutOfDate := ""
|
||||
_, ok = searchResult["OutOfDate"].(float64)
|
||||
if ok {
|
||||
OutOfDate = fmt.Sprintf("过期时间:%s\n", time.Unix(int64(searchResult["OutOfDate"].(float64)), 0).Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
var msg string
|
||||
msg += "仓库:AUR\n"
|
||||
msg += "包名:" + searchResult["Name"].(string) + "\n"
|
||||
|
@ -121,6 +141,8 @@ func (a *Pkg) GetMsg() string {
|
|||
upstream = "无"
|
||||
}
|
||||
msg += "上游:" + upstream + "\n"
|
||||
msg += OutOfDate
|
||||
last_update := time.Unix(int64(searchResult["LastModified"].(float64)), 0).Format("2006-01-02 15:04:05")
|
||||
msg += "更新时间:" + last_update
|
||||
|
||||
// fmt.Println(msg)
|
||||
|
|
Loading…
Reference in a new issue