diff --git a/handler/constants.go b/handler/constants.go index 697131b..5ccf33f 100644 --- a/handler/constants.go +++ b/handler/constants.go @@ -17,4 +17,5 @@ const ( UserArtworksFullURL = "https://www.pixiv.net/ajax/user/%s/profile/illusts?work_category=illustManga&is_first_page=0&lang=en%s" UserBookmarksURL = "https://www.pixiv.net/ajax/user/%s/illusts/bookmarks?tag=&offset=%d&limit=48&rest=%s" FrequentTagsURL = "https://www.pixiv.net/ajax/tags/frequent/illust?%s" + LandingPageURL = "https://www.pixiv.net/ajax/top/illust?mode=%s" ) diff --git a/handler/top.go b/handler/top.go new file mode 100644 index 0000000..71b3ebe --- /dev/null +++ b/handler/top.go @@ -0,0 +1,55 @@ +package handler + +import ( + "fmt" + "pixivfe/models" + + "github.com/goccy/go-json" +) + +func (p *PixivClient) GetLandingPage(mode string) (models.LandingArtworks, error) { + var context models.LandingArtworks + URL := fmt.Sprintf(LandingPageURL, mode) + + response, err := p.PixivRequest(URL) + if err != nil { + return context, err + } + + var pages struct { + Follow []any `json:"follow"` + Commission []any `json:"completeRequestIds"` + } + + var body struct { + Thumbnails json.RawMessage `json:"thumbnails"` + Page json.RawMessage `json:"page"` + } + + var artworks struct { + Artworks []models.IllustShort `json:"illust"` + } + + err = json.Unmarshal([]byte(response), &body) + if err != nil { + return context, err + } + err = json.Unmarshal([]byte(body.Thumbnails), &artworks) + if err != nil { + return context, err + } + err = json.Unmarshal([]byte(body.Page), &pages) + if err != nil { + return context, err + } + + // Keep track + count := len(pages.Commission) + + context.Commissions = artworks.Artworks[:count] + context.Following = artworks.Artworks[count:len(pages.Follow)] + + count += len(pages.Follow) + + return context, nil +} diff --git a/models/models.go b/models/models.go index c5523e4..d85d496 100644 --- a/models/models.go +++ b/models/models.go @@ -213,3 +213,8 @@ func (s *SearchResult) ProxyImages(proxy string) { s.Popular.Permanent = ProxyShortArtworkSlice(s.Popular.Permanent, proxy) s.Popular.Recent = ProxyShortArtworkSlice(s.Popular.Recent, proxy) } + +type LandingArtworks struct { + Commissions []IllustShort + Following []IllustShort +} diff --git a/template/index.jet.html b/template/index.jet.html new file mode 100644 index 0000000..a9c8c4f --- /dev/null +++ b/template/index.jet.html @@ -0,0 +1,6 @@ +
+

Newest works by users you follow

+
{{ include "small-tn" Artworks.Following }}
+

Recently completed commissions

+
{{ include "small-tn" Artworks.Commissions }}
+
diff --git a/views/pages.go b/views/pages.go index 319be18..05623de 100644 --- a/views/pages.go +++ b/views/pages.go @@ -61,6 +61,10 @@ func artwork_page(c *fiber.Ctx) error { } func index_page(c *fiber.Ctx) error { + image_proxy := get_session_value(c, "image-proxy") + if image_proxy == nil { + image_proxy = &configs.ProxyServer + } // recommended, _ := handler.GetRecommendedIllust(c) // ranking, _ := handler.GetRankingIllust(c, "day") // spotlight := handler.GetSpotlightArticle(c) @@ -71,16 +75,15 @@ func index_page(c *fiber.Ctx) error { // "Spotlights": spotlight, // "Newest": newest, // }) - sess, err := configs.Store.Get(c) - if err != nil { - panic(err) - } - token := sess.Get("token") + // artworks, err := PC.GetLandingPage("all") + // if err != nil { + // return err + // } - if token != nil { - println(token.(string)) - } + // artworks.Following = models.ProxyShortArtworkSlice(artworks.Following, *image_proxy) + // artworks.Commissions = models.ProxyShortArtworkSlice(artworks.Commissions, *image_proxy) + // return c.Render("index", fiber.Map{"Title": "Landing", "Artworks": artworks}) return c.Render("temp", fiber.Map{"Title": "Landing"}) }