diff --git a/routers/home.go b/routers/home.go index 4fa0e42bb..651f73a9a 100755 --- a/routers/home.go +++ b/routers/home.go @@ -642,6 +642,31 @@ func GetRecommendOrg() ([]map[string]interface{}, error) { return resultOrg, nil } +func GetImageInfo() ([]map[string]interface{}, error) { + url := setting.RecommentRepoAddr + "picture_info" + result, err := repository.RecommendFromPromote(url) + + if err != nil { + return nil, err + } + imageInfo := make([]map[string]interface{}, 0) + for i := 0; i < (len(result) - 1); i++ { + line := result[i] + imageMap := make(map[string]interface{}) + if line[0:4] == "url=" { + url := line[4:] + imageMap["url"] = url + if result[i+1][0:11] == "image_link=" { + image_link := result[i+1][11:] + imageMap["image_link"] = image_link + } + } + imageInfo = append(imageInfo, imageMap) + i = i + 1 + } + return imageInfo, nil +} + func GetRankUser(index string) ([]map[string]interface{}, error) { url := setting.RecommentRepoAddr + "user_rank_" + index result, err := repository.RecommendFromPromote(url) @@ -680,6 +705,15 @@ func GetRankUser(index string) ([]map[string]interface{}, error) { return resultOrg, nil } +func GetImageInfoFromPromote(ctx *context.Context) { + imageInfo, err := GetImageInfo() + if err != nil { + ctx.ServerError("500", err) + return + } + ctx.JSON(200, imageInfo) +} + func GetUserRankFromPromote(ctx *context.Context) { index := ctx.Params("index") resultUserRank, err := GetRankUser(index) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 2ce32ea90..1e1a862ff 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -326,6 +326,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/recommend/org", routers.RecommendOrgFromPromote) m.Get("/recommend/repo", routers.RecommendRepoFromPromote) m.Get("/recommend/userrank/:index", routers.GetUserRankFromPromote) + m.Get("/recommend/imageinfo", routers.GetImageInfoFromPromote) m.Post("/all/search/", routers.Search) m.Get("/all/search/", routers.EmptySearch) m.Get("/all/dosearch/", routers.SearchApi)