mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
ba3ec43559
thanks semgrep! Squashed commit of the following: commit 3a5e08190583804d3b330ecc6cb3422bc04c291b Author: iacore <noreply+gpg-stub@1a-insec.net> Date: Fri Feb 9 12:58:07 2024 +0000 final commit f1cdc73e9f8d331715de8e8aec5d1573218df0c3 Author: iacore <noreply+gpg-stub@1a-insec.net> Date: Fri Feb 9 12:50:23 2024 +0000 manual tweak commit 3a3ba2b8d8d7ce9af4d897288596d9318c715a08 Author: iacore <noreply+gpg-stub@1a-insec.net> Date: Fri Feb 9 12:49:15 2024 +0000 stage 1
115 lines
2.8 KiB
Go
115 lines
2.8 KiB
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
session "codeberg.org/vnpower/pixivfe/v2/core/config"
|
|
http "codeberg.org/vnpower/pixivfe/v2/core/http"
|
|
"github.com/goccy/go-json"
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
type Pixivision struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Thumbnail string `json:"thumbnailUrl"`
|
|
URL string `json:"url"`
|
|
}
|
|
|
|
type RecommendedTags struct {
|
|
Name string `json:"tag"`
|
|
Artworks []ArtworkBrief
|
|
}
|
|
type LandingArtworks struct {
|
|
Commissions []ArtworkBrief
|
|
Following []ArtworkBrief
|
|
Recommended []ArtworkBrief
|
|
Newest []ArtworkBrief
|
|
Rankings []ArtworkBrief
|
|
Users []ArtworkBrief
|
|
Pixivision []Pixivision
|
|
RecommendByTags []RecommendedTags
|
|
}
|
|
|
|
func GetLanding(c *fiber.Ctx, mode string) (LandingArtworks, error) {
|
|
var pages struct {
|
|
Pixivision []Pixivision `json:"pixivision"`
|
|
Follow []int `json:"follow"`
|
|
Recommended struct {
|
|
IDs []string `json:"ids"`
|
|
} `json:"recommend"`
|
|
// EditorRecommended []any `json:"editorRecommend"`
|
|
// UserRecommended []any `json:"recommendUser"`
|
|
// Commission []any `json:"completeRequestIds"`
|
|
RecommendedByTags []struct {
|
|
Name string `json:"tag"`
|
|
IDs []string `json:"ids"`
|
|
} `json:"recommendByTag"`
|
|
}
|
|
|
|
URL := http.GetLandingURL(mode)
|
|
|
|
var landing LandingArtworks
|
|
|
|
resp, err := http.UnwrapWebAPIRequest(URL, "")
|
|
|
|
if err != nil {
|
|
return landing, err
|
|
}
|
|
resp = session.ProxyImageUrl(resp)
|
|
|
|
artworks := map[string]ArtworkBrief{}
|
|
|
|
// Get thumbnails and save it into a map, since they were kept
|
|
// separately and need to the index quickly.
|
|
//
|
|
// Since there are no duplicates in this object, we are unable
|
|
// to rely to ranges (ex. one artwork in two separate sections)
|
|
stuff := gjson.Get(resp, "thumbnails.illust")
|
|
stuff.ForEach(func(key, value gjson.Result) bool {
|
|
var artwork ArtworkBrief
|
|
err = json.Unmarshal([]byte(value.String()), &artwork)
|
|
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
if artwork.ID != "" {
|
|
artworks[artwork.ID] = artwork
|
|
}
|
|
|
|
return true // keep iterating
|
|
})
|
|
|
|
pagesStr := gjson.Get(resp, "page").String()
|
|
err = json.Unmarshal([]byte(pagesStr), &pages)
|
|
|
|
if err != nil {
|
|
return landing, err
|
|
}
|
|
|
|
// Parse everything
|
|
landing.Pixivision = pages.Pixivision
|
|
|
|
landing.Following = make([]ArtworkBrief, len(pages.Follow))
|
|
for _, i := range pages.Follow {
|
|
landing.Following = append(landing.Following, artworks[fmt.Sprint(i)])
|
|
}
|
|
|
|
for _, i := range pages.RecommendedByTags {
|
|
temp := make([]ArtworkBrief, 0)
|
|
for _, j := range i.IDs {
|
|
temp = append(temp, artworks[j])
|
|
}
|
|
landing.RecommendByTags = append(landing.RecommendByTags, RecommendedTags{Name: i.Name, Artworks: temp})
|
|
}
|
|
|
|
landing.Recommended = make([]ArtworkBrief, 0)
|
|
for _, i := range pages.Recommended.IDs {
|
|
landing.Recommended = append(landing.Recommended, artworks[i])
|
|
}
|
|
|
|
return landing, nil
|
|
}
|