run gofumpt

https://github.com/mvdan/gofumpt
This commit is contained in:
perennial
2024-10-13 16:27:35 +11:00
parent c93b8e8ae9
commit d41e98ab8b
30 changed files with 81 additions and 70 deletions
+10 -8
View File
@@ -17,12 +17,14 @@ import (
"codeberg.org/vnpower/pixivfe/v2/server/utils"
)
const USER_AGENT = "PixivAndroidApp/5.0.234 (Android 11; Pixel 5)"
const REDIRECT_URI = "https://app-api.pixiv.net/web/v1/users/auth/pixiv/callback"
const LOGIN_URL = "https://app-api.pixiv.net/web/v1/login"
const AUTH_TOKEN_URL = "https://oauth.secure.pixiv.net/auth/token"
const CLIENT_ID = "MOBrBDS8blbauoSck0ZfDbtuzpyT"
const CLIENT_SECRET = "lsACyCD94FhDUtGTXi3QzcFE2uU1hqtDaKeqrdwj"
const (
USER_AGENT = "PixivAndroidApp/5.0.234 (Android 11; Pixel 5)"
REDIRECT_URI = "https://app-api.pixiv.net/web/v1/users/auth/pixiv/callback"
LOGIN_URL = "https://app-api.pixiv.net/web/v1/login"
AUTH_TOKEN_URL = "https://oauth.secure.pixiv.net/auth/token"
CLIENT_ID = "MOBrBDS8blbauoSck0ZfDbtuzpyT"
CLIENT_SECRET = "lsACyCD94FhDUtGTXi3QzcFE2uU1hqtDaKeqrdwj"
)
type AppAPICredentials struct {
AccessToken string `json:"access_token"`
@@ -75,7 +77,7 @@ func oauth_pkce() (string, string) {
func AppAPIRefresh(r *http.Request, refresh_token string) AppAPICredentials {
var credentials AppAPICredentials
var body = []byte(fmt.Sprintf(`client_id=%s&client_secret=%s&grant_type=refresh_token&include_policy=true&refresh_token=%s`, CLIENT_ID, CLIENT_SECRET, refresh_token))
body := []byte(fmt.Sprintf(`client_id=%s&client_secret=%s&grant_type=refresh_token&include_policy=true&refresh_token=%s`, CLIENT_ID, CLIENT_SECRET, refresh_token))
req, err := http.NewRequestWithContext(r.Context(), "POST", AUTH_TOKEN_URL, bytes.NewBuffer(body))
if err != nil {
panic(err)
@@ -110,7 +112,7 @@ func AppAPILogin(r *http.Request) AppAPICredentials {
// Change this.
fmt.Scanln(&s)
var body = []byte(fmt.Sprintf(`client_id=%s&client_secret=%s&code=%s&code_verifier=%s&grant_type=authorization_code&include_policy=true&redirect_uri=%s`, CLIENT_ID, CLIENT_SECRET, s, code_verifier, REDIRECT_URI))
body := []byte(fmt.Sprintf(`client_id=%s&client_secret=%s&code=%s&code_verifier=%s&grant_type=authorization_code&include_policy=true&redirect_uri=%s`, CLIENT_ID, CLIENT_SECRET, s, code_verifier, REDIRECT_URI))
req, err := http.NewRequestWithContext(r.Context(), "POST", AUTH_TOKEN_URL, bytes.NewBuffer(body))
if err != nil {
panic(err)
-3
View File
@@ -59,7 +59,6 @@ func GetLanding(r *http.Request, mode string, isLoggedIn bool) (*LandingArtworks
var landing LandingArtworks
resp, err := API_GET_UnwrapJson(r.Context(), URL, "")
if err != nil {
return &landing, err
}
@@ -80,7 +79,6 @@ func GetLanding(r *http.Request, mode string, isLoggedIn bool) (*LandingArtworks
stuff.ForEach(func(key, value gjson.Result) bool {
var artwork ArtworkBrief
err = json.Unmarshal([]byte(value.String()), &artwork)
if err != nil {
return false
}
@@ -94,7 +92,6 @@ func GetLanding(r *http.Request, mode string, isLoggedIn bool) (*LandingArtworks
pagesStr := gjson.Get(resp, "page").String()
err = json.Unmarshal([]byte(pagesStr), &pages)
if err != nil {
return &landing, err
}
+1 -2
View File
@@ -1,11 +1,10 @@
package core
import (
"net/http"
"strconv"
"time"
"net/http"
"codeberg.org/vnpower/pixivfe/v2/server/session"
"github.com/goccy/go-json"
)
+2 -1
View File
@@ -1,9 +1,10 @@
package core
import (
"net/http"
"codeberg.org/vnpower/pixivfe/v2/server/session"
"github.com/goccy/go-json"
"net/http"
)
func GetNewestArtworks(r *http.Request, worktype string, r18 string) ([]ArtworkBrief, error) {
+8 -7
View File
@@ -2,12 +2,11 @@ package core
import (
"fmt"
"net/http"
"regexp"
"strings"
"time"
"net/http"
"codeberg.org/vnpower/pixivfe/v2/server/session"
"github.com/goccy/go-json"
)
@@ -126,11 +125,13 @@ type NovelBrief struct {
}
// Novel embedded illusts
var re_r = regexp.MustCompile(`\[pixivimage:\d+(-\d+)?\]`)
var re_d = regexp.MustCompile(`\d+(-\d+)?`)
var re_t = regexp.MustCompile(`\"original\":\"(.+?)\"`)
var re_u = regexp.MustCompile(`\[uploadedimage:(\d+)\]`)
var re_id = regexp.MustCompile(`\d+`)
var (
re_r = regexp.MustCompile(`\[pixivimage:\d+(-\d+)?\]`)
re_d = regexp.MustCompile(`\d+(-\d+)?`)
re_t = regexp.MustCompile(`\"original\":\"(.+?)\"`)
re_u = regexp.MustCompile(`\[uploadedimage:(\d+)\]`)
re_id = regexp.MustCompile(`\d+`)
)
func GetNovelByID(r *http.Request, id string) (Novel, error) {
var novel Novel
+1 -1
View File
@@ -1,11 +1,11 @@
package core
import (
"net/http"
"time"
"codeberg.org/vnpower/pixivfe/v2/server/session"
"github.com/goccy/go-json"
"net/http"
)
type NovelSeries struct {
+2 -1
View File
@@ -1,10 +1,11 @@
package core
import (
"net/http"
"codeberg.org/vnpower/pixivfe/v2/server/session"
"github.com/goccy/go-json"
"net/http"
)
func GetNewestFromFollowing(r *http.Request, mode, page string) ([]ArtworkBrief, error) {
+6 -5
View File
@@ -2,7 +2,6 @@ package core
import (
"fmt"
"github.com/PuerkitoBio/goquery"
"html"
"io"
"net/http"
@@ -11,6 +10,8 @@ import (
"strings"
"time"
"github.com/PuerkitoBio/goquery"
"codeberg.org/vnpower/pixivfe/v2/i18n"
)
@@ -216,8 +217,8 @@ func PixivisionGetTag(r *http.Request, id string, page string, lang ...string) (
doc.Find("._article-card").Each(func(i int, s *goquery.Selection) {
var article PixivisionArticle
//article.ID = s.Find(".arc__title a").AttrOr("data-gtm-label", "")
//article.Title = s.Find(".arc__title a").Text()
// article.ID = s.Find(".arc__title a").AttrOr("data-gtm-label", "")
// article.Title = s.Find(".arc__title a").Text()
article.ID = s.Find(`a[data-gtm-action="ClickTitle"]`).AttrOr("data-gtm-label", "")
article.Title = s.Find(`a[data-gtm-action="ClickTitle"]`).Text()
@@ -330,8 +331,8 @@ func PixivisionGetCategory(r *http.Request, id string, page string, lang ...stri
doc.Find("._article-card").Each(func(i int, s *goquery.Selection) {
var article PixivisionArticle
//article.ID = s.Find(".arc__title a").AttrOr("data-gtm-label", "")
//article.Title = s.Find(".arc__title a").Text()
// article.ID = s.Find(".arc__title a").AttrOr("data-gtm-label", "")
// article.Title = s.Find(".arc__title a").Text()
article.ID = s.Find(`a[data-gtm-action="ClickTitle"]`).AttrOr("data-gtm-label", "")
article.Title = s.Find(`a[data-gtm-action="ClickTitle"]`).Text()
+1 -1
View File
@@ -1,6 +1,7 @@
package core
import (
"net/http"
"strings"
"time"
@@ -8,7 +9,6 @@ import (
"codeberg.org/vnpower/pixivfe/v2/server/session"
"github.com/goccy/go-json"
"net/http"
)
/*
+1 -1
View File
@@ -1,11 +1,11 @@
package core
import (
"net/http"
"strings"
"codeberg.org/vnpower/pixivfe/v2/server/session"
"github.com/goccy/go-json"
"net/http"
)
type TagDetail struct {
+1 -4
View File
@@ -3,9 +3,8 @@ package core
import (
"fmt"
"math"
"sort"
"net/http"
"sort"
"codeberg.org/vnpower/pixivfe/v2/i18n"
"codeberg.org/vnpower/pixivfe/v2/server/session"
@@ -153,7 +152,6 @@ func GetUserArtworkList(r *http.Request, id, ids string) ([]ArtworkBrief, error)
for _, v := range body.Illusts {
var illust ArtworkBrief
err = json.Unmarshal(v, &illust)
if err != nil {
return nil, err
}
@@ -194,7 +192,6 @@ func GetUserNovels(r *http.Request, id, ids string) ([]NovelBrief, error) {
for _, v := range body.Novels {
var novel NovelBrief
err = json.Unmarshal(v, &novel)
if err != nil {
return nil, err
}
+4 -2
View File
@@ -35,8 +35,10 @@ func main() {
encoder.Encode(result)
}
var re_command_fullmatch = regexp.MustCompile(`\A([\s\n# =]*\{\{[^\{\}]*\}\})*[\s\n]*\z`)
var re_comment = regexp.MustCompile(`\{\*[\s\S]*?\*\}`)
var (
re_command_fullmatch = regexp.MustCompile(`\A([\s\n# =]*\{\{[^\{\}]*\}\})*[\s\n]*\z`)
re_comment = regexp.MustCompile(`\{\*[\s\S]*?\*\}`)
)
func stripComments(s string) string {
return re_comment.ReplaceAllString(s, "")
+1
View File
@@ -46,6 +46,7 @@ func loadLocale(fs_i18n fs.FS, locale string) (map[string]string, error) {
maps.Copy(m0, m1)
return m0, nil
}
func loadLocale_helper(fs_i18n fs.FS, locale string, filename string) (map[string]string, error) {
file, err := fs_i18n.Open(path.Join(locale, filename))
if err != nil {
+5 -3
View File
@@ -9,9 +9,11 @@ import (
"go.uber.org/zap/zapcore"
)
var optionSaveResponse bool
var MaxRecordedCount = 0
var logger *zap.Logger
var (
optionSaveResponse bool
MaxRecordedCount = 0
logger *zap.Logger
)
// Init initializes the audit package and sets up response saving if enabled.
// saveResponse is passed as a boolean from main.go.
+12 -1
View File
@@ -1,9 +1,10 @@
package audit
import (
"codeberg.org/vnpower/pixivfe/v2/i18n"
"net/http"
"time"
"codeberg.org/vnpower/pixivfe/v2/i18n"
)
type Span interface {
@@ -34,21 +35,26 @@ type ServerRequestSpan struct {
func (span ServerRequestSpan) GetStartTime() time.Time {
return span.StartTime
}
func (span ServerRequestSpan) GetEndTime() time.Time {
return span.EndTime
}
func (span ServerRequestSpan) GetRequestId() string {
return span.RequestId
}
func (span ServerRequestSpan) Component() string {
return "server"
}
func (span ServerRequestSpan) Action() map[string]interface{} {
return map[string]interface{}{
"method": span.Method,
"path": span.Path,
}
}
func (span ServerRequestSpan) Outcome() map[string]interface{} {
outcome := map[string]interface{}{
"status": span.Status,
@@ -77,15 +83,19 @@ type APIRequestSpan struct {
func (span APIRequestSpan) GetStartTime() time.Time {
return span.StartTime
}
func (span APIRequestSpan) GetEndTime() time.Time {
return span.EndTime
}
func (span APIRequestSpan) GetRequestId() string {
return span.RequestId
}
func (span APIRequestSpan) Component() string {
return "API"
}
func (span APIRequestSpan) Action() map[string]interface{} {
return map[string]interface{}{
"method": span.Method,
@@ -93,6 +103,7 @@ func (span APIRequestSpan) Action() map[string]interface{} {
"response_file": span.ResponseFilename,
}
}
func (span APIRequestSpan) Outcome() map[string]interface{} {
outcome := map[string]interface{}{
"status": "success",
-1
View File
@@ -51,7 +51,6 @@ func HandleError(h http.Handler) http.Handler {
// Check if an error was caught during the request processing
err := request_context.Get(r).CaughtError
if err != nil {
// If an error was caught, render the error page
routes.ErrorPage(w, r, err, http.StatusInternalServerError)
+2 -1
View File
@@ -1,8 +1,9 @@
package routes
import (
"codeberg.org/vnpower/pixivfe/v2/config"
"net/http"
"codeberg.org/vnpower/pixivfe/v2/config"
)
func AboutPage(w http.ResponseWriter, r *http.Request) error {
+1 -2
View File
@@ -3,9 +3,8 @@ package routes
import (
"fmt"
"math"
"strconv"
"net/http"
"strconv"
"codeberg.org/vnpower/pixivfe/v2/core"
"codeberg.org/vnpower/pixivfe/v2/i18n"
+2 -1
View File
@@ -1,8 +1,9 @@
package routes
import (
"codeberg.org/vnpower/pixivfe/v2/core"
"net/http"
"codeberg.org/vnpower/pixivfe/v2/core"
)
func NewestPage(w http.ResponseWriter, r *http.Request) error {
+1 -2
View File
@@ -3,9 +3,8 @@ package routes
import (
"fmt"
"math"
"strconv"
"net/http"
"strconv"
"codeberg.org/vnpower/pixivfe/v2/core"
"codeberg.org/vnpower/pixivfe/v2/i18n"
+2 -2
View File
@@ -1,10 +1,10 @@
package routes
import (
"net/http"
"codeberg.org/vnpower/pixivfe/v2/core"
"codeberg.org/vnpower/pixivfe/v2/server/session"
"net/http"
)
func PixivisionHomePage(w http.ResponseWriter, r *http.Request) error {
-2
View File
@@ -15,7 +15,6 @@ func SPximgProxy(w http.ResponseWriter, r *http.Request) error {
}
core.ProxyRequest(w, req)
return nil
}
func IPximgProxy(w http.ResponseWriter, r *http.Request) error {
@@ -27,7 +26,6 @@ func IPximgProxy(w http.ResponseWriter, r *http.Request) error {
req.Header.Add("Referer", "https://www.pixiv.net/")
core.ProxyRequest(w, req)
return nil
}
func UgoiraProxy(w http.ResponseWriter, r *http.Request) error {
+1 -1
View File
@@ -1,10 +1,10 @@
package routes
import (
"net/http"
"strconv"
"codeberg.org/vnpower/pixivfe/v2/core"
"net/http"
)
func RankingPage(w http.ResponseWriter, r *http.Request) error {
+1 -2
View File
@@ -2,11 +2,10 @@ package routes
import (
"fmt"
"net/http"
"strconv"
"time"
"net/http"
"codeberg.org/vnpower/pixivfe/v2/core"
"codeberg.org/vnpower/pixivfe/v2/server/utils"
)
+5 -3
View File
@@ -2,11 +2,11 @@ package routes
import (
"net/http"
"time"
"codeberg.org/vnpower/pixivfe/v2/core"
"codeberg.org/vnpower/pixivfe/v2/server/request_context"
"codeberg.org/vnpower/pixivfe/v2/server/template"
"time"
)
func RenderHTML[T any](w http.ResponseWriter, r *http.Request, data T) error {
@@ -48,7 +48,6 @@ type Data_artworkMulti struct {
Artworks []core.Illust
Title string
}
type Data_diagnostics struct{}
type Data_discovery struct {
Artworks []core.ArtworkBrief
Title string
@@ -153,7 +152,6 @@ type Data_tag struct {
ActiveRatio string
ActiveSearchMode string
}
type Data_unauthorized struct{}
type Data_user struct {
Title string
User core.User
@@ -179,3 +177,7 @@ type Data_mangaSeries struct {
Page int
PageLimit int
}
type (
Data_diagnostics struct{}
Data_unauthorized struct{}
)
+1 -1
View File
@@ -2,11 +2,11 @@ package routes
import (
"math"
"net/http"
"strconv"
"time"
"codeberg.org/vnpower/pixivfe/v2/core"
"net/http"
)
type userPageData struct {
+1 -2
View File
@@ -3,9 +3,8 @@
package session
import (
"time"
"net/http"
"time"
)
type CookieName string
+1 -1
View File
@@ -34,7 +34,7 @@ func (l *LocalizedFSLoader) Open(templatePath string) (io.ReadCloser, error) {
i18n_path := path.Join(l.Dir, templatePath)
templatePath = filepath.Join(l.Dir, filepath.FromSlash(templatePath))
//println("load replacer:", i18n_path)
// println("load replacer:", i18n_path)
replacer := i18n.Replacer(locale, i18n_path)
if replacer == nil {
-1
View File
@@ -83,7 +83,6 @@ func testWith[T any](t *testing.T, data T) {
}
err := template.Render(io.Discard, variables, data)
if err != nil {
template_name, _ := strings.CutPrefix(reflect.TypeFor[T]().Name(), "Data_")
t.Errorf("while rendering template %s: %v", template_name, err)
+8 -8
View File
@@ -317,11 +317,13 @@ func SwitchButtonAttributes(baseURL, selection, currentSelection string) string
return fmt.Sprintf(`href=%s%s class=switch-button selected=%s`, baseURL, selection, cur)
}
var furiganaPattern = regexp.MustCompile(`\[\[rb:\s*(.+?)\s*>\s*(.+?)\s*\]\]`)
var chapterPattern = regexp.MustCompile(`\[chapter:\s*(.+?)\s*\]`)
var jumpUriPattern = regexp.MustCompile(`\[\[jumpuri:\s*(.+?)\s*>\s*(.+?)\s*\]\]`)
var jumpPagePattern = regexp.MustCompile(`\[jump:\s*(\d+?)\s*\]`)
var newPagePattern = regexp.MustCompile(`\s*\[newpage\]\s*`)
var (
furiganaPattern = regexp.MustCompile(`\[\[rb:\s*(.+?)\s*>\s*(.+?)\s*\]\]`)
chapterPattern = regexp.MustCompile(`\[chapter:\s*(.+?)\s*\]`)
jumpUriPattern = regexp.MustCompile(`\[\[jumpuri:\s*(.+?)\s*>\s*(.+?)\s*\]\]`)
jumpPagePattern = regexp.MustCompile(`\[jump:\s*(\d+?)\s*\]`)
newPagePattern = regexp.MustCompile(`\s*\[newpage\]\s*`)
)
// GetTemplateFunctions returns a map of custom template functions for use in HTML templates
func GetTemplateFunctions() map[string]any {
@@ -347,9 +349,7 @@ func GetTemplateFunctions() map[string]any {
"isEmphasize": func(s string) bool {
switch s {
case
"R-18",
"R-18G":
case "R-18", "R-18G":
return true
}
return false