mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
Escape URL parameters in Sprintf
This commit is contained in:
+4
-4
@@ -14,7 +14,7 @@ func (p *PixivClient) GetArtworkImages(id string) ([]models.Image, error) {
|
||||
var resp []models.ImageResponse
|
||||
var images []models.Image
|
||||
|
||||
URL := fmt.Sprintf(ArtworkImagesURL, id)
|
||||
URL := UrlSprintf(ArtworkImagesURL, id)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
@@ -44,7 +44,7 @@ func (p *PixivClient) GetArtworkImages(id string) ([]models.Image, error) {
|
||||
func (p *PixivClient) GetArtworkByID(id string) (*models.Illust, error) {
|
||||
var images []models.Image
|
||||
|
||||
URL := fmt.Sprintf(ArtworkInformationURL, id)
|
||||
URL := UrlSprintf(ArtworkInformationURL, id)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
@@ -175,7 +175,7 @@ func (p *PixivClient) GetArtworkComments(id string) ([]models.Comment, error) {
|
||||
Comments []models.Comment `json:"comments"`
|
||||
}
|
||||
|
||||
URL := fmt.Sprintf(ArtworkCommentsURL, id)
|
||||
URL := UrlSprintf(ArtworkCommentsURL, id)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
@@ -195,7 +195,7 @@ func (p *PixivClient) GetRelatedArtworks(id string) ([]models.IllustShort, error
|
||||
Illusts []models.IllustShort `json:"illusts"`
|
||||
}
|
||||
|
||||
URL := fmt.Sprintf(ArtworkRelatedURL, id, 96)
|
||||
URL := UrlSprintf(ArtworkRelatedURL, id, 96)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
|
||||
+15
-4
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -37,7 +38,7 @@ func (p *PixivClient) GetNewestArtworks(worktype string, r18 string) ([]models.I
|
||||
lastID := "0"
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
URL := fmt.Sprintf(ArtworkNewestURL, worktype, r18, lastID)
|
||||
URL := UrlSprintf(ArtworkNewestURL, worktype, r18, lastID)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
@@ -69,7 +70,7 @@ func (p *PixivClient) GetRanking(mode string, content string, date string, page
|
||||
date = "&date=" + date
|
||||
}
|
||||
|
||||
url := fmt.Sprintf(ArtworkRankingURL, mode, content, date, page)
|
||||
url := UrlSprintf(ArtworkRankingURL, mode, content, date, page)
|
||||
|
||||
s, err := p.TextRequest(url)
|
||||
|
||||
@@ -88,7 +89,7 @@ func (p *PixivClient) GetRanking(mode string, content string, date string, page
|
||||
}
|
||||
|
||||
func (p *PixivClient) GetSearch(artworkType string, name string, order string, age_settings string, page string) (*models.SearchResult, error) {
|
||||
URL := fmt.Sprintf(SearchArtworksURL, artworkType, name, order, age_settings, page)
|
||||
URL := UrlSprintf(SearchArtworksURL, artworkType, name, order, age_settings, page)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
@@ -132,7 +133,7 @@ func (p *PixivClient) GetDiscoveryArtwork(mode string, count int) ([]models.Illu
|
||||
|
||||
count -= itemsForRequest
|
||||
|
||||
URL := fmt.Sprintf(ArtworkDiscoveryURL, mode, itemsForRequest)
|
||||
URL := UrlSprintf(ArtworkDiscoveryURL, mode, itemsForRequest)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
@@ -217,3 +218,13 @@ func (p *PixivClient) GetRankingLog(mode string, year, month int, image_proxy st
|
||||
}
|
||||
return template.HTML(renderString), nil
|
||||
}
|
||||
|
||||
func UrlSprintf(format string, a ...interface{}) string {
|
||||
for i, v := range a {
|
||||
s, ok := v.(string)
|
||||
if ok {
|
||||
a[i] = url.PathEscape(s)
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf(format, a...)
|
||||
}
|
||||
+1
-3
@@ -1,14 +1,12 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"codeberg.org/vnpower/pixivfe/models"
|
||||
"github.com/goccy/go-json"
|
||||
)
|
||||
|
||||
func (p *PixivClient) GetNewestFromFollowing(mode, page, token string) ([]models.IllustShort, error) {
|
||||
URL := fmt.Sprintf(NewestFromFollowURL, "illust", mode, page)
|
||||
URL := UrlSprintf(NewestFromFollowURL, "illust", mode, page)
|
||||
|
||||
var body struct {
|
||||
Thumbnails json.RawMessage `json:"thumbnails"`
|
||||
|
||||
+2
-4
@@ -1,8 +1,6 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"codeberg.org/vnpower/pixivfe/models"
|
||||
"github.com/goccy/go-json"
|
||||
)
|
||||
@@ -10,7 +8,7 @@ import (
|
||||
func (p *PixivClient) GetTagData(name string) (models.TagDetail, error) {
|
||||
var tag models.TagDetail
|
||||
|
||||
URL := fmt.Sprintf(SearchTagURL, name)
|
||||
URL := UrlSprintf(SearchTagURL, name)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
@@ -28,7 +26,7 @@ func (p *PixivClient) GetTagData(name string) (models.TagDetail, error) {
|
||||
func (p *PixivClient) GetFrequentTags(ids string) ([]models.FrequentTag, error) {
|
||||
var tags []models.FrequentTag
|
||||
|
||||
URL := fmt.Sprintf(FrequentTagsURL, ids)
|
||||
URL := UrlSprintf(FrequentTagsURL, ids)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ func ParsePixivRedirect(s string) template.HTML {
|
||||
}
|
||||
|
||||
func EscapeString(s string) string {
|
||||
escaped := url.QueryEscape(s)
|
||||
escaped := url.PathEscape(s)
|
||||
return escaped
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -1,15 +1,13 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"codeberg.org/vnpower/pixivfe/models"
|
||||
"github.com/goccy/go-json"
|
||||
)
|
||||
|
||||
func (p *PixivClient) GetLandingPage(mode string) (models.LandingArtworks, error) {
|
||||
var context models.LandingArtworks
|
||||
URL := fmt.Sprintf(LandingPageURL, mode)
|
||||
URL := UrlSprintf(LandingPageURL, mode)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
|
||||
+5
-5
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func (p *PixivClient) GetUserArtworksID(id string, category string, page int) (string, int, error) {
|
||||
URL := fmt.Sprintf(UserArtworksURL, id)
|
||||
URL := UrlSprintf(UserArtworksURL, id)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
@@ -80,7 +80,7 @@ func (p *PixivClient) GetUserArtworksID(id string, category string, page int) (s
|
||||
func (p *PixivClient) GetUserArtworks(id string, ids string) ([]models.IllustShort, error) {
|
||||
var works []models.IllustShort
|
||||
|
||||
URL := fmt.Sprintf(UserArtworksFullURL, id, ids)
|
||||
URL := UrlSprintf(UserArtworksFullURL, id, ids)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
@@ -113,7 +113,7 @@ func (p *PixivClient) GetUserArtworks(id string, ids string) ([]models.IllustSho
|
||||
func (p *PixivClient) GetUserBasicInformation(id string) (models.UserShort, error) {
|
||||
var user models.UserShort
|
||||
|
||||
URL := fmt.Sprintf(UserBasicInformationURL, id)
|
||||
URL := UrlSprintf(UserBasicInformationURL, id)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
@@ -131,7 +131,7 @@ func (p *PixivClient) GetUserBasicInformation(id string) (models.UserShort, erro
|
||||
func (p *PixivClient) GetUserInformation(id string, category string, page int) (*models.User, error) {
|
||||
var user *models.User
|
||||
|
||||
URL := fmt.Sprintf(UserInformationURL, id)
|
||||
URL := UrlSprintf(UserInformationURL, id)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
@@ -202,7 +202,7 @@ func (p *PixivClient) GetUserInformation(id string, category string, page int) (
|
||||
|
||||
func (p *PixivClient) GetUserBookmarks(id string, mode string, page int) ([]models.IllustShort, int, error) {
|
||||
page--
|
||||
URL := fmt.Sprintf(UserBookmarksURL, id, page*48, mode)
|
||||
URL := UrlSprintf(UserBookmarksURL, id, page*48, mode)
|
||||
|
||||
response, err := p.PixivRequest(URL)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user