mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
index.go: Reorganize code
This commit is contained in:
+59
-54
@@ -12,6 +12,57 @@ import (
|
||||
"codeberg.org/vnpower/pixivfe/v2/server/session"
|
||||
)
|
||||
|
||||
// Pages is a helper struct for parsing Pixiv's API
|
||||
// Each field should represent a section of the index page
|
||||
// Some fields' type can be a separate struct.
|
||||
// Structs made specifically for this struct must all have the suffix "SN" to distinguish themselves from other structs
|
||||
type Pages struct {
|
||||
Pixivision []Pixivision `json:"pixivision"`
|
||||
Follow []int `json:"follow"`
|
||||
Recommended RecommendedSN `json:"recommend"`
|
||||
RecommendedByTag []RecommendByTagSN `json:"recommendByTag"`
|
||||
RecommendUser []RecommendUserSN `json:"recommendUser"`
|
||||
TrendingTag []TrendingTagSN `json:"trendingTags"`
|
||||
Newest []string `json:"newPost"`
|
||||
|
||||
// Commented out fields that aren't currently implemented in the frontend
|
||||
// EditorRecommended []any `json:"editorRecommend"`
|
||||
// RecommendedUsers []RecommendedUser `json:"recommendUser"`
|
||||
// Commission []any `json:"completeRequestIds"`
|
||||
// BoothFollows []BoothFollow `json:"boothFollowItemIds"`
|
||||
// OngoingContests []Contest `json:"contestOngoing"`
|
||||
// ContestResult []Contest `json:"contestResult"`
|
||||
// FavoriteTags []any `json:"myFavoriteTags"`
|
||||
// MyPixiv []any `json:"mypixiv"`
|
||||
//"ranking",
|
||||
//"sketchLiveFollowIds",
|
||||
//"sketchLivePopularIds",
|
||||
//"tags",
|
||||
//"trendingTags",
|
||||
//"userEventIds"
|
||||
|
||||
// These aren't included as pages
|
||||
// "requests"
|
||||
//"illustSeries"
|
||||
// SketchLives []SketchLive `json:"sketchLives"`
|
||||
// BoothItems []BoothItem `json:"boothItems"`
|
||||
}
|
||||
|
||||
type TrendingTagSN struct {
|
||||
Name string `json:"tag"`
|
||||
TrendingRate int `json:"trendingRate"`
|
||||
IDs []int `json:"ids"`
|
||||
}
|
||||
|
||||
type RecommendedSN struct {
|
||||
IDs []string `json:"ids"`
|
||||
}
|
||||
|
||||
type RecommendByTagSN struct {
|
||||
Name string `json:"tag"`
|
||||
IDs []string `json:"ids"`
|
||||
}
|
||||
|
||||
// Pixivision represents a Pixivision article as returned by the landing page endpoint.
|
||||
//
|
||||
// Note that this type is less complete than the PixivisionArticle type.
|
||||
@@ -25,7 +76,7 @@ type Pixivision struct {
|
||||
// RecommendUser represents a recommended user as returned by the landing page endpoint.
|
||||
//
|
||||
// This type is distinct from the User type.
|
||||
type RecommendUser struct {
|
||||
type RecommendUserSN struct {
|
||||
ID int `json:"id"`
|
||||
IllustIDs []string `json:"illustIds"`
|
||||
NovelIDs []string `json:"novelIds"` // Unimplemented
|
||||
@@ -33,14 +84,14 @@ type RecommendUser struct {
|
||||
|
||||
// RecommendedTags groups artworks under a specific tag recommendation.
|
||||
type RecommendedTags struct {
|
||||
Name string `json:"tag"`
|
||||
Name string
|
||||
Artworks []ArtworkBrief
|
||||
}
|
||||
|
||||
type PopularTag struct {
|
||||
Name string `json:"tag"`
|
||||
TrendingRate int `json:"trendingRate"`
|
||||
IDs []int `json:"ids"`
|
||||
Name string
|
||||
TrendingRate int
|
||||
IDs []int
|
||||
Artworks []ArtworkBrief
|
||||
}
|
||||
|
||||
@@ -59,52 +110,6 @@ type LandingArtworks struct {
|
||||
PopularTag []PopularTag
|
||||
}
|
||||
|
||||
// VnPower: sort alphabetically
|
||||
type Pages struct {
|
||||
Pixivision []Pixivision `json:"pixivision"`
|
||||
Follow []int `json:"follow"`
|
||||
Recommended RecommendedSection `json:"recommend"`
|
||||
RecommendedByTag []RecommendByTag `json:"recommendByTag"`
|
||||
RecommendUser []RecommendUser `json:"recommendUser"`
|
||||
// Commented out fields that aren't currently implemented in the frontend
|
||||
// EditorRecommended []any `json:"editorRecommend"`
|
||||
// RecommendedUsers []RecommendedUser `json:"recommendUser"`
|
||||
// Commission []any `json:"completeRequestIds"`
|
||||
TrendingTag []TrendingTag `json:"trendingTags"`
|
||||
// BoothFollows []BoothFollow `json:"boothFollowItemIds"`
|
||||
// OngoingContests []Contest `json:"contestOngoing"`
|
||||
// ContestResult []Contest `json:"contestResult"`
|
||||
// FavoriteTags []any `json:"myFavoriteTags"`
|
||||
// MyPixiv []any `json:"mypixiv"`
|
||||
Newest []string `json:"newPost"`
|
||||
//"ranking",
|
||||
//"sketchLiveFollowIds",
|
||||
//"sketchLivePopularIds",
|
||||
//"tags",
|
||||
//"trendingTags",
|
||||
//"userEventIds"
|
||||
|
||||
// These aren't included as pages
|
||||
// "requests"
|
||||
//"illustSeries"
|
||||
// SketchLives []SketchLive `json:"sketchLives"`
|
||||
// BoothItems []BoothItem `json:"boothItems"`
|
||||
}
|
||||
|
||||
type TrendingTag struct {
|
||||
Name string `json:"tag"`
|
||||
TrendingRate int `json:"trendingRate"`
|
||||
IDs []int `json:"ids"`
|
||||
}
|
||||
|
||||
type RecommendedSection struct {
|
||||
IDs []string `json:"ids"`
|
||||
}
|
||||
|
||||
type RecommendByTag struct {
|
||||
Name string `json:"tag"`
|
||||
IDs []string `json:"ids"`
|
||||
}
|
||||
|
||||
// Constants for calling GetNewestFromFollowing when len(followIDs) == 0
|
||||
const (
|
||||
@@ -279,7 +284,7 @@ func populateRecommended(recommendedIDs []string, artworks map[string]ArtworkBri
|
||||
}
|
||||
|
||||
// populateRecommendedByTags uses the generic helper for each tag's IDs.
|
||||
func populateRecommendedByTags(recommends []RecommendByTag, artworks map[string]ArtworkBrief) []RecommendedTags {
|
||||
func populateRecommendedByTags(recommends []RecommendByTagSN, artworks map[string]ArtworkBrief) []RecommendedTags {
|
||||
recommendByTags := make([]RecommendedTags, 0, len(recommends))
|
||||
|
||||
for _, r := range recommends {
|
||||
@@ -294,7 +299,7 @@ func populateRecommendedByTags(recommends []RecommendByTag, artworks map[string]
|
||||
}
|
||||
|
||||
// populateRecommendUsers is a generic helper function.
|
||||
func populateRecommendUsers(recommendUsers []RecommendUser, users map[string]User, artworks map[string]ArtworkBrief) []User {
|
||||
func populateRecommendUsers(recommendUsers []RecommendUserSN, users map[string]User, artworks map[string]ArtworkBrief) []User {
|
||||
populated := make([]User, 0, len(recommendUsers))
|
||||
|
||||
for _, recommendUser := range recommendUsers {
|
||||
@@ -309,7 +314,7 @@ func populateRecommendUsers(recommendUsers []RecommendUser, users map[string]Use
|
||||
return populated
|
||||
}
|
||||
|
||||
func populatePopularTags(tags []TrendingTag, artworks map[string]ArtworkBrief) []PopularTag {
|
||||
func populatePopularTags(tags []TrendingTagSN, artworks map[string]ArtworkBrief) []PopularTag {
|
||||
populated := make([]PopularTag, 0, len(tags))
|
||||
|
||||
for _, tag := range tags {
|
||||
|
||||
Reference in New Issue
Block a user