diff --git a/entity/models.go b/entity/models.go index 9e9bdcc..261512b 100644 --- a/entity/models.go +++ b/entity/models.go @@ -1,16 +1,23 @@ package entity +import ( + "html/template" + "time" +) + type Illust struct { - ID int `json:"id"` - Title string `json:"title"` - Caption string `json:"caption"` - Images map[string]string `json:"image_urls"` - Artist UserBrief `json:"user"` + ID int `json:"id"` + Title string `json:"title"` + Caption template.HTML `json:"caption"` + Images map[string]string `json:"image_urls"` + Artist UserBrief `json:"user"` + Date time.Time `json:"create_date"` + Pages int `json:"page_count"` + Views int `json:"total_view"` + Bookmarks int `json:"total_bookmarks"` + SingleImage map[string]string `json:"meta_single_page"` + MultipleImage []map[string]map[string]string `json:"meta_pages"` // Tags Tag[]; - Date string `json:"create_date"` - Pages int `json:"page_count"` - Views int `json:"total_view"` - Bookmarks int `json:"total_bookmarks"` } type Spotlight struct { diff --git a/handler/illust.go b/handler/illust.go index 3cbbf3d..a22c157 100644 --- a/handler/illust.go +++ b/handler/illust.go @@ -56,13 +56,45 @@ func GetNewestIllust(c *gin.Context) []entity.Illust { return illusts } +func GetRelatedIllust(c *gin.Context) []entity.Illust { + id := c.Param("id") + URL := "https://hibi.cocomi.cf/api/pixiv/related?id=" + id + var illusts []entity.Illust + + s := Request(URL) + g := GetInnerJSON(s, "illusts") + + err := json.Unmarshal([]byte(g), &illusts) + if err != nil { + panic("Failed to parse JSON") + } + + return illusts +} + +func GetIllustByID(c *gin.Context) entity.Illust { + id := c.Param("id") + URL := "https://hibi.cocomi.cf/api/pixiv/illust?id=" + id + var illust entity.Illust + + s := Request(URL) + g := GetInnerJSON(s, "illust") + + err := json.Unmarshal([]byte(g), &illust) + if err != nil { + panic(err) + } + + return illust +} + func GetSpotlightArticle(c *gin.Context) []entity.Spotlight { - // URL := "https://hibi.cocomi.cf/api/pixiv/spotlights?lang=en" - URL := "https://now.pixiv.pics/api/pixivision?lang=en" + URL := "https://hibi.cocomi.cf/api/pixiv/spotlights?lang=en" + // URL := "https://now.pixiv.pics/api/pixivision?lang=en" var articles []entity.Spotlight s := Request(URL) - g := GetInnerJSON(s, "articles") + g := GetInnerJSON(s, "spotlight_articles") err := json.Unmarshal([]byte(g), &articles) if err != nil { diff --git a/main.go b/main.go index 7fd1f40..162334e 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,12 @@ func inc(n int) int { return n + 1 } +func artwork_page(c *gin.Context) { + illust := handler.GetIllustByID(c) + related := handler.GetRelatedIllust(c) + c.HTML(http.StatusOK, "artwork.html", gin.H{"Illust": illust, "Related": related}) +} + func index_page(c *gin.Context) { recommended := handler.GetRecommendedIllust(c) ranking := handler.GetRankingIllust(c, "day") @@ -30,9 +36,11 @@ func main() { server.SetFuncMap(template.FuncMap{ "inc": inc, }) + server.StaticFile("/favicon.ico", "./template/favicon.ico") server.Static("css/", "./template/css") server.LoadHTMLGlob("template/*.html") server.GET("/", index_page) + server.GET("artworks/:id", artwork_page) - server.Run(":8000") + server.Run(":8080") } diff --git a/template/artwork.html b/template/artwork.html new file mode 100644 index 0000000..0960812 --- /dev/null +++ b/template/artwork.html @@ -0,0 +1,43 @@ +{{ template "header.html" }} +
+
+ {{ .Caption }}
+Tags
+