Feature: history rankings #20

This commit is contained in:
VnPower 2023-08-23 21:08:25 +07:00
parent 35cc3201bc
commit 85b7e918ab
Signed by: vnpower
GPG key ID: 881DE3DEB966106C
6 changed files with 96 additions and 71 deletions

View file

@ -6,7 +6,7 @@ const (
ArtworkRelatedURL = "https://www.pixiv.net/ajax/illust/%s/recommend/init?limit=%d" ArtworkRelatedURL = "https://www.pixiv.net/ajax/illust/%s/recommend/init?limit=%d"
ArtworkCommentsURL = "https://www.pixiv.net/ajax/illusts/comments/roots?illust_id=%s&limit=100" ArtworkCommentsURL = "https://www.pixiv.net/ajax/illusts/comments/roots?illust_id=%s&limit=100"
ArtworkNewestURL = "https://www.pixiv.net/ajax/illust/new?limit=30&type=%s&r18=%s&lastId=%s" ArtworkNewestURL = "https://www.pixiv.net/ajax/illust/new?limit=30&type=%s&r18=%s&lastId=%s"
ArtworkRankingURL = "https://www.pixiv.net/ranking.php?format=json&mode=%s&content=%s&date=%s&p=%s" ArtworkRankingURL = "https://www.pixiv.net/ranking.php?format=json&mode=%s&content=%s%s&p=%s"
ArtworkDiscoveryURL = "https://www.pixiv.net/ajax/discovery/artworks?mode=%s&limit=%d" ArtworkDiscoveryURL = "https://www.pixiv.net/ajax/discovery/artworks?mode=%s&limit=%d"
SearchTagURL = "https://www.pixiv.net/ajax/search/tags/%s" SearchTagURL = "https://www.pixiv.net/ajax/search/tags/%s"
SearchArtworksURL = "https://www.pixiv.net/ajax/search/%s/%s?order=%s&mode=%s&p=%s" SearchArtworksURL = "https://www.pixiv.net/ajax/search/%s/%s?order=%s&mode=%s&p=%s"

View file

@ -41,6 +41,10 @@ func (p *PixivClient) GetRanking(mode string, content string, date string, page
// Ranking data is formatted differently // Ranking data is formatted differently
var pr models.RankingResponse var pr models.RankingResponse
if len(date) > 0 {
date = "&date=" + date
}
url := fmt.Sprintf(ArtworkRankingURL, mode, content, date, page) url := fmt.Sprintf(ArtworkRankingURL, mode, content, date, page)
s, err := p.TextRequest(url) s, err := p.TextRequest(url)
@ -53,6 +57,8 @@ func (p *PixivClient) GetRanking(mode string, content string, date string, page
if err != nil { if err != nil {
return pr, err return pr, err
} }
pr.PrevDate = strings.ReplaceAll(string(pr.PrevDateRaw[:]), "\"", "")
pr.NextDate = strings.ReplaceAll(string(pr.NextDateRaw[:]), "\"", "")
return pr, nil return pr, nil
} }

View file

@ -33,6 +33,14 @@ func ProxyRecommendedByTagsSlice(artworks []LandingRecommendByTags, proxy string
return artworks return artworks
} }
func ProxyRankedArtworkSlice(artworks []RankedArtwork, proxy string) []RankedArtwork {
for i := range artworks {
artworks[i].Image = ProxyImage(artworks[i].Image, proxy)
artworks[i].ArtistAvatar = ProxyImage(artworks[i].ArtistAvatar, proxy)
}
return artworks
}
func ProxyCommentsSlice(comments []Comment, proxy string) []Comment { func ProxyCommentsSlice(comments []Comment, proxy string) []Comment {
for i := range comments { for i := range comments {
comments[i].Avatar = ProxyImage(comments[i].Avatar, proxy) comments[i].Avatar = ProxyImage(comments[i].Avatar, proxy)

View file

@ -20,9 +20,18 @@ type PixivResponse struct {
} }
type RankingResponse struct { type RankingResponse struct {
Artworks []RankedArtwork `json:"contents"` Artworks []RankedArtwork `json:"contents"`
Mode string `json:"mode"` Mode string `json:"mode"`
Content string `json:"content"` Content string `json:"content"`
CurrentDate string `json:"date"`
PrevDateRaw json.RawMessage `json:"prev_date"`
NextDateRaw json.RawMessage `json:"next_date"`
PrevDate string
NextDate string
}
func (s *RankingResponse) ProxyImages(proxy string) {
s.Artworks = ProxyRankedArtworkSlice(s.Artworks, proxy)
} }
type ImageResponse struct { type ImageResponse struct {

View file

@ -1,70 +1,77 @@
<div class="container"> <div class="container">
<h2>{{ Title }}</h2> <h2>{{ Title }}</h2>
<div class="switcher"> <div class="switcher">
{{ url := "/ranking?mode=" + Queries.Mode + "&page=1&content=" }} {{ url := "/ranking?mode=" + Queries.Mode + "&date=" + Data.CurrentDate + "&page=1&content=" }}
<span class="switch-title">Content</span> <span class="switch-title">Content</span>
<a href="{{ url }}all" class="switch-button">Overall</a> <a href="{{ url }}all" class="switch-button">Overall</a>
<a href="{{ url }}illust" class="switch-button">Illustrations</a> <a href="{{ url }}illust" class="switch-button">Illustrations</a>
<a href="{{ url }}manga" class="switch-button">Mangas</a> <a href="{{ url }}manga" class="switch-button">Mangas</a>
</div> </div>
<br /> <br />
<div class="switcher"> <div class="switcher">
{{ url := "/ranking?content=" + Queries.Content + "&page=1&mode=" }} {{ url := "/ranking?content=" + Queries.Content +"&date=" + Data.CurrentDate + "&page=1&mode=" }}
<span class="switch-title">Modes</span> <span class="switch-title">Modes</span>
<a href="{{ url }}daily" class="switch-button">Daily</a> <a href="{{ url }}daily" class="switch-button">Daily</a>
<a href="{{ url }}weekly" class="switch-button">Weekly</a> <a href="{{ url }}weekly" class="switch-button">Weekly</a>
<a href="{{ url }}monthly" class="switch-button">Monthly</a> <a href="{{ url }}monthly" class="switch-button">Monthly</a>
<a href="{{ url }}rookie" class="switch-button">Rookie</a> <a href="{{ url }}rookie" class="switch-button">Rookie</a>
<span class="switch-seperator"></span> <span class="switch-seperator"></span>
<a href="{{ url }}daily_r18" class="switch-button">Daily (R-18)</a> <a href="{{ url }}daily_r18" class="switch-button">Daily (R-18)</a>
<a href="{{ url }}weekly_r18" class="switch-button">Weekly (R-18)</a> <a href="{{ url }}weekly_r18" class="switch-button">Weekly (R-18)</a>
</div> </div>
<br /> <br />
{{ range Items }} <div class="switcher">
<div class="artwork-thumbnail-small artwork-thumbnail artwork-mobile"> {{ url := "/ranking?content=" + Queries.Content + "&mode=" + Queries.Mode + "&page=1" }}
<div class="artwork-rank-circle">{{ .Rank }}</div> <span class="switch-title">Date</span>
{{ if toInt(.Pages) > 1 }} {{ if Data.PrevDate != "false" }}
<div class="artwork-page-count"><span>&boxbox; {{ .Pages }}</span></div> <a href="{{ url }}&date={{Data.PrevDate}}" class="switch-button">Yesterday</a>
{{ end }} {{ end }}
<a href="/artworks/{{ .ID }}"> {{ if Data.NextDate != "false" }}
<img src="{{ .Image }}" alt="{{ .Title }}" class="artwork-master-image" /> <a href="{{ url }}&date={{Data.NextDate}}" class="switch-button">Next day</a>
</a> {{ end }}
<a href="{{ url }}" class="switch-button">Latest</a>
</div>
<br />
<a class="artwork-thumbnail-title" href="/artworks/{{ .ID }}"> {{ range Data.Artworks }}
<h3 class="no-margin">{{ .Title }}</h3> <div class="artwork-thumbnail-small artwork-thumbnail artwork-mobile">
</a> <div class="artwork-rank-circle">{{ .Rank }}</div>
<a href="/users/{{ .ArtistID }}" class="artwork-thumbnail-artist flex" {{ if toInt(.Pages) > 1 }}
><img <div class="artwork-page-count"><span>&boxbox; {{ .Pages }}</span></div>
src="{{ .ArtistAvatar }}" {{ end }}
alt="{{ .ArtistName }}" <a href="/artworks/{{ .ID }}">
class="artwork-thumbnail-artist-avatar border-rounded" <img src="{{ .Image }}" alt="{{ .Title }}" class="artwork-master-image" />
/> </a>
{{ .ArtistName }}</a
>
</div>
{{ end }}
<div class="pagination"> <a class="artwork-thumbnail-title" href="/artworks/{{ .ID }}">
{{ url := "/ranking?content=" + Queries.Content + "&mode=" + Queries.Mode + <h3 class="no-margin">{{ .Title }}</h3>
"&page=" }} {{ if Page <= 1 }} </a>
<a href="#" class="pagination-button disabled">First</a> <a href="/users/{{ .ArtistID }}" class="artwork-thumbnail-artist flex"><img src="{{ .ArtistAvatar }}"
<a href="#" class="pagination-button disabled">Previous</a> alt="{{ .ArtistName }}" class="artwork-thumbnail-artist-avatar border-rounded" />
{{ else }} {{ .ArtistName }}</a>
<a href="{{ url }}1" class="pagination-button">First</a> </div>
<a href="{{ url }}{{ Page - 1 }}" class="pagination-button">Previous</a>
{{ end }} {{ end }}
<a href="#" class="pagination-button disabled">{{ Page }}</a> <div class="pagination">
{{ url := "/ranking?content=" + Queries.Content +"&date=" + Data.CurrentDate + "&mode=" + Queries.Mode +
"&page=" }} {{ if Page <= 1 }} <a href="#" class="pagination-button disabled">First</a>
<a href="#" class="pagination-button disabled">Previous</a>
{{ else }}
<a href="{{ url }}1" class="pagination-button">First</a>
<a href="{{ url }}{{ Page - 1 }}" class="pagination-button">Previous</a>
{{ end }}
{{ if Page == 10 }} <a href="#" class="pagination-button disabled">{{ Page }}</a>
<a href="#" class="pagination-button disabled">Next</a>
<a href="#" class="pagination-button disabled">Last</a> {{ if Page == 10 }}
{{ else }} <a href="#" class="pagination-button disabled">Next</a>
<a href="{{ url }}{{ Page + 1 }}" class="pagination-button">Next</a> <a href="#" class="pagination-button disabled">Last</a>
<a href="{{ url }}10" class="pagination-button">Last</a> {{ else }}
{{ end }} <a href="{{ url }}{{ Page + 1 }}" class="pagination-button">Next</a>
</div> <a href="{{ url }}10" class="pagination-button">Last</a>
{{ end }}
</div>
</div> </div>

View file

@ -141,16 +141,11 @@ func ranking_page(c *fiber.Ctx) error {
return err return err
} }
artworks := response.Artworks response.ProxyImages(*image_proxy)
for i := range artworks {
artworks[i].Image = models.ProxyImage(artworks[i].Image, *image_proxy)
artworks[i].ArtistAvatar = models.ProxyImage(artworks[i].ArtistAvatar, *image_proxy)
}
return c.Render("pages/rank", fiber.Map{ return c.Render("pages/rank", fiber.Map{
"Title": "Ranking", "Title": "Ranking",
"Items": artworks, "Data": response,
"Queries": queries, "Queries": queries,
"Page": pageInt, "Page": pageInt,
}) })