rename constants in core/user

This commit is contained in:
perennial
2024-10-19 20:18:22 +11:00
parent 4fb1e53278
commit ea14f339a6
3 changed files with 35 additions and 35 deletions
+30 -30
View File
@@ -13,25 +13,25 @@ import (
)
// pixivfe internal data type. not used by pixiv.
type UserArtCategory string
type UserWorkCategory string
const (
UserArt_Any UserArtCategory = ""
UserArt_AnyAlt UserArtCategory = "artworks"
UserArt_Illustration UserArtCategory = "illustrations"
UserArt_Manga UserArtCategory = "manga"
UserArt_Bookmarks UserArtCategory = "bookmarks" // what this user has bookmarked; not art by this user
UserArt_Novel UserArtCategory = "novels"
CategoryAny UserWorkCategory = ""
CategoryAnyAlt UserWorkCategory = "artworks"
CategoryIllustration UserWorkCategory = "illustrations"
CategoryManga UserWorkCategory = "manga"
CategoryBookmarks UserWorkCategory = "bookmarks" // what this user has bookmarked; not art by this user
CategoryNovels UserWorkCategory = "novels"
)
func (s UserArtCategory) Validate() error {
if s != UserArt_Any &&
s != UserArt_AnyAlt &&
s != UserArt_Illustration &&
s != UserArt_Manga &&
s != UserArt_Bookmarks &&
s != UserArt_Novel {
return i18n.Errorf(`Invalid work category: %#v. Only "%s", "%s", "%s", "%s", "%s" and "%s" are available`, s, UserArt_Any, UserArt_AnyAlt, UserArt_Illustration, UserArt_Manga, UserArt_Bookmarks, UserArt_Novel)
func (s UserWorkCategory) Validate() error {
if s != CategoryAny &&
s != CategoryAnyAlt &&
s != CategoryIllustration &&
s != CategoryManga &&
s != CategoryBookmarks &&
s != CategoryNovels {
return i18n.Errorf(`Invalid work category: %#v. Only "%s", "%s", "%s", "%s", "%s" and "%s" are available`, s, CategoryAny, CategoryAnyAlt, CategoryIllustration, CategoryManga, CategoryBookmarks, CategoryNovels)
} else {
return nil
}
@@ -115,7 +115,7 @@ func (m *IntStringMap) UnmarshalJSON(data []byte) error {
}
// GetUserArtworksIDAndSeries retrieves artwork IDs and series information for a user.
func GetUserArtworksIDAndSeries(r *http.Request, id string, category UserArtCategory, page int) (idsString string, count int, illustCount int, mangaCount int, novelCount int, series json.RawMessage, err error) {
func GetUserArtworksIDAndSeries(r *http.Request, id string, category UserWorkCategory, page int) (idsString string, count int, illustCount int, mangaCount int, novelCount int, series json.RawMessage, err error) {
URL := GetUserArtworksURL(id)
resp, err := API_GET_UnwrapJson(r.Context(), URL, "", r.Header)
@@ -146,7 +146,7 @@ func GetUserArtworksIDAndSeries(r *http.Request, id string, category UserArtCate
var manga IntStringMap
var novels IntStringMap
if category == UserArt_Illustration || category == UserArt_Any || category == UserArt_AnyAlt {
if category == CategoryIllustration || category == CategoryAny || category == CategoryAnyAlt {
if body.Illusts != nil && len(*body.Illusts) > 0 {
if err = json.Unmarshal(*body.Illusts, &illusts); err != nil {
fmt.Printf("Error unmarshalling illusts: %v\n", err)
@@ -160,7 +160,7 @@ func GetUserArtworksIDAndSeries(r *http.Request, id string, category UserArtCate
}
}
if category == UserArt_Manga || category == UserArt_Any {
if category == CategoryManga || category == CategoryAny {
if body.Manga != nil && len(*body.Manga) > 0 {
if err = json.Unmarshal(*body.Manga, &manga); err != nil {
fmt.Printf("Error unmarshalling manga: %v\n", err)
@@ -177,7 +177,7 @@ func GetUserArtworksIDAndSeries(r *http.Request, id string, category UserArtCate
}
}
if category == UserArt_Novel {
if category == CategoryNovels {
if body.Novels != nil && len(*body.Novels) > 0 {
if err = json.Unmarshal(*body.Novels, &novels); err != nil {
fmt.Printf("Error unmarshalling novels: %v\n", err)
@@ -211,12 +211,12 @@ func GetUserArtworksIDAndSeries(r *http.Request, id string, category UserArtCate
return idsString, count, illustCount, mangaCount, novelCount, series, nil
}
func fetchAndProcessArtworks(r *http.Request, id, ids string, category UserArtCategory) ([]ArtworkBrief, []NovelBrief, error) {
func fetchAndProcessArtworks(r *http.Request, id, ids string, category UserWorkCategory) ([]ArtworkBrief, []NovelBrief, error) {
var artworks []ArtworkBrief
var novels []NovelBrief
var err error
if category == UserArt_Novel {
if category == CategoryNovels {
novels, err = GetUserNovelIDs(r, id, ids)
} else {
artworks, err = GetUserArtworkIDs(r, id, ids)
@@ -227,7 +227,7 @@ func fetchAndProcessArtworks(r *http.Request, id, ids string, category UserArtCa
}
// Sort the works
if category == UserArt_Novel {
if category == CategoryNovels {
sort.Slice(novels[:], func(i, j int) bool {
return numberGreaterThan(novels[i].ID, novels[j].ID)
})
@@ -240,12 +240,12 @@ func fetchAndProcessArtworks(r *http.Request, id, ids string, category UserArtCa
return artworks, novels, nil
}
func handleSeriesData(series json.RawMessage, category UserArtCategory) ([]NovelSeries, []MangaSeries) {
func handleSeriesData(series json.RawMessage, category UserWorkCategory) ([]NovelSeries, []MangaSeries) {
var novelSeries []NovelSeries
var mangaSeries []MangaSeries
if series != nil {
if category == UserArt_Novel {
if category == CategoryNovels {
_ = json.Unmarshal(series, &novelSeries)
} else {
_ = json.Unmarshal(series, &mangaSeries)
@@ -255,7 +255,7 @@ func handleSeriesData(series json.RawMessage, category UserArtCategory) ([]Novel
return novelSeries, mangaSeries
}
func GetUserProfile(r *http.Request, id string, category UserArtCategory, page int, getTags bool) (User, error) {
func GetUserProfile(r *http.Request, id string, category UserWorkCategory, page int, getTags bool) (User, error) {
var user User
token := session.GetUserToken(r)
@@ -275,7 +275,7 @@ func GetUserProfile(r *http.Request, id string, category UserArtCategory, page i
}
// Get counts for illustrations and manga
_, allCount, illustCount, mangaCount, _, _, err := GetUserArtworksIDAndSeries(r, id, UserArt_Any, 1)
_, allCount, illustCount, mangaCount, _, _, err := GetUserArtworksIDAndSeries(r, id, CategoryAny, 1)
if err != nil {
return user, err
}
@@ -284,7 +284,7 @@ func GetUserProfile(r *http.Request, id string, category UserArtCategory, page i
user.CountInfo.Manga = mangaCount
// Get count for novels separately
_, _, _, _, novelCount, _, err := GetUserArtworksIDAndSeries(r, id, UserArt_Novel, 1)
_, _, _, _, novelCount, _, err := GetUserArtworksIDAndSeries(r, id, CategoryNovels, 1)
if err != nil {
return user, err
}
@@ -297,7 +297,7 @@ func GetUserProfile(r *http.Request, id string, category UserArtCategory, page i
}
user.CountInfo.Bookmarks = bookmarksCount
if category == UserArt_Bookmarks {
if category == CategoryBookmarks {
// Bookmarks
works, _, err := GetUserBookmarks(r, id, "show", page)
if err != nil {
@@ -318,7 +318,7 @@ func GetUserProfile(r *http.Request, id string, category UserArtCategory, page i
return user, err
}
if category == UserArt_Novel {
if category == CategoryNovels {
user.Novels = novels
} else {
user.Artworks = artworks
@@ -395,7 +395,7 @@ func GetUserWorks[T Work](r *http.Request, url string) ([]T, error) {
}
// GetUserFrequentTags retrieves frequent tags for a user based on category.
func GetUserFrequentTags(r *http.Request, ids string, category UserArtCategory) ([]FrequentTag, error) {
func GetUserFrequentTags(r *http.Request, ids string, category UserWorkCategory) ([]FrequentTag, error) {
var tags []FrequentTag
var URL string
+2 -2
View File
@@ -155,7 +155,7 @@ type Data_tag struct {
type Data_user struct {
Title string
User core.User
Category core.UserArtCategory
Category core.UserWorkCategory
PageLimit int
Page int
MetaImage string
@@ -164,7 +164,7 @@ type Data_userAtom struct {
URL string
Title string
User core.User
Category core.UserArtCategory
Category core.UserWorkCategory
Updated string
PageLimit int
Page int
+3 -3
View File
@@ -11,7 +11,7 @@ import (
type userPageData struct {
user core.User
category core.UserArtCategory
category core.UserWorkCategory
pageLimit int
page int
}
@@ -21,7 +21,7 @@ func fetchData(r *http.Request, getTags bool) (userPageData, error) {
if _, err := strconv.Atoi(id); err != nil {
return userPageData{}, err
}
category := core.UserArtCategory(GetPathVar(r, "category", string(core.UserArt_Any)))
category := core.UserWorkCategory(GetPathVar(r, "category", string(core.CategoryAny)))
err := category.Validate()
if err != nil {
return userPageData{}, err
@@ -41,7 +41,7 @@ func fetchData(r *http.Request, getTags bool) (userPageData, error) {
var worksCount int
var worksPerPage float64
if category == core.UserArt_Bookmarks {
if category == core.CategoryBookmarks {
worksPerPage = 48.0
} else {
worksPerPage = 30.0