mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
clean up
This commit is contained in:
+7
-8
@@ -3,7 +3,6 @@ package core
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -103,13 +102,13 @@ type ArtworkBrief struct {
|
||||
}
|
||||
|
||||
type Illust struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description template.HTML `json:"description"`
|
||||
UserID string `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
UserAccount string `json:"userAccount"`
|
||||
Date time.Time `json:"uploadDate"`
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Description HTML `json:"description"`
|
||||
UserID string `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
UserAccount string `json:"userAccount"`
|
||||
Date time.Time `json:"uploadDate"`
|
||||
Images []Image
|
||||
Tags []Tag `json:"tags"`
|
||||
Pages int `json:"pageCount"`
|
||||
|
||||
@@ -40,9 +40,9 @@ func GetRankingCalendar(r *http.Request, mode string, year, month int) (template
|
||||
URL := GetRankingCalendarURL(mode, year, month)
|
||||
|
||||
req, err := http.NewRequestWithContext(r.Context(), "GET", URL, nil)
|
||||
if err != nil {
|
||||
return template.HTML(""), err
|
||||
}
|
||||
if err != nil {
|
||||
return template.HTML(""), err
|
||||
}
|
||||
req.Header.Add("User-Agent", "Mozilla/5.0")
|
||||
req.Header.Add("Cookie", "PHPSESSID="+token)
|
||||
// req.AddCookie(&http.Cookie{
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
html "html/template"
|
||||
)
|
||||
|
||||
type HTML = html.HTML
|
||||
+1
-2
@@ -3,7 +3,6 @@ package core
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
@@ -48,7 +47,7 @@ type User struct {
|
||||
Avatar string `json:"imageBig"`
|
||||
Following int `json:"following"`
|
||||
MyPixiv int `json:"mypixivCount"`
|
||||
Comment template.HTML `json:"commentHtml"`
|
||||
Comment HTML `json:"commentHtml"`
|
||||
Webpage string `json:"webpage"`
|
||||
SocialRaw json.RawMessage `json:"social"`
|
||||
Artworks []ArtworkBrief `json:"artworks"`
|
||||
|
||||
+3
-3
@@ -16,9 +16,9 @@ func pixivPostRequest(r *http.Request, url, payload, token, csrf string, isJSON
|
||||
requestBody := []byte(payload)
|
||||
|
||||
req, err := http.NewRequestWithContext(r.Context(), "POST", url, bytes.NewBuffer(requestBody))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Add("User-Agent", "Mozilla/5.0")
|
||||
req.Header.Add("Accept", "application/json")
|
||||
req.Header.Add("Cookie", "PHPSESSID="+token)
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
|
||||
func GetQueryParam(r *http.Request, name string, defaultValue ...string) string {
|
||||
if v := r.URL.Query().Get(name); v != "" {
|
||||
return v
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ func LoginUserPage(w http.ResponseWriter, r *http.Request) error {
|
||||
// The left part of the token is the member ID
|
||||
userId := strings.Split(token, "_")
|
||||
|
||||
http.Redirect(w, r, "/users/" + userId[0], http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/users/"+userId[0], http.StatusSeeOther)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func LoginBookmarkPage(w http.ResponseWriter, r *http.Request) error {
|
||||
// The left part of the token is the member ID
|
||||
userId := strings.Split(token, "_")
|
||||
|
||||
http.Redirect(w, r, "/users/" + userId[0] + "/bookmarks#checkpoint", http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/users/"+userId[0]+"/bookmarks#checkpoint", http.StatusSeeOther)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ func RankingCalendarPicker(w http.ResponseWriter, r *http.Request) error {
|
||||
}
|
||||
date := r.FormValue("date")
|
||||
|
||||
return utils.RedirectTo(w, r,"/rankingCalendar", map[string]string{
|
||||
"mode": mode,
|
||||
"date": date,
|
||||
return utils.RedirectTo(w, r, "/rankingCalendar", map[string]string{
|
||||
"mode": mode,
|
||||
"date": date,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ func TagPage(w http.ResponseWriter, r *http.Request) error {
|
||||
}
|
||||
|
||||
func AdvancedTagPost(w http.ResponseWriter, r *http.Request) error {
|
||||
return utils.RedirectTo(w, r,"/tags", map[string]string{
|
||||
return utils.RedirectTo(w, r, "/tags", map[string]string{
|
||||
"name": GetQueryParam(r, "name", r.FormValue("name")),
|
||||
"category": GetQueryParam(r, "category", "artworks"),
|
||||
"order": GetQueryParam(r, "order", "date_d"),
|
||||
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
html "html/template"
|
||||
"net/http"
|
||||
|
||||
"codeberg.org/vnpower/pixivfe/v2/core"
|
||||
@@ -102,7 +101,7 @@ type Data_rank struct {
|
||||
}
|
||||
type Data_rankingCalendar struct {
|
||||
Title string
|
||||
Render html.HTML
|
||||
Render core.HTML
|
||||
Mode string
|
||||
Year int
|
||||
MonthBefore DateWrap
|
||||
|
||||
@@ -2,7 +2,6 @@ package template
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
@@ -13,6 +12,8 @@ import (
|
||||
"codeberg.org/vnpower/pixivfe/v2/core"
|
||||
)
|
||||
|
||||
type HTML = core.HTML
|
||||
|
||||
func GetRandomColor() string {
|
||||
// Some color shade I stole
|
||||
colors := []string{
|
||||
@@ -42,7 +43,7 @@ func GetRandomColor() string {
|
||||
return colors[rand.Intn(len(colors))]
|
||||
}
|
||||
|
||||
func ParseEmojis(s string) template.HTML {
|
||||
func ParseEmojis(s string) HTML {
|
||||
emojiList := map[string]string{
|
||||
"normal": "101",
|
||||
"surprise": "102",
|
||||
@@ -92,10 +93,10 @@ func ParseEmojis(s string) template.HTML {
|
||||
|
||||
return fmt.Sprintf(`<img src="/proxy/s.pximg.net/common/images/emoji/%s.png" alt="(%s)" class="emoji" />`, id, s)
|
||||
})
|
||||
return template.HTML(parsedString)
|
||||
return HTML(parsedString)
|
||||
}
|
||||
|
||||
func ParsePixivRedirect(s string) template.HTML {
|
||||
func ParsePixivRedirect(s string) HTML {
|
||||
regex := regexp.MustCompile(`\/jump\.php\?(http[^"]+)`)
|
||||
|
||||
parsedString := regex.ReplaceAllStringFunc(s, func(s string) string {
|
||||
@@ -104,9 +105,9 @@ func ParsePixivRedirect(s string) template.HTML {
|
||||
})
|
||||
escaped, err := url.QueryUnescape(parsedString)
|
||||
if err != nil {
|
||||
return template.HTML(s)
|
||||
return HTML(s)
|
||||
}
|
||||
return template.HTML(escaped)
|
||||
return HTML(escaped)
|
||||
}
|
||||
|
||||
func EscapeString(s string) string {
|
||||
@@ -122,7 +123,7 @@ func ParseTimeCustomFormat(date time.Time, format string) string {
|
||||
return date.Format(format)
|
||||
}
|
||||
|
||||
func CreatePaginator(base, ending string, current_page, max_page int) template.HTML {
|
||||
func CreatePaginator(base, ending string, current_page, max_page int) HTML {
|
||||
pageUrl := func(page int) string {
|
||||
return fmt.Sprintf(`%s%d%s`, base, page, ending)
|
||||
}
|
||||
@@ -194,7 +195,7 @@ func CreatePaginator(base, ending string, current_page, max_page int) template.H
|
||||
}
|
||||
pages += `</div>`
|
||||
|
||||
return template.HTML(pages)
|
||||
return HTML(pages)
|
||||
}
|
||||
|
||||
func GetNovelGenre(s string) string {
|
||||
@@ -249,11 +250,11 @@ func SwitchButtonAttributes(baseURL, selection, currentSelection string) string
|
||||
|
||||
func GetTemplateFunctions() map[string]any {
|
||||
return map[string]any{
|
||||
"parseEmojis": func(s string) template.HTML {
|
||||
"parseEmojis": func(s string) HTML {
|
||||
return ParseEmojis(s)
|
||||
},
|
||||
|
||||
"parsePixivRedirect": func(s string) template.HTML {
|
||||
"parsePixivRedirect": func(s string) HTML {
|
||||
return ParsePixivRedirect(s)
|
||||
},
|
||||
"escapeString": func(s string) string {
|
||||
@@ -289,7 +290,7 @@ func GetTemplateFunctions() map[string]any {
|
||||
"parseTimeCustomFormat": func(date time.Time, format string) string {
|
||||
return ParseTimeCustomFormat(date, format)
|
||||
},
|
||||
"createPaginator": func(base, ending string, current_page, max_page int) template.HTML {
|
||||
"createPaginator": func(base, ending string, current_page, max_page int) HTML {
|
||||
return CreatePaginator(base, ending, current_page, max_page)
|
||||
},
|
||||
"joinArtworkIds": func(artworks []core.ArtworkBrief) string {
|
||||
@@ -303,10 +304,10 @@ func GetTemplateFunctions() map[string]any {
|
||||
// this is stupid
|
||||
return s[:len(s)-6]
|
||||
},
|
||||
"renderNovel": func(s string) template.HTML {
|
||||
"renderNovel": func(s string) HTML {
|
||||
s = strings.ReplaceAll(s, "\n", "<br />")
|
||||
s = strings.ReplaceAll(s, "[newpage]", "Insert page separator here.")
|
||||
return template.HTML(s)
|
||||
return HTML(s)
|
||||
},
|
||||
"novelGenre": GetNovelGenre,
|
||||
"floor": func(i float64) int {
|
||||
|
||||
+3
-3
@@ -1,16 +1,16 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
"github.com/goccy/go-json"
|
||||
)
|
||||
|
||||
func SendString(w http.ResponseWriter, text string) error {
|
||||
w.Header().Set("content-type", "text/plain")
|
||||
_, err := w.Write([]byte(text))
|
||||
_, err := w.Write([]byte(text))
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user