mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
more core/user refactor
This commit is contained in:
+21
-21
@@ -177,25 +177,6 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
|
||||
zap.Bool("getTags", getTags),
|
||||
)
|
||||
|
||||
auditor.Logger.Debug("Fetching bookmarks")
|
||||
// Fetch bookmarks
|
||||
works, count, err := fetchBookmarks(auditor, r, id, "show", page)
|
||||
if err != nil {
|
||||
auditor.SugaredLogger.Error("Failed to fetch bookmarks", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
user.Categories["bookmarks"].IllustWorks = works
|
||||
user.Categories["bookmarks"].WorkCount = count
|
||||
|
||||
auditor.Logger.Debug("Bookmarks fetched", zap.Int("count", count), zap.Int("worksCount", len(works)))
|
||||
|
||||
// Calculate PageLimit for bookmarks
|
||||
worksPerPage := 48.0
|
||||
pageLimit := int(math.Ceil(float64(count) / worksPerPage))
|
||||
user.Categories["bookmarks"].SetPageLimit(pageLimit)
|
||||
auditor.Logger.Debug("PageLimit set for bookmarks", zap.Int("pageLimit", pageLimit))
|
||||
|
||||
// Fetch work IDs and series data
|
||||
auditor.Logger.Debug("Fetching work IDs and series data for works")
|
||||
categoriesData, err := fetchWorkIDsAndSeriesData(auditor, r, id, currentCategory, page)
|
||||
@@ -212,7 +193,7 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
|
||||
|
||||
// Fetch and populate works for each category
|
||||
for _, cat := range user.Categories {
|
||||
if cat.WorkIDs == "" {
|
||||
if cat.WorkIDs == "" && cat.Value != "bookmarks" {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -234,6 +215,18 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
|
||||
return err
|
||||
}
|
||||
cat.NovelWorks = novels
|
||||
|
||||
case "bookmarks":
|
||||
auditor.Logger.Debug("Fetching and populating Bookmarks", zap.String("category", cat.Value))
|
||||
bookmarks, count, err := fetchBookmarks(auditor, r, id, "show", page)
|
||||
if err != nil {
|
||||
auditor.SugaredLogger.Error("Failed to fetch bookmarks", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
cat.IllustWorks = bookmarks
|
||||
cat.WorkCount = count
|
||||
worksPerPage := 48.0
|
||||
cat.PageLimit = int(math.Ceil(float64(count) / worksPerPage))
|
||||
}
|
||||
|
||||
// Handle series data
|
||||
@@ -245,7 +238,7 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
|
||||
}
|
||||
|
||||
// Fetch frequent tags if requested
|
||||
if getTags {
|
||||
if getTags && cat.Value != "bookmarks" {
|
||||
auditor.Logger.Debug("Fetching frequent tags for category", zap.String("category", cat.Value))
|
||||
tags, err := fetchFrequentTags(auditor, r, cat.WorkIDs, cat)
|
||||
if err != nil {
|
||||
@@ -357,6 +350,13 @@ func fetchWorkIDsAndSeriesData(auditor *audit.Auditor, r *http.Request, id strin
|
||||
}
|
||||
categories["novels"] = novelCat
|
||||
|
||||
// Create an empty bookmarks category
|
||||
//
|
||||
// We don't build an ID string here as fetchBookmarks populates IllustWorks without the need for a WorkIDs string
|
||||
// (which is also why we can't call fetchFrequentTags for the "bookmarks" category, though extracting the IDs from
|
||||
// ArtworkBrief would be possible)
|
||||
categories["bookmarks"] = &UserWorkCategory{Value: "bookmarks"}
|
||||
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user