diff --git a/assets/views/tag.jet.html b/assets/views/tag.jet.html
index 92e8157..75c6eaf 100644
--- a/assets/views/tag.jet.html
+++ b/assets/views/tag.jet.html
@@ -53,7 +53,10 @@
{{- range .Data.RelatedTags }}
{{- end }}
diff --git a/core/artwork.go b/core/artwork.go
index dd48085..65e47b4 100644
--- a/core/artwork.go
+++ b/core/artwork.go
@@ -86,7 +86,7 @@ type Image struct {
IllustType int
}
-type Tag struct {
+type ArtworkTag struct {
Name string `json:"tag"`
TranslatedName string `json:"translation"`
}
@@ -129,18 +129,18 @@ type Illust struct {
UserAccount string `json:"userAccount"`
Date time.Time `json:"uploadDate"`
Images []Image
- Tags []Tag `json:"tags"`
- Pages int `json:"pageCount"`
- Bookmarks int `json:"bookmarkCount"`
- Likes int `json:"likeCount"`
- Comments int `json:"commentCount"`
- Views int `json:"viewCount"`
- CommentDisabled int `json:"commentOff"`
- SanityLevel int `json:"sl"`
- XRestrict XRestrict `json:"xRestrict"`
- AiType AiType `json:"aiType"`
- BookmarkData any `json:"bookmarkData"`
- Liked bool `json:"likeData"`
+ Tags []ArtworkTag `json:"tags"`
+ Pages int `json:"pageCount"`
+ Bookmarks int `json:"bookmarkCount"`
+ Likes int `json:"likeCount"`
+ Comments int `json:"commentCount"`
+ Views int `json:"viewCount"`
+ CommentDisabled int `json:"commentOff"`
+ SanityLevel int `json:"sl"`
+ XRestrict XRestrict `json:"xRestrict"`
+ AiType AiType `json:"aiType"`
+ BookmarkData any `json:"bookmarkData"`
+ Liked bool `json:"likeData"`
SeriesNavData struct {
SeriesType string `json:"seriesType"`
SeriesID string `json:"seriesId"`
@@ -389,9 +389,9 @@ func GetArtworkByID(auditor *audit.Auditor, r *http.Request, id string, full boo
}
// Store translated tags and preserve the original language form for international users.
- var tagsList []Tag
+ var tagsList []ArtworkTag
for _, tag := range tags.Tags {
- var newTag Tag
+ var newTag ArtworkTag
newTag.Name = tag.Tag
newTag.TranslatedName = tag.Translation["en"]
diff --git a/core/tag.go b/core/tag.go
index 42b1a69..26cd1dc 100644
--- a/core/tag.go
+++ b/core/tag.go
@@ -25,18 +25,19 @@ type SearchArtworks struct {
Total int `json:"total"`
}
+// TODO: find a better name for this struct
+type TagTag struct {
+ Name string `json:"tag"`
+ TranslatedName string `json:"translation"`
+}
+
type SearchResult struct {
Artworks SearchArtworks
Popular struct {
Permanent []ArtworkBrief `json:"permanent"`
Recent []ArtworkBrief `json:"recent"`
} `json:"popular"`
- RelatedTags []string `json:"relatedTags"`
-}
-
-type TagWithTranslation struct {
- Name string `json:"relatedTags"`
- TranslatedName string `json:"tagTranslation"`
+ RelatedTags []TagTag `json:"relatedTags"`
}
type SearchPageSettings struct {
@@ -106,31 +107,53 @@ func GetSearch(auditor *audit.Auditor, r *http.Request, settings SearchPageSetti
}
response = session.ProxyImageUrl(r, response)
- // IDK how to do better than this lol
+ // Replace "illust", "manga", and "illustManga" with "works" in the JSON response
+ //
+ // VnPower: IDK how to do better than this lol
temp := strings.ReplaceAll(string(response), `"illust"`, `"works"`)
temp = strings.ReplaceAll(temp, `"manga"`, `"works"`)
temp = strings.ReplaceAll(temp, `"illustManga"`, `"works"`)
+ // Define an intermediate struct to unmarshal the JSON response
var resultRaw struct {
- *SearchResult
ArtworksRaw json.RawMessage `json:"works"`
+ Popular struct {
+ Permanent []ArtworkBrief `json:"permanent"`
+ Recent []ArtworkBrief `json:"recent"`
+ } `json:"popular"`
+ RelatedTags []string `json:"relatedTags"`
+ TagTranslation map[string]struct{ En string } `json:"tagTranslation"`
}
- var artworks SearchArtworks
- var result *SearchResult
+ var artworks SearchArtworks
+ var result SearchResult
+
+ // Unmarshal the modified JSON response into the intermediate struct
err = json.Unmarshal([]byte(temp), &resultRaw)
if err != nil {
return nil, err
}
- result = resultRaw.SearchResult
-
+ // Unmarshal the artworks data
err = json.Unmarshal([]byte(resultRaw.ArtworksRaw), &artworks)
if err != nil {
return nil, err
}
+ // Assign artworks and popular data to the result
result.Artworks = artworks
+ result.Popular = resultRaw.Popular
- return result, nil
+ // Process related tags and translations to populate the RelatedTags slice
+ for _, tagName := range resultRaw.RelatedTags {
+ tag := TagTag{
+ Name: tagName,
+ }
+ if translation, exists := resultRaw.TagTranslation[tagName]; exists {
+ tag.TranslatedName = translation.En
+ }
+ result.RelatedTags = append(result.RelatedTags, tag)
+ }
+
+ return &result, nil
}
diff --git a/i18n/locale/en/template.json b/i18n/locale/en/template.json
index 0b7db6e..aa355dd 100644
--- a/i18n/locale/en/template.json
+++ b/i18n/locale/en/template.json
@@ -519,6 +519,7 @@
"assets/views/tag.jet.html:tLDBgUWw9-g": "Safe",
"assets/views/tag.jet.html:vQknITzlB0I": "Search options",
"assets/views/tag.jet.html:vUR6oAGwbwE": "Order",
+ "assets/views/tag.jet.html:xd9cjh9m0Go": "({{ .TranslatedName }})",
"assets/views/tag.jet.html:yHft19aQloM": "Minimum image width",
"assets/views/tag.jet.html:yxDtQeZtxgU": "Portrait",
"assets/views/unauthorized.jet.html:Q84lx6mjuV0": "Unauthorized",