Browse Source

模板添加邀请界面

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.9.2^2
zouap 3 years ago
parent
commit
ad72c3a49c
2 changed files with 25 additions and 15 deletions
  1. +3
    -15
      routers/home.go
  2. +22
    -0
      services/repository/repository.go

+ 3
- 15
routers/home.go View File

@@ -736,23 +736,11 @@ func getImageInfo(filename string) ([]map[string]string, error) {
func GetMapInfo(ctx *context.Context) {
filename := ctx.Query("filename")
url := setting.RecommentRepoAddr + filename
result, err := repository.RecommendFromPromote(url)
imageInfo := make(map[string]string, 0)
result, err := repository.RecommendContentFromPromote(url)
if err != nil {
ctx.JSON(http.StatusOK, imageInfo)
return
}

for i := 0; i < len(result); i++ {
strLine := result[i]
tmpIndex := strings.Index(strLine, "=")
if tmpIndex != -1 {
key := strLine[0:tmpIndex]
value := strLine[tmpIndex+1:]
imageInfo[key] = value
}
log.Info("get file error:" + err.Error())
}
ctx.JSON(http.StatusOK, imageInfo)
ctx.JSON(http.StatusOK, result)
}

func GetRankUser(index string) ([]map[string]interface{}, error) {


+ 22
- 0
services/repository/repository.go View File

@@ -148,6 +148,28 @@ func GetRecommendRepoFromPromote(filename string) ([]map[string]interface{}, err
return resultRepo, nil
}

func RecommendContentFromPromote(url string) (string, error) {
defer func() {
if err := recover(); err != nil {
log.Info("not error.", err)
return
}
}()
resp, err := http.Get(url)
if err != nil || resp.StatusCode != 200 {
log.Info("Get organizations url error=" + err.Error())
return "", err
}
bytes, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
log.Info("Get organizations url error=" + err.Error())
return "", err
}
allLineStr := string(bytes)
return allLineStr, nil
}

func RecommendFromPromote(url string) ([]string, error) {
defer func() {
if err := recover(); err != nil {


Loading…
Cancel
Save