mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
core/user naming + run gofumpt
This commit is contained in:
+1
-1
@@ -378,7 +378,7 @@ func GetArtworkByID(auditor *audit.Auditor, r *http.Request, id string, full boo
|
||||
for i := 0; i < count; i++ {
|
||||
idsString += fmt.Sprintf("&ids[]=%d", ids[i])
|
||||
}
|
||||
recent, err := fetchArtworkIDs(auditor, r, illust.UserID, idsString)
|
||||
recent, err := populateArtworkIDs(auditor, r, illust.UserID, idsString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ func addDaysOfMonth(calendar []DayCalendar, links []string, dayCount, numDays, y
|
||||
day.ArtworkLink = fmt.Sprintf("/artworks/%s", artworkID)
|
||||
}
|
||||
}
|
||||
day.DateString = fmt.Sprintf("%d%02d%02d", year, month, i + 1)
|
||||
day.DateString = fmt.Sprintf("%d%02d%02d", year, month, i+1)
|
||||
calendar = append(calendar, day)
|
||||
dayCount++
|
||||
}
|
||||
|
||||
+15
-13
@@ -199,7 +199,7 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
|
||||
switch cat.Value {
|
||||
case "illustrations", "manga":
|
||||
auditor.Logger.Debug("Fetching and populating ArtworkBriefs", zap.String("category", cat.Value))
|
||||
artworks, err := fetchPopulatedArtworkBriefs(auditor, r, id, cat.WorkIDs, fetchArtworkIDs)
|
||||
artworks, err := fetchPopulatedArtworkBriefs(auditor, r, id, cat.WorkIDs, populateArtworkIDs)
|
||||
if err != nil {
|
||||
auditor.SugaredLogger.Error("Failed to fetch populated ArtworkBriefs", zap.Error(err))
|
||||
return err
|
||||
@@ -208,7 +208,7 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
|
||||
|
||||
case "novels":
|
||||
auditor.Logger.Debug("Fetching and populating NovelBriefs", zap.String("category", cat.Value))
|
||||
novels, err := fetchPopulatedNovelBriefs(auditor, r, id, cat.WorkIDs, fetchNovelIDs)
|
||||
novels, err := fetchPopulatedNovelBriefs(auditor, r, id, cat.WorkIDs, populateNovelIDs)
|
||||
if err != nil {
|
||||
auditor.SugaredLogger.Error("Failed to fetch populated NovelBriefs", zap.Error(err))
|
||||
return err
|
||||
@@ -217,7 +217,7 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
|
||||
|
||||
case "bookmarks":
|
||||
auditor.Logger.Debug("Fetching and populating Bookmarks", zap.String("category", cat.Value))
|
||||
bookmarks, count, err := fetchBookmarks(auditor, r, id, "show", page)
|
||||
bookmarks, count, err := populateBookmarks(auditor, r, id, "show", page)
|
||||
if err != nil {
|
||||
auditor.SugaredLogger.Error("Failed to fetch bookmarks", zap.Error(err))
|
||||
return err
|
||||
@@ -494,8 +494,10 @@ func fetchFrequentTags(auditor *audit.Auditor, r *http.Request, ids string, work
|
||||
// Work is a generic type constraint.
|
||||
type Work interface{}
|
||||
|
||||
// fetchWorkIDs is a generic helper function to fetch work IDs.
|
||||
func fetchWorkIDs[T Work](auditor *audit.Auditor, r *http.Request, url string) ([]T, error) {
|
||||
// populateWorkIDs is a generic helper function to populate a []Work for a given set of work IDs.
|
||||
//
|
||||
// Each work ID should be in the format `&ids[]=123456`.
|
||||
func populateWorkIDs[T Work](auditor *audit.Auditor, r *http.Request, url string) ([]T, error) {
|
||||
resp, err := API_GET_UnwrapJson(r.Context(), auditor, url, "", r.Header)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -531,11 +533,11 @@ func fetchWorkIDs[T Work](auditor *audit.Auditor, r *http.Request, url string) (
|
||||
return works, nil
|
||||
}
|
||||
|
||||
// fetchArtworkIDs fetches the list of artwork IDs for a user (without other data).
|
||||
func fetchArtworkIDs(auditor *audit.Auditor, r *http.Request, id, ids string) ([]ArtworkBrief, error) {
|
||||
// populateArtworkIDs populates a []ArtworkBrief for a given set of artwork IDs.
|
||||
func populateArtworkIDs(auditor *audit.Auditor, r *http.Request, id, ids string) ([]ArtworkBrief, error) {
|
||||
URL := GetUserFullArtworkURL(id, ids)
|
||||
|
||||
works, err := fetchWorkIDs[ArtworkBrief](auditor, r, URL)
|
||||
works, err := populateWorkIDs[ArtworkBrief](auditor, r, URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -543,11 +545,11 @@ func fetchArtworkIDs(auditor *audit.Auditor, r *http.Request, id, ids string) ([
|
||||
return works, nil
|
||||
}
|
||||
|
||||
// fetchNovelIDs fetches the list of novel IDs for a user (without other data).
|
||||
func fetchNovelIDs(auditor *audit.Auditor, r *http.Request, id, ids string) ([]NovelBrief, error) {
|
||||
// populateNovelIDs populates a []NovelBrief for a given set of novel IDs.
|
||||
func populateNovelIDs(auditor *audit.Auditor, r *http.Request, id, ids string) ([]NovelBrief, error) {
|
||||
URL := GetUserFullNovelURL(id, ids)
|
||||
|
||||
works, err := fetchWorkIDs[NovelBrief](auditor, r, URL)
|
||||
works, err := populateWorkIDs[NovelBrief](auditor, r, URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -555,11 +557,11 @@ func fetchNovelIDs(auditor *audit.Auditor, r *http.Request, id, ids string) ([]N
|
||||
return works, nil
|
||||
}
|
||||
|
||||
// fetchBookmarks fetches the list of bookmarks for a user (with other data).
|
||||
// populateBookmarks populates a []ArtworkBrief for a given set of bookmarked work IDs.
|
||||
//
|
||||
// This function cannot be neatly refactored to use getWorkIDs due to having
|
||||
// a different API response structure.
|
||||
func fetchBookmarks(auditor *audit.Auditor, r *http.Request, id, mode string, page int) ([]ArtworkBrief, int, error) {
|
||||
func populateBookmarks(auditor *audit.Auditor, r *http.Request, id, mode string, page int) ([]ArtworkBrief, int, error) {
|
||||
page--
|
||||
|
||||
URL := GetUserBookmarksURL(id, mode, page)
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
func PixivisionHomePage(w http.ResponseWriter, r *http.Request) error {
|
||||
page := GetQueryParam(r, "p", "1")
|
||||
data, err := core.PixivisionGetHomepage(r, page, "en")
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -85,8 +84,8 @@ func PixivisionCategoryPage(w http.ResponseWriter, r *http.Request) error {
|
||||
|
||||
return RenderHTML(w, r, Data_pixivisionCategory{
|
||||
Category: data,
|
||||
Page: pageint,
|
||||
ID: id,
|
||||
Page: pageint,
|
||||
ID: id,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -113,8 +112,8 @@ func PixivisionTagPage(w http.ResponseWriter, r *http.Request) error {
|
||||
}
|
||||
|
||||
return RenderHTML(w, r, Data_pixivisionTag{
|
||||
Tag: data,
|
||||
Tag: data,
|
||||
Page: pageint,
|
||||
ID: id,
|
||||
ID: id,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -111,14 +111,14 @@ type Data_pixivisionArticle struct {
|
||||
|
||||
type Data_pixivisionCategory struct {
|
||||
Category core.PixivisionCategory
|
||||
Page int
|
||||
ID string
|
||||
Page int
|
||||
ID string
|
||||
}
|
||||
|
||||
type Data_pixivisionTag struct {
|
||||
Tag core.PixivisionTag
|
||||
Tag core.PixivisionTag
|
||||
Page int
|
||||
ID string
|
||||
ID string
|
||||
}
|
||||
|
||||
type Data_rank struct {
|
||||
|
||||
Reference in New Issue
Block a user