diff --git a/routers/home.go b/routers/home.go index 69aaf5165..ac607b5be 100755 --- a/routers/home.go +++ b/routers/home.go @@ -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) { diff --git a/services/repository/repository.go b/services/repository/repository.go index 6bf4ab283..b4c047392 100644 --- a/services/repository/repository.go +++ b/services/repository/repository.go @@ -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 {