core/user renaming

This commit is contained in:
perennial
2024-10-22 02:28:04 +11:00
parent c67e4df682
commit fde27bf5a9
3 changed files with 27 additions and 26 deletions
+2
View File
@@ -132,6 +132,7 @@
<h2 class="d-flex align-items-baseline mb-0">Works<span class="fs-6 bg-charcoal-surface1 rounded px-2 py-1 ms-2">{{ .User.WorkCounts.All }}</span></h2>
</div>
{*
<!-- Manga series -->
<h2 class="d-flex align-items-baseline">Manga series<span class="fs-6 bg-charcoal-surface1 rounded px-2 py-1 ms-2">{{ len(.User.MangaSeries) }}</span></h2>
<div class="row row-cols-2 row-cols-md-4 row-cols-lg-6 g-4">
@@ -139,6 +140,7 @@
{{- include "fragments/mangaseries-tn" . }}
{{- end }}
</div>
*}
<!-- Illustrations -->
{{ if len(.User.Illustrations) != 0 }}
+25 -25
View File
@@ -106,11 +106,11 @@ type User struct {
}
// GetUserProfile retrieves the user profile, including counts, artworks/bookmarks, and social data.
func GetUserProfile(auditor *audit.Auditor, r *http.Request, id string, category *UserWorkCategory, page int, getTags bool) (User, error) {
func GetUserProfile(auditor *audit.Auditor, r *http.Request, id string, currentCategory *UserWorkCategory, page int, getTags bool) (User, error) {
var user User
auditor.Logger.Debug("GetUserProfile called",
zap.String("userID", id),
zap.String("category", category.Value),
zap.String("currentCategory", currentCategory.Value),
zap.Int("page", page),
zap.Bool("getTags", getTags),
)
@@ -139,9 +139,9 @@ func GetUserProfile(auditor *audit.Auditor, r *http.Request, id string, category
}
auditor.Logger.Debug("User information unmarshalled", zap.String("userName", user.Name))
// Get populated works or bookmarks based on the category
// Get populated works or bookmarks based on the currentCategory
auditor.Logger.Debug("Getting populated works")
if err := getPopulatedWorks(auditor, r, &user, id, category, page, getTags); err != nil {
if err := getPopulatedWorks(auditor, r, &user, id, currentCategory, page, getTags); err != nil {
auditor.SugaredLogger.Error("Failed to get populated works", zap.Error(err))
return user, err
}
@@ -169,18 +169,18 @@ func GetUserProfile(auditor *audit.Auditor, r *http.Request, id string, category
return user, nil
}
// getPopulatedWorks fetches then populates information for a user's works or bookmarks, based on the category.
// getPopulatedWorks fetches then populates information for a user's works or bookmarks, based on the currentCategory.
//
// It also handles a user's frequently used tags and series data.
func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id string, category *UserWorkCategory, page int, getTags bool) error {
func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id string, currentCategory *UserWorkCategory, page int, getTags bool) error {
auditor.Logger.Debug("getPopulatedWorks called",
zap.String("userID", id),
zap.String("category", category.Value),
zap.String("currentCategory", currentCategory.Value),
zap.Int("page", page),
zap.Bool("getTags", getTags),
)
if category.Value == CategoryBookmarks.Value {
if currentCategory.Value == CategoryBookmarks.Value {
auditor.Logger.Debug("Category is Bookmarks, fetching bookmarks")
// Fetch bookmarks
works, count, err := fetchBookmarks(auditor, r, id, "show", page)
@@ -200,7 +200,7 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
// Calculate PageLimit for bookmarks
worksPerPage := 48.0
pageLimit := int(math.Ceil(float64(count) / worksPerPage))
category.SetPageLimit(pageLimit)
currentCategory.SetPageLimit(pageLimit)
auditor.Logger.Debug("PageLimit set for bookmarks", zap.Int("pageLimit", pageLimit))
return nil
@@ -208,7 +208,7 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
// Fetch work IDs and series data
auditor.Logger.Debug("Fetching work IDs and series data for works")
userWorkIDs, countInfo, mangaSeriesData, novelSeriesData, err := fetchWorkIDsAndSeriesData(auditor, r, id, category, page)
userWorkIDs, countInfo, mangaSeriesData, novelSeriesData, err := fetchWorkIDsAndSeriesData(auditor, r, id, currentCategory, page)
if err != nil {
auditor.SugaredLogger.Error("Failed to fetch work IDs and series data", zap.Error(err))
return err
@@ -221,7 +221,7 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
// Initialize ID strings for different work types
var illustrationIDs, mangaIDs, novelIDs string
switch category.Value {
switch currentCategory.Value {
case CategoryIllustration.Value:
illustrationIDs = userWorkIDs.IllustrationIDs
auditor.Logger.Debug("Category is Illustration", zap.String("illustrationIDs", illustrationIDs))
@@ -242,8 +242,8 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
zap.String("novelIDs", novelIDs),
)
default:
auditor.SugaredLogger.Warn("Unsupported category", zap.String("category", category.Value))
return fmt.Errorf("unsupported category: %v", category.Value)
auditor.SugaredLogger.Warn("Unsupported category", zap.String("category", currentCategory.Value))
return fmt.Errorf("unsupported category: %v", currentCategory.Value)
}
// Early return if there are no works to fetch
@@ -299,7 +299,7 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
// Fetch a user's frequently used tags if requested
if getTags {
auditor.Logger.Debug("Fetching frequent tags")
user.FrequentTags, err = populateFrequentTags(auditor, r, id, category, illustrationIDs, mangaIDs, novelIDs)
user.FrequentTags, err = populateFrequentTags(auditor, r, id, currentCategory, illustrationIDs, mangaIDs, novelIDs)
if err != nil {
auditor.SugaredLogger.Error("Failed to populate frequent tags", zap.Error(err))
return err
@@ -330,7 +330,7 @@ func populateFrequentTags(
auditor *audit.Auditor,
r *http.Request,
id string,
category *UserWorkCategory,
currentCategory *UserWorkCategory,
illustrationIDs string,
mangaIDs string,
novelIDs string,
@@ -416,7 +416,7 @@ func populateFrequentTags(
if len(finalTagsIDs) != 0 {
// Concatenate IDs to form a single string
ids := strings.Join(finalTagsIDs, "")
frequentTags, err := fetchFrequentTags(auditor, r, ids, category)
frequentTags, err := fetchFrequentTags(auditor, r, ids, currentCategory)
if err != nil {
return nil, fmt.Errorf("failed to get user frequent tags: %w", err)
}
@@ -425,7 +425,7 @@ func populateFrequentTags(
auditor.Logger.Warn(
"No tags found to fetch, setting FrequentTags to empty slice",
zap.String("category", category.Value),
zap.String("currentCategory", currentCategory.Value),
zap.Strings("primaryTagsIDs", primaryTagsIDs),
zap.Strings("secondaryTagsIDs", secondaryTagsIDs),
zap.String("illustrationIDs", illustrationIDs),
@@ -541,10 +541,10 @@ func extractIDs(rawMessage *json.RawMessage, categoryName string) ([]int, int, e
// fetchWorkIDsAndSeriesData retrieves artwork IDs and series information for a user.
//
// It returns separate ID strings for illustrations, manga, and novels encapsulated in UserWorkIDs.
func fetchWorkIDsAndSeriesData(auditor *audit.Auditor, r *http.Request, id string, category *UserWorkCategory, page int) (userWorkIDs UserWorkIDs, workCounts WorkCounts, mangaSeriesData, novelSeriesData json.RawMessage, err error) {
func fetchWorkIDsAndSeriesData(auditor *audit.Auditor, r *http.Request, id string, currentCategory *UserWorkCategory, page int) (userWorkIDs UserWorkIDs, workCounts WorkCounts, mangaSeriesData, novelSeriesData json.RawMessage, err error) {
auditor.Logger.Debug("fetchWorkIDsAndSeriesData called",
zap.String("userID", id),
zap.String("category", category.Value),
zap.String("currentCategory", currentCategory.Value),
zap.Int("page", page),
)
@@ -702,13 +702,13 @@ func fetchWorkIDsAndSeriesData(auditor *audit.Auditor, r *http.Request, id strin
}
// Set PageLimit on the correct category
if subCategory.Value == category.Value {
category.SetPageLimit(pageLimit)
if subCategory.Value == currentCategory.Value {
currentCategory.SetPageLimit(pageLimit)
auditor.Logger.Debug("PageLimit set for category",
zap.String("category", category.Value),
zap.String("category", currentCategory.Value),
zap.Int("pageLimit", pageLimit),
)
} else if category.Value == "" || category.Value == "artworks" {
} else if currentCategory.Value == "" || currentCategory.Value == "artworks" {
// For "any" or "artworks", accumulate total items and compute PageLimit later
totalItemsForCategory += totalItems
}
@@ -783,12 +783,12 @@ func handleSeriesData(auditor *audit.Auditor, mangaSeriesData, novelSeriesData j
}
// fetchFrequentTags fetches a user's frequently used tags, based on category.
func fetchFrequentTags(auditor *audit.Auditor, r *http.Request, ids string, category *UserWorkCategory) ([]FrequentTag, error) {
func fetchFrequentTags(auditor *audit.Auditor, r *http.Request, ids string, currentCategory *UserWorkCategory) ([]FrequentTag, error) {
var tags []FrequentTag
var URL string
// TODO: If overall, request both?
if category != &CategoryNovels {
if currentCategory != &CategoryNovels {
URL = GetUserFrequentArtworkTagsURL(ids)
} else {
URL = GetUserFrequentNovelTagsURL(ids)
-1
View File
@@ -543,7 +543,6 @@
"assets/views/unauthorized.jet.html:SNRVjaimXDQ": "You need to <a href=\"/settings#login\">log in</a> to use this feature.",
"assets/views/user.jet.html:3_oq3Nw2b2U": "View on pixiv.net",
"assets/views/user.jet.html:5xhgcv5yNyM": "Frequently used tags",
"assets/views/user.jet.html:818-yx2fz-M": "Manga series",
"assets/views/user.jet.html:9EbrMpLP6_U": "Bookmarks",
"assets/views/user.jet.html:Awt3bDxDL0U": "View more",
"assets/views/user.jet.html:P6fO_UTqr7E": "Manga",