models.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. package models
  2. import (
  3. "html/template"
  4. "time"
  5. "encoding/json"
  6. )
  7. type PaginationData struct {
  8. PreviousPage int
  9. CurrentPage int
  10. NextPage int
  11. }
  12. type PixivResponse struct {
  13. Error bool
  14. Message string
  15. Body json.RawMessage
  16. }
  17. type RankingResponse struct {
  18. Artworks []RankedArtwork `json:"contents"`
  19. Mode string `json:"mode"`
  20. Content string `json:"content"`
  21. CurrentDate string `json:"date"`
  22. PrevDateRaw json.RawMessage `json:"prev_date"`
  23. NextDateRaw json.RawMessage `json:"next_date"`
  24. PrevDate string
  25. NextDate string
  26. }
  27. func (s *RankingResponse) ProxyImages(proxy string) {
  28. s.Artworks = ProxyRankedArtworkSlice(s.Artworks, proxy)
  29. }
  30. type ImageResponse struct {
  31. Urls map[string]string `json:"urls"`
  32. }
  33. type TagResponse struct {
  34. AuthorID string `json:"authorId"`
  35. RawTags json.RawMessage `json:"tags"`
  36. }
  37. // Pixiv returns 0, 1, 2 to filter SFW and/or NSFW artworks.
  38. // Those values are saved in `xRestrict`
  39. // 0: Safe
  40. // 1: R18
  41. // 2: R18G
  42. type xRestrict int
  43. const (
  44. Safe xRestrict = 0
  45. R18 xRestrict = 1
  46. R18G xRestrict = 2
  47. )
  48. var xRestrictModel = map[xRestrict]string{
  49. Safe: "",
  50. R18: "R18",
  51. R18G: "R18G",
  52. }
  53. // Pixiv returns 0, 1, 2 to filter SFW and/or NSFW artworks.
  54. // Those values are saved in `aiType`
  55. // 0: Not rated / Unknown
  56. // 1: Not AI-generated
  57. // 2: AI-generated
  58. type aiType int
  59. const (
  60. Unrated aiType = 0
  61. NotAI aiType = 1
  62. AI aiType = 2
  63. )
  64. var aiTypeModel = map[aiType]string{
  65. Unrated: "Unrated",
  66. NotAI: "Not AI",
  67. AI: "AI",
  68. }
  69. // Pixiv gives us 5 types of an image. I don't need the mini one tho.
  70. // PS: Where tf is my 360x360 image, Pixiv?
  71. type Image struct {
  72. Small string `json:"thumb_mini"`
  73. Medium string `json:"small"`
  74. Large string `json:"regular"`
  75. Original string `json:"original"`
  76. }
  77. type Tag struct {
  78. Name string `json:"tag"`
  79. TranslatedName string `json:"translation"`
  80. }
  81. type FrequentTag struct {
  82. Name string `json:"tag"`
  83. TranslatedName string `json:"tag_translation"`
  84. }
  85. type Illust struct {
  86. ID string `json:"id"`
  87. Title string `json:"title"`
  88. Description template.HTML `json:"description"`
  89. UserID string `json:"userId"`
  90. UserName string `json:"userName"`
  91. UserAccount string `json:"userAccount"`
  92. Date time.Time `json:"uploadDate"`
  93. Images []Image `json:"images"`
  94. Tags []Tag `json:"tags"`
  95. Pages int `json:"pageCount"`
  96. Bookmarks int `json:"bookmarkCount"`
  97. Likes int `json:"likeCount"`
  98. Comments int `json:"commentCount"`
  99. Views int `json:"viewCount"`
  100. CommentDisabled int `json:"commentOff"`
  101. SanityLevel int `json:"sl"`
  102. XRestrict xRestrict `json:"xRestrict"`
  103. AiType aiType `json:"aiType"`
  104. User UserShort
  105. RecentWorks []IllustShort
  106. RelatedWorks []IllustShort
  107. CommentsList []Comment
  108. IsUgoira bool
  109. }
  110. func (s *Illust) ProxyImages(proxy string) {
  111. for i := range s.Images {
  112. s.Images[i].Small = ProxyImage(s.Images[i].Small, proxy)
  113. s.Images[i].Medium = ProxyImage(s.Images[i].Medium, proxy)
  114. s.Images[i].Large = ProxyImage(s.Images[i].Large, proxy)
  115. s.Images[i].Original = ProxyImage(s.Images[i].Original, proxy)
  116. }
  117. for i := range s.RecentWorks {
  118. s.RecentWorks[i].Thumbnail = ProxyImage(s.RecentWorks[i].Thumbnail, proxy)
  119. }
  120. s.RelatedWorks = ProxyShortArtworkSlice(s.RelatedWorks, proxy)
  121. s.CommentsList = ProxyCommentsSlice(s.CommentsList, proxy)
  122. s.User.Avatar = ProxyImage(s.User.Avatar, proxy)
  123. }
  124. type IllustShort struct {
  125. ID string `json:"id"`
  126. Title string `json:"title"`
  127. Description template.HTML `json:"description"`
  128. ArtistID string `json:"userId"`
  129. ArtistName string `json:"userName"`
  130. ArtistAvatar string `json:"profileImageUrl"`
  131. Date time.Time `json:"uploadDate"`
  132. Thumbnail string `json:"url"`
  133. Pages int `json:"pageCount"`
  134. XRestrict xRestrict `json:"xRestrict"`
  135. AiType aiType `json:"aiType"`
  136. }
  137. type Comment struct {
  138. AuthorID string `json:"userId"`
  139. AuthorName string `json:"userName"`
  140. Avatar string `json:"img"`
  141. Context string `json:"comment"`
  142. Stamp string `json:"stampId"`
  143. Date string `json:"commentDate"`
  144. }
  145. type User struct {
  146. ID string `json:"userId"`
  147. Name string `json:"name"`
  148. Avatar string `json:"imageBig"`
  149. BackgroundImage string `json:"background"`
  150. Following int `json:"following"`
  151. MyPixiv int `json:"mypixivCount"`
  152. Comment template.HTML `json:"commentHtml"`
  153. Webpage string `json:"webpage"`
  154. SocialRaw json.RawMessage `json:"social"`
  155. Artworks []IllustShort `json:"artworks"`
  156. ArtworksCount int
  157. FrequentTags []FrequentTag
  158. Social map[string]map[string]string
  159. }
  160. func (s *User) ProxyImages(proxy string) {
  161. s.Avatar = ProxyImage(s.Avatar, proxy)
  162. s.BackgroundImage = ProxyImage(s.BackgroundImage, proxy)
  163. s.Artworks = ProxyShortArtworkSlice(s.Artworks, proxy)
  164. }
  165. func (s *User) ParseSocial() {
  166. if string(s.SocialRaw[:]) == "[]" {
  167. // Fuck Pixiv
  168. return
  169. }
  170. _ = json.Unmarshal(s.SocialRaw, &s.Social)
  171. }
  172. type UserShort struct {
  173. ID string `json:"userId"`
  174. Name string `json:"name"`
  175. Avatar string `json:"imageBig"`
  176. }
  177. type RankedArtwork struct {
  178. ID int `json:"illust_id"`
  179. Title string `json:"title"`
  180. Rank int `json:"rank"`
  181. Pages string `json:"illust_page_count"`
  182. Image string `json:"url"`
  183. ArtistID int `json:"user_id"`
  184. ArtistName string `json:"user_name"`
  185. ArtistAvatar string `json:"profile_img"`
  186. }
  187. type TagDetail struct {
  188. Name string `json:"tag"`
  189. AlternativeName string `json:"word"`
  190. Metadata struct {
  191. Detail string `json:"abstract"`
  192. Image string `json:"image"`
  193. Name string `json:"tag"`
  194. ID json.Number `json:"id"`
  195. } `json:"pixpedia"`
  196. }
  197. type SearchArtworks struct {
  198. Artworks []IllustShort `json:"data"`
  199. Total int `json:"total"`
  200. }
  201. type SearchResult struct {
  202. Artworks SearchArtworks
  203. Popular struct {
  204. Permanent []IllustShort `json:"permanent"`
  205. Recent []IllustShort `json:"recent"`
  206. } `json:"popular"`
  207. RelatedTags []string `json:"relatedTags"`
  208. }
  209. func (s *SearchResult) ProxyImages(proxy string) {
  210. s.Artworks.Artworks = ProxyShortArtworkSlice(s.Artworks.Artworks, proxy)
  211. s.Popular.Permanent = ProxyShortArtworkSlice(s.Popular.Permanent, proxy)
  212. s.Popular.Recent = ProxyShortArtworkSlice(s.Popular.Recent, proxy)
  213. }
  214. type Pixivision struct {
  215. ID string `json:"id"`
  216. Title string `json:"title"`
  217. Thumbnail string `json:"thumbnailUrl"`
  218. URL string `json:"url"`
  219. }
  220. type LandingRecommendByTags struct {
  221. Name string `json:"tag"`
  222. Artworks []IllustShort
  223. }
  224. type LandingArtworks struct {
  225. Commissions []IllustShort
  226. Following []IllustShort
  227. Recommended []IllustShort
  228. Newest []IllustShort
  229. Rankings []IllustShort
  230. Users []IllustShort
  231. Pixivision []Pixivision
  232. RecommendByTags []LandingRecommendByTags
  233. }