mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
Feature: add frequent tags (check out any user page)
This commit is contained in:
+36
-9
@@ -35,6 +35,7 @@ const (
|
||||
UserInformationURL = "https://www.pixiv.net/ajax/user/%s?full=1"
|
||||
UserArtworksURL = "https://www.pixiv.net/ajax/user/%s/profile/all"
|
||||
UserArtworksFullURL = "https://www.pixiv.net/ajax/user/%s/profile/illusts?work_category=illustManga&is_first_page=0&lang=en%s"
|
||||
FrequentTagsURL = "https://www.pixiv.net/ajax/tags/frequent/illust?%s"
|
||||
)
|
||||
|
||||
func (p *PixivClient) SetHeader(header map[string]string) {
|
||||
@@ -146,6 +147,28 @@ func (p *PixivClient) GetArtworkImages(id string) ([]models.Image, error) {
|
||||
return images, nil
|
||||
}
|
||||
|
||||
func (p *PixivClient) GetFrequentTags(ids string) ([]models.FrequentTag, error) {
|
||||
s, _ := p.TextRequest(fmt.Sprintf(FrequentTagsURL, ids))
|
||||
|
||||
var pr models.PixivResponse
|
||||
var tags []models.FrequentTag
|
||||
// Parse Pixiv response body
|
||||
err := json.Unmarshal([]byte(s), &pr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if pr.Error {
|
||||
return nil, errors.New(fmt.Sprintf("Pixiv returned error message: %s", pr.Message))
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(pr.Body), &tags)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (p *PixivClient) GetArtworkByID(id string) (*models.Illust, error) {
|
||||
s, _ := p.TextRequest(fmt.Sprintf(ArtworkInformationURL, id))
|
||||
|
||||
@@ -322,20 +345,16 @@ func (p *PixivClient) GetRelatedArtworks(id string) ([]models.IllustShort, error
|
||||
return body.Illusts, nil
|
||||
}
|
||||
|
||||
func (p *PixivClient) GetUserArtworks(id string, page int) ([]models.IllustShort, error) {
|
||||
ids, err := p.GetUserArtworksID(id, page)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func (p *PixivClient) GetUserArtworks(id string, ids string) ([]models.IllustShort, error) {
|
||||
|
||||
url := fmt.Sprintf(UserArtworksFullURL, id, *ids)
|
||||
url := fmt.Sprintf(UserArtworksFullURL, id, ids)
|
||||
|
||||
var pr models.PixivResponse
|
||||
var works []models.IllustShort
|
||||
|
||||
s, _ := p.TextRequest(url)
|
||||
|
||||
err = json.Unmarshal([]byte(s), &pr)
|
||||
err := json.Unmarshal([]byte(s), &pr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -370,9 +389,14 @@ func (p *PixivClient) GetUserInformation(id string, page int) (*models.User, err
|
||||
var user *models.User
|
||||
var pr models.PixivResponse
|
||||
|
||||
ids, err := p.GetUserArtworksID(id, page)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s, _ := p.TextRequest(fmt.Sprintf(UserInformationURL, id))
|
||||
|
||||
err := json.Unmarshal([]byte(s), &pr)
|
||||
err = json.Unmarshal([]byte(s), &pr)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -395,7 +419,7 @@ func (p *PixivClient) GetUserInformation(id string, page int) (*models.User, err
|
||||
user = body.User
|
||||
|
||||
// Artworks
|
||||
works, _ := p.GetUserArtworks(id, page)
|
||||
works, _ := p.GetUserArtworks(id, *ids)
|
||||
user.Artworks = works
|
||||
|
||||
// Background image
|
||||
@@ -406,6 +430,9 @@ func (p *PixivClient) GetUserInformation(id string, page int) (*models.User, err
|
||||
// Artworks count
|
||||
// user.ArtworksCount, _ = p.GetUserArtworksCount(id)
|
||||
|
||||
// Frequent tags
|
||||
user.FrequentTags, err = p.GetFrequentTags(*ids)
|
||||
|
||||
return user, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,11 @@ type Tag struct {
|
||||
TranslatedName string `json:"translation"`
|
||||
}
|
||||
|
||||
type FrequentTag struct {
|
||||
Name string `json:"tag"`
|
||||
TranslatedName string `json:"tag_translation"`
|
||||
}
|
||||
|
||||
type Illust struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
@@ -139,6 +144,7 @@ type User struct {
|
||||
Comment template.HTML `json:"commentHtml"`
|
||||
Artworks []IllustShort `json:"artworks"`
|
||||
ArtworksCount int
|
||||
FrequentTags []FrequentTag
|
||||
}
|
||||
|
||||
type RankedArtwork struct {
|
||||
|
||||
@@ -395,6 +395,7 @@ body {
|
||||
background-color: #262a2b;
|
||||
display: inline-block;
|
||||
padding: 5px 10px;
|
||||
margin-bottom: 4px;
|
||||
text-decoration: none;
|
||||
color: #d8d4cf;
|
||||
font-weight: bold;
|
||||
|
||||
@@ -463,6 +463,7 @@ body {
|
||||
background-color: $bg-alt;
|
||||
display: inline-block;
|
||||
padding: 5px 10px;
|
||||
margin-bottom: 4px;
|
||||
text-decoration: none;
|
||||
color: $fg;
|
||||
font-weight: bold;
|
||||
|
||||
+9
-20
@@ -8,11 +8,7 @@
|
||||
<div class="container">
|
||||
<div class="user-page">
|
||||
<div class="user-details">
|
||||
<img
|
||||
src="{{ proxyImage(User.Avatar) }}"
|
||||
alt="avatar"
|
||||
class="user-avatar"
|
||||
/>
|
||||
<img src="{{ proxyImage(User.Avatar) }}" alt="avatar" class="user-avatar" />
|
||||
<h2 class="user-name">{{ User.Name }}</h2>
|
||||
<p class="user-id">
|
||||
{{ User.Following }} Following | {{ User.MyPixiv }} MyPixiv
|
||||
@@ -20,6 +16,11 @@
|
||||
<p class="user-comment">{{ raw: User.Comment }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
{{ range User.FrequentTags }}
|
||||
<a class="tag-container" href="/tags/{{ .Name }}">#{{ .Name }}</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
<div>
|
||||
<h1>Illustrations and Mangas</h1>
|
||||
{{ include "small-tn" User.Artworks }}
|
||||
@@ -30,11 +31,7 @@
|
||||
<a href="#" class="pagination-button disabled">Previous</a>
|
||||
{{ else }}
|
||||
<a href="/users/{{ User.ID }}?page=1" class="pagination-button">First</a>
|
||||
<a
|
||||
href="/users/{{ User.ID }}?page={{ dec(Page) }}"
|
||||
class="pagination-button"
|
||||
>Previous</a
|
||||
>
|
||||
<a href="/users/{{ User.ID }}?page={{ dec(Page) }}" class="pagination-button">Previous</a>
|
||||
{{ end }}
|
||||
|
||||
<a href="#" class="pagination-button disabled">{{ Page }}</a>
|
||||
@@ -43,16 +40,8 @@
|
||||
<a href="#" class="pagination-button disabled">Next</a>
|
||||
<a href="#" class="pagination-button disabled">Last</a>
|
||||
{{ else }}
|
||||
<a
|
||||
href="/users/{{ User.ID }}?page={{ inc(Page) }}"
|
||||
class="pagination-button"
|
||||
>Next</a
|
||||
>
|
||||
<a
|
||||
href="/users/{{ User.ID }}?page={{ dec(PageLimit) }}"
|
||||
class="pagination-button"
|
||||
>Last</a
|
||||
>
|
||||
<a href="/users/{{ User.ID }}?page={{ inc(Page) }}" class="pagination-button">Next</a>
|
||||
<a href="/users/{{ User.ID }}?page={{ dec(PageLimit) }}" class="pagination-button">Last</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user