Feature: discovery page
This commit is contained in:
parent
c1f62a8b81
commit
62cafeea11
5 changed files with 66 additions and 0 deletions
|
@ -29,6 +29,7 @@ const (
|
|||
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"
|
||||
ArtworkRankingURL = "https://www.pixiv.net/ranking.php?format=json&mode=%s&content=%s&p=%s"
|
||||
ArtworkDiscoveryURL = "https://www.pixiv.net/ajax/discovery/artworks?mode=%s&limit=100"
|
||||
SearchTagURL = "https://www.pixiv.net/ajax/search/tags/%s"
|
||||
SearchArtworksURL = "https://www.pixiv.net/ajax/search/%s/%s?order=%s&mode=%s&p=%s"
|
||||
SearchTopURL = "https://www.pixiv.net/ajax/search/top/%s"
|
||||
|
@ -497,3 +498,36 @@ func (p *PixivClient) GetSearch(artworkType string, name string, order string, a
|
|||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (p *PixivClient) GetDiscoveryArtwork(mode string) ([]models.IllustShort, error) {
|
||||
var pr models.PixivResponse
|
||||
var artworks []models.IllustShort
|
||||
|
||||
url := fmt.Sprintf(ArtworkDiscoveryURL, mode)
|
||||
|
||||
s, err := p.TextRequest(url)
|
||||
|
||||
err = json.Unmarshal([]byte(s), &pr)
|
||||
|
||||
if err != nil {
|
||||
return artworks, errors.New("Error")
|
||||
}
|
||||
|
||||
if pr.Error {
|
||||
return artworks, errors.New(pr.Message)
|
||||
}
|
||||
|
||||
var thumbnail struct {
|
||||
Data json.RawMessage `json:"thumbnails"`
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(pr.Body), &thumbnail)
|
||||
|
||||
var body struct {
|
||||
Artworks []models.IllustShort `json:"illust"`
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(thumbnail.Data), &body)
|
||||
|
||||
return body.Artworks, nil
|
||||
}
|
||||
|
|
BIN
template/assets/compass.png
Normal file
BIN
template/assets/compass.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
17
template/discovery.html
Normal file
17
template/discovery.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
{{ template "header.html" }}
|
||||
|
||||
<div class="container">
|
||||
<h2>Newest works from all users</h2>
|
||||
<div class="switcher">
|
||||
<span class="switch-title">Filter</span>
|
||||
<a href="/discovery?mode=all" class="switch-button">All</a>
|
||||
<a href="/discovery?mode=safe" class="switch-button">Safe</a>
|
||||
<a href="/discovery?mode=r18" class="switch-button">R-18</a>
|
||||
</div>
|
||||
<div>{{ template "small-tn.html" .Artworks }}</div>
|
||||
<div class="pagination">
|
||||
<a href="" class="pagination-button">Reload</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ template "footer.html" }}
|
|
@ -79,6 +79,9 @@
|
|||
|
||||
<div class="sidebar">
|
||||
<ul class="sidebar-list">
|
||||
<a class="sidebar-item" href="/discovery">
|
||||
<img src="/assets/compass.png" alt="icon" />Discovery</a
|
||||
>
|
||||
<a class="sidebar-item" href="/ranking">
|
||||
<img src="/assets/crown.png" alt="icon" />Ranking</a
|
||||
>
|
||||
|
|
|
@ -149,6 +149,17 @@ func search(c *gin.Context) {
|
|||
c.Redirect(http.StatusFound, "/tags/"+name)
|
||||
}
|
||||
|
||||
func discovery_page(c *gin.Context) {
|
||||
mode, ok := c.GetQuery("mode")
|
||||
|
||||
if !ok {
|
||||
mode = "all"
|
||||
}
|
||||
|
||||
artworks, _ := PC.GetDiscoveryArtwork(mode)
|
||||
c.HTML(http.StatusOK, "discovery.html", gin.H{"Artworks": artworks})
|
||||
}
|
||||
|
||||
func NewPixivClient(timeout int) *models.PixivClient {
|
||||
transport := &http.Transport{Proxy: http.ProxyFromEnvironment}
|
||||
client := &http.Client{
|
||||
|
@ -176,5 +187,6 @@ func SetupRoutes(r *gin.Engine) {
|
|||
r.GET("newest", newestArtworksPage)
|
||||
r.GET("ranking", ranking_page)
|
||||
r.GET("tags/:name", search_page)
|
||||
r.GET("discovery", discovery_page)
|
||||
r.POST("tags", search)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue