This commit is contained in:
VnPower
2024-01-20 22:33:00 +07:00
parent 7ed0d85c6a
commit e803899243
5 changed files with 150 additions and 1 deletions
+15
View File
@@ -71,18 +71,33 @@ func GetArtworkInformationURL(id string) string {
return fmt.Sprintf(base, id)
}
func GetArtworkImagesURL(id string) string {
base := "https://www.pixiv.net/ajax/illust/%s/pages"
return fmt.Sprintf(base, id)
}
func GetArtworkRelatedURL(id string, limit int) string {
base := "https://www.pixiv.net/ajax/illust/%s/recommend/init?limit=%d"
return fmt.Sprintf(base, id, limit)
}
func GetArtworkCommentsURL(id string) string {
base := "https://www.pixiv.net/ajax/illusts/comments/roots?illust_id=%s&limit=100"
return fmt.Sprintf(base, id)
}
func GetTagDetailURL(id string) string {
base := "https://www.pixiv.net/ajax/search/tags/%s"
return fmt.Sprintf(base, id)
}
func GetSearchArtworksURL(artworkType, name, order, age_settings, page string) string {
base := "https://www.pixiv.net/ajax/search/%s/%s?order=%s&mode=%s&p=%s"
return fmt.Sprintf(base, artworkType, name, order, age_settings, page)
}
+95
View File
@@ -0,0 +1,95 @@
package core
import (
"strings"
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"
)
type TagDetail struct {
Name string `json:"tag"`
AlternativeName string `json:"word"`
Metadata struct {
Detail string `json:"abstract"`
Image string `json:"image"`
Name string `json:"tag"`
ID json.Number `json:"id"`
} `json:"pixpedia"`
}
type SearchArtworks struct {
Artworks []ArtworkBrief `json:"data"`
Total int `json:"total"`
}
type SearchResult struct {
Artworks SearchArtworks
Popular struct {
Permanent []ArtworkBrief `json:"permanent"`
Recent []ArtworkBrief `json:"recent"`
} `json:"popular"`
RelatedTags []string `json:"relatedTags"`
}
func GetTagData(c *fiber.Ctx, name string) (TagDetail, error) {
var tag TagDetail
imageProxy := session.GetImageProxy(c)
URL := http.GetTagDetailURL(name)
response, err := http.UnwrapWebAPIRequest(URL, "")
if err != nil {
return tag, err
}
response = ProxyImages(response, imageProxy)
err = json.Unmarshal([]byte(response), &tag)
if err != nil {
return tag, err
}
return tag, nil
}
func GetSearch(c *fiber.Ctx, artworkType, name, order, age_settings, page string) (*SearchResult, error) {
imageProxy := session.GetImageProxy(c)
URL := http.GetSearchArtworksURL(artworkType, name, order, age_settings, page)
response, err := http.UnwrapWebAPIRequest(URL, "")
if err != nil {
return nil, err
}
response = ProxyImages(response, imageProxy)
// IDK how to do better than this lol
temp := strings.ReplaceAll(string(response), `"illust"`, `"works"`)
temp = strings.ReplaceAll(temp, `"manga"`, `"works"`)
temp = strings.ReplaceAll(temp, `"illustManga"`, `"works"`)
var resultRaw struct {
*SearchResult
ArtworksRaw json.RawMessage `json:"works"`
}
var artworks SearchArtworks
var result *SearchResult
err = json.Unmarshal([]byte(temp), &resultRaw)
if err != nil {
return nil, err
}
result = resultRaw.SearchResult
err = json.Unmarshal([]byte(resultRaw.ArtworksRaw), &artworks)
if err != nil {
return nil, err
}
result.Artworks = artworks
return result, nil
}
+9
View File
@@ -3,6 +3,7 @@ package main
import (
"log"
"net"
"net/http"
"os"
"time"
@@ -130,6 +131,14 @@ func main() {
self.Get("/followingWorks", pages.FollowingWorksPage)
self.Get("/bookmarks", pages.LoginBookmarkPage)
server.Get("tags/:name", pages.TagPage)
server.Post("tags",
func(c *fiber.Ctx) error {
name := c.FormValue("name")
return c.Redirect("/tags/"+name, http.StatusFound)
})
// Legacy illust URL
server.Get("member_illust.php", func(c *fiber.Ctx) error {
return c.Redirect("artworks/" + c.Query("illust_id"))
+31
View File
@@ -0,0 +1,31 @@
package pages
import (
"strconv"
core "codeberg.org/vnpower/pixivfe/v2/core/webapi"
"github.com/gofiber/fiber/v2"
)
func TagPage(c *fiber.Ctx) error {
queries := make(map[string]string, 3)
queries["Mode"] = c.Query("mode", "safe")
queries["Category"] = c.Query("category", "artworks")
queries["Order"] = c.Query("order", "date_d")
name := c.Params("name")
page := c.Query("page", "1")
pageInt, _ := strconv.Atoi(page)
tag, err := core.GetTagData(c, name)
if err != nil {
return err
}
result, err := core.GetSearch(c, queries["Category"], name, queries["Order"], queries["Mode"], page)
if err != nil {
return err
}
return c.Render("pages/tag", fiber.Map{"Title": "Results for " + tag.Name, "Tag": tag, "Data": result, "Queries": queries, "Page": pageInt})
}
-1
View File
@@ -1,6 +1,5 @@
#!/bin/sh
# Update the program every time you run?
# git pull