Feature: base code for landing/index page
This commit is contained in:
parent
516d68b8a6
commit
c1e522003d
5 changed files with 78 additions and 8 deletions
|
@ -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"
|
||||
)
|
||||
|
|
55
handler/top.go
Normal file
55
handler/top.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
6
template/index.jet.html
Normal file
6
template/index.jet.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
<div class="container">
|
||||
<h2>Newest works by users you follow</h2>
|
||||
<div class="thumbnail-container">{{ include "small-tn" Artworks.Following }}</div>
|
||||
<h2>Recently completed commissions</h2>
|
||||
<div class="thumbnail-container">{{ include "small-tn" Artworks.Commissions }}</div>
|
||||
</div>
|
|
@ -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"})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue