diff --git a/core/config/session.go b/core/config/session.go index 6e3ebe9..58d5163 100644 --- a/core/config/session.go +++ b/core/config/session.go @@ -34,6 +34,14 @@ func ProxyImageUrl(c *fiber.Ctx, s string) string { return s } +func ProxyImageUrlNoEscape(c *fiber.Ctx, s string) string { + proxy := GetImageProxy(c) + s = strings.ReplaceAll(s, `https://i.pximg.net`, "https://"+proxy) + // s = strings.ReplaceAll(s, `https:\/\/i.pximg.net`, "/proxy/i.pximg.net") + s = strings.ReplaceAll(s, `https://s.pximg.net`, "/proxy/s.pximg.net") + return s +} + func GetImageProxy(c *fiber.Ctx) string { sess, err := Store.Get(c) if err != nil { diff --git a/core/webapi/artwork.go b/core/webapi/artwork.go index 74c8e67..6e94549 100644 --- a/core/webapi/artwork.go +++ b/core/webapi/artwork.go @@ -56,14 +56,18 @@ var aiTypeModel = map[aiType]string{ } type ImageResponse struct { - Urls map[string]string `json:"urls"` + Width int `json:"width"` + Height int `json:"height"` + Urls map[string]string `json:"urls"` } type Image struct { - Small string `json:"thumb_mini"` - Medium string `json:"small"` - Large string `json:"regular"` - Original string `json:"original"` + Width int + Height int + Small string + Medium string + Large string + Original string } type Tag struct { @@ -86,6 +90,20 @@ type UserBrief struct { Avatar string `json:"imageBig"` } +type ArtworkBrief struct { + ID string `json:"id"` + Title string `json:"title"` + ArtistID string `json:"userId"` + ArtistName string `json:"userName"` + ArtistAvatar string `json:"profileImageUrl"` + Thumbnail string `json:"url"` + Pages int `json:"pageCount"` + XRestrict int `json:"xRestrict"` + AiType int `json:"aiType"` + Bookmarked any `json:"bookmarkData"` + IllustType int `json:"illustType"` +} + type Illust struct { ID string `json:"id"` Title string `json:"title"` @@ -94,19 +112,19 @@ type Illust struct { UserName string `json:"userName"` UserAccount string `json:"userAccount"` Date time.Time `json:"uploadDate"` - Images []Image `json:"images"` - Tags []Tag `json:"tags"` - Pages int `json:"pageCount"` - Bookmarks int `json:"bookmarkCount"` - Likes int `json:"likeCount"` - Comments int `json:"commentCount"` - Views int `json:"viewCount"` - CommentDisabled int `json:"commentOff"` - SanityLevel int `json:"sl"` - XRestrict xRestrict `json:"xRestrict"` - AiType aiType `json:"aiType"` - Bookmarked any `json:"bookmarkData"` - Liked any `json:"json:"likeData"` + Images []Image + Tags []Tag `json:"tags"` + Pages int `json:"pageCount"` + Bookmarks int `json:"bookmarkCount"` + Likes int `json:"likeCount"` + Comments int `json:"commentCount"` + Views int `json:"viewCount"` + CommentDisabled int `json:"commentOff"` + SanityLevel int `json:"sl"` + XRestrict xRestrict `json:"xRestrict"` + AiType aiType `json:"aiType"` + Bookmarked any `json:"bookmarkData"` + Liked any `json:"likeData"` User UserBrief RecentWorks []ArtworkBrief RelatedWorks []ArtworkBrief @@ -154,6 +172,12 @@ func GetArtworkImages(c *fiber.Ctx, id string) ([]Image, error) { for _, imageRaw := range resp { var image Image + // this is the original art dimention, not the "regular" art dimension + // the image ratio of "regular" is close to Width/Height + // maybe not useful + image.Width = imageRaw.Width + image.Height = imageRaw.Height + image.Small = imageRaw.Urls["thumb_mini"] image.Medium = imageRaw.Urls["small"] image.Large = imageRaw.Urls["regular"] @@ -220,6 +244,7 @@ func GetArtworkByID(c *fiber.Ctx, id string, full bool) (*Illust, error) { var illust struct { *Illust + // recent illustrations by same user Recent map[int]any `json:"userIllusts"` RawTags json.RawMessage `json:"tags"` } diff --git a/core/webapi/newest.go b/core/webapi/newest.go index fd4639f..8af17a8 100644 --- a/core/webapi/newest.go +++ b/core/webapi/newest.go @@ -7,19 +7,6 @@ import ( "github.com/gofiber/fiber/v2" ) -type ArtworkBrief struct { - ID string `json:"id"` - Title string `json:"title"` - ArtistID string `json:"userId"` - ArtistName string `json:"userName"` - ArtistAvatar string `json:"profileImageUrl"` - Thumbnail string `json:"url"` - Pages int `json:"pageCount"` - XRestrict int `json:"xRestrict"` - AiType int `json:"aiType"` - Bookmarked any `json:"bookmarkData"` -} - func GetNewestArtworks(c *fiber.Ctx, worktype string, r18 string) ([]ArtworkBrief, error) { token := session.GetToken(c) URL := http.GetNewestArtworksURL(worktype, r18, "0") diff --git a/core/webapi/ranking.go b/core/webapi/ranking.go index 2c19186..e89df98 100644 --- a/core/webapi/ranking.go +++ b/core/webapi/ranking.go @@ -20,6 +20,7 @@ type Ranking struct { ID int `json:"illust_id"` ArtistID int `json:"user_id"` Rank int `json:"rank"` + IllustType string `json:"illust_type"` } `json:"contents"` Mode string `json:"mode"` diff --git a/core/webapi/rankingCalendar.go b/core/webapi/rankingCalendar.go index 672c46c..4b369d3 100644 --- a/core/webapi/rankingCalendar.go +++ b/core/webapi/rankingCalendar.go @@ -64,7 +64,7 @@ func GetRankingCalendar(c *fiber.Ctx, mode string, year, month int) (template.HT for _, a := range n.Attr { if a.Key == "data-src" { // adds a new link entry when the attribute matches - links = append(links, session.ProxyImageUrl(c, a.Val)) + links = append(links, session.ProxyImageUrlNoEscape(c, a.Val)) } } } diff --git a/pages/artwork-multi.go b/pages/artwork-multi.go index 51bf2c9..e1f4dea 100644 --- a/pages/artwork-multi.go +++ b/pages/artwork-multi.go @@ -2,6 +2,7 @@ package pages import ( "errors" + "fmt" "strconv" "strings" "sync" @@ -14,7 +15,7 @@ func ArtworkMultiPage(c *fiber.Ctx) error { param_ids := c.Params("ids") ids := strings.Split(param_ids, ",") - artworks := make([]ArtWorkData, len(ids)) + artworks := make([]*core.Illust, len(ids)) wg := sync.WaitGroup{} wg.Add(len(ids)) @@ -28,8 +29,8 @@ func ArtworkMultiPage(c *fiber.Ctx) error { illust, err := core.GetArtworkByID(c, id, false) if err != nil { - artworks[i] = ArtWorkData{ - Title: err.Error(), + artworks[i] = &core.Illust{ + Title: err.Error(), // this might be flaky } return } @@ -39,18 +40,13 @@ func ArtworkMultiPage(c *fiber.Ctx) error { metaDescription += "#" + i.Name + ", " } - artworks[i] = ArtWorkData{ - Illust: illust, - Title: illust.Title, - PageType: "artwork", - MetaDescription: metaDescription, - MetaImage: illust.Images[0].Original, - } + artworks[i] = illust }(i, id) } wg.Wait() return c.Render("pages/artwork-multi", fiber.Map{ "Artworks": artworks, + "Title": fmt.Sprintf("(%d images)", len(artworks)), }) } diff --git a/pages/artwork.go b/pages/artwork.go index 495c538..679fc9d 100644 --- a/pages/artwork.go +++ b/pages/artwork.go @@ -8,14 +8,6 @@ import ( "github.com/gofiber/fiber/v2" ) -type ArtWorkData struct { - Illust *core.Illust - Title string - PageType string - MetaDescription string - MetaImage string -} - func ArtworkPage(c *fiber.Ctx) error { param_id := c.Params("id") if _, err := strconv.Atoi(param_id); err != nil { diff --git a/views/assets/tumblr.svg b/views/assets/tumblr.svg new file mode 100644 index 0000000..6b4e836 --- /dev/null +++ b/views/assets/tumblr.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/views/layout.jet.html b/views/layout.jet.html index 694c40c..58cb3ce 100644 --- a/views/layout.jet.html +++ b/views/layout.jet.html @@ -30,7 +30,7 @@ {{ end }} -
+