优化pkg功能

This commit is contained in:
liyp 2024-06-27 13:16:14 +08:00
parent 6d8a3476a8
commit 383cdf1e02

View file

@ -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,26 +70,31 @@ func (a *Pkg) GetMsg() string {
if err != nil {
fmt.Println(err)
}
if len(suggestions) > 0 {
searchUrl := "https://aur.archlinux.org/rpc/v5/search/" + suggestions[0] + "?by=name"
searchReq, err := http.Get(searchUrl)
if err != nil {
fmt.Println(err)
}
defer searchReq.Body.Close()
searchRe, err := io.ReadAll(searchReq.Body)
if err != nil {
fmt.Println(err)
}
var searchMap map[string]interface{}
err = json.Unmarshal(searchRe, &searchMap)
if err != nil {
fmt.Println(err)
}
// 增加根据投票人数排序
searchResults := searchMap["results"].([]interface{})
maxVotes := 0.0
var searchResult map[string]interface{}
// 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 {
fmt.Println(err)
}
defer searchReq.Body.Close()
searchRe, err := io.ReadAll(searchReq.Body)
if err != nil {
fmt.Println(err)
}
var searchMap map[string]interface{}
err = json.Unmarshal(searchRe, &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)
@ -98,26 +103,29 @@ func (a *Pkg) GetMsg() string {
searchResult = resultMap
}
}
maintainer, ok := searchResult["Maintainer"].(string)
if !ok {
maintainer = "孤儿包"
}
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"
msg += "版本:" + searchResult["Version"].(string) + "\n"
msg += "描述:" + searchResult["Description"].(string) + "\n"
msg += "维护者:" + maintainer + "\n"
msg += "链接:" + searchResult["URL"].(string) + "\n"
msg += "更新时间:" + last_update + "\n"
fmt.Println(msg)
return msg
} else {
return "没有找到相关软件"
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"
msg += "版本:" + searchResult["Version"].(string) + "\n"
msg += "描述:" + searchResult["Description"].(string) + "\n"
msg += "维护者:" + maintainer + "\n"
msg += "链接:" + searchResult["URL"].(string) + "\n"
msg += "更新时间:" + last_update
fmt.Println(msg)
return msg
}
result := resultSlipe[0].(map[string]interface{})