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