diff --git a/core/user.go b/core/user.go index 3affe94..9a7671c 100644 --- a/core/user.go +++ b/core/user.go @@ -458,18 +458,22 @@ func fetchWorkIDsAndSeriesData(r *http.Request, id string, category UserWorkCate // Build the UserWorkIDs by computing slice bounds and constructing ID strings idCategories := []struct { + name string ids *[]int idStringField *string }{ { + name: "illusts", ids: &illustIDs, idStringField: &userWorkIDs.IllustrationIDs, }, { + name: "manga", ids: &mangaIDs, idStringField: &userWorkIDs.MangaIDs, }, { + name: "novels", ids: &novelIDs, idStringField: &userWorkIDs.NovelIDs, }, @@ -477,9 +481,12 @@ func fetchWorkIDsAndSeriesData(r *http.Request, id string, category UserWorkCate for _, cat := range idCategories { totalItems := len(*cat.ids) - start, end, err := computeSliceBounds(page, worksPerPage, totalItems) + start, end, err := computeSliceBounds(page, worksPerPage, totalItems, cat.name) if err != nil { - return UserWorkIDs{}, WorkCounts{}, nil, err + fmt.Printf("Error computing slice bounds for category '%s': %v\n", cat.name, err) + // Set idStringField to an empty string so that it's caught by getPopulatedWorks correctly + *(cat.idStringField) = "" + continue } idsToUse := (*cat.ids)[start:end] var idsBuilder strings.Builder @@ -660,19 +667,28 @@ func (s *User) parseSocial() error { } // computeSliceBounds is a utility function to compute slice bounds safely -func computeSliceBounds(page int, worksPerPage float64, totalItems int) (start, end int, err error) { +func computeSliceBounds(page int, worksPerPage float64, totalItems int, categoryName string) (start, end int, err error) { + // fmt.Printf("[DEBUG] Entering computeSliceBounds - page: %d, worksPerPage: %.2f, totalItems: %d, category: %s\n", page, worksPerPage, totalItems, categoryName) + if totalItems == 0 { + // fmt.Printf("[DEBUG] totalItems is 0 for category '%s', returning 0, 0, nil\n", categoryName) return 0, 0, nil } maxPages := int(math.Ceil(float64(totalItems) / worksPerPage)) + // fmt.Printf("[DEBUG] Calculated maxPages: %d for category '%s'\n", maxPages, categoryName) + if page < 1 || page > maxPages { - return 0, 0, i18n.Error("Invalid page number.") + // fmt.Printf("[DEBUG] Invalid page number for category '%s'. page: %d, maxPages: %d\n", categoryName, page, maxPages) + return 0, 0, fmt.Errorf("Invalid page number for category '%s'", categoryName) } start = (page - 1) * int(worksPerPage) end = min(start+int(worksPerPage), totalItems) + // fmt.Printf("[DEBUG] Calculated start: %d, end: %d for category '%s'\n", start, end, categoryName) + + // fmt.Printf("[DEBUG] Exiting computeSliceBounds successfully for category '%s'\n", categoryName) return start, end, nil } diff --git a/i18n/locale/en/code.json b/i18n/locale/en/code.json index 187a189..f4c2634 100644 --- a/i18n/locale/en/code.json +++ b/i18n/locale/en/code.json @@ -28,7 +28,6 @@ "core/requests.go:lLy9SHFUtQQ": "failed to copy response body: %w", "core/requests.go:o8eDPgojH4w": "Incompatible response body", "core/requests.go:y3v5nQwdU0s": "All tokens (%d) are timed out, resetting all tokens to their initial good state.\nConsider providing additional tokens in PIXIVFE_TOKEN or reviewing API request level backoff configuration.\nPlease refer the following documentation for additional information:\n- https://pixivfe-docs.pages.dev/hosting/obtaining-pixivfe-token/\n- https://pixivfe-docs.pages.dev/hosting/environment-variables/#exponential-backoff-configuration", - "core/user.go:1itpJBE-3VI": "Invalid page number.", "core/user.go:T3RwaHcnsYQ": "Invalid work category: %#v. Only \"%s\", \"%s\", \"%s\", \"%s\", \"%s\" and \"%s\" are available", "server/audit/audit_init.go:RVQo5OR9IKs": "failed to initialize zap logger: %w", "server/audit/audit_init.go:k5XgFtfJlBA": "failed to create response save directory: %w",