contribute.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. package space
  2. import (
  3. "go-common/app/interface/main/app-interface/model"
  4. "go-common/app/interface/main/app-interface/model/audio"
  5. "go-common/app/interface/main/app-interface/model/bplus"
  6. article "go-common/app/interface/openplatform/article/model"
  7. "go-common/app/service/main/archive/api"
  8. xtime "go-common/library/time"
  9. "strconv"
  10. )
  11. const (
  12. _gotoAv = 0
  13. _gotoArticle = 1
  14. _gotoClip = 2
  15. _gotoAlbum = 3
  16. _gotoAudio = 4
  17. )
  18. // Contributes struct
  19. type Contributes struct {
  20. Tab *Tab `json:"tab,omitempty"`
  21. Items []*Item `json:"items,omitempty"`
  22. Links *Links `json:"links,omitempty"`
  23. }
  24. // Tab struct
  25. type Tab struct {
  26. Archive bool `json:"archive"`
  27. Article bool `json:"article"`
  28. Clip bool `json:"clip"`
  29. Album bool `json:"album"`
  30. Favorite bool `json:"favorite"`
  31. Bangumi bool `json:"bangumi"`
  32. Coin bool `json:"coin"`
  33. Like bool `json:"like"`
  34. Community bool `json:"community"`
  35. Dynamic bool `json:"dynamic"`
  36. Audios bool `json:"audios"`
  37. Shop bool `json:"shop"`
  38. }
  39. // Item struct
  40. type Item struct {
  41. ID int64 `json:"id,omitempty"`
  42. TypeName string `json:"tname,omitempty"`
  43. Category *article.Category `json:"category,omitempty"`
  44. Title string `json:"title,omitempty"`
  45. Cover string `json:"cover,omitempty"`
  46. Tag string `json:"tag,omitempty"`
  47. Tags []*article.Tag `json:"tags,omitempty"`
  48. Desc string `json:"description,omitempty"`
  49. URI string `json:"uri,omitempty"`
  50. Param string `json:"param,omitempty"`
  51. Goto string `json:"goto,omitempty"`
  52. Length string `json:"length,omitempty"`
  53. Duration int64 `json:"duration,omitempty"`
  54. Banner string `json:"banner,omitempty"`
  55. Play int `json:"play,omitempty"`
  56. Comment int `json:"comment,omitempty"`
  57. Danmaku int `json:"danmaku,omitempty"`
  58. Count int `json:"count,omitempty"`
  59. Reply int `json:"reply,omitempty"`
  60. CTime xtime.Time `json:"ctime,omitempty"`
  61. MTime xtime.Time `json:"mtime,omitempty"`
  62. ImageURLs []string `json:"image_urls,omitempty"`
  63. Pictures []*bplus.Pictures `json:"pictures,omitempty"`
  64. Words int64 `json:"words,omitempty"`
  65. Stats *article.Stats `json:"stats,omitempty"`
  66. AuthType int `json:"authType,omitempty"`
  67. Member int64 `json:"member,omitempty"`
  68. }
  69. // Links struct
  70. type Links struct {
  71. Previous int64 `json:"previous,omitempty"`
  72. Next int64 `json:"next,omitempty"`
  73. }
  74. // Link func
  75. func (l *Links) Link(sinceID, untilID int64) {
  76. if sinceID < 0 || untilID < 0 {
  77. return
  78. }
  79. l.Previous = sinceID
  80. l.Next = untilID
  81. }
  82. // Items struct
  83. type Items []*Item
  84. //Len()
  85. func (is Items) Len() int { return len(is) }
  86. //Less()
  87. func (is Items) Less(i, j int) bool {
  88. var it, jt xtime.Time
  89. if is[i] != nil {
  90. it = is[i].CTime
  91. }
  92. if is[j] != nil {
  93. jt = is[j].CTime
  94. }
  95. return it > jt
  96. }
  97. //Swap()
  98. func (is Items) Swap(i, j int) {
  99. is[i], is[j] = is[j], is[i]
  100. }
  101. // Clip struct
  102. type Clip struct {
  103. ID int64 `json:"id"`
  104. Duration int64 `json:"duration"`
  105. CTime xtime.Time `json:"ctime"`
  106. View int `json:"view"`
  107. Damaku int `json:"damaku"`
  108. Title string `json:"title"`
  109. Cover string `json:"cover"`
  110. Tag string `json:"tag"`
  111. }
  112. // Album struct
  113. type Album struct {
  114. ID int64 `json:"doc_id"`
  115. CTime xtime.Time `json:"ctime"`
  116. Count int `json:"count"`
  117. View int `json:"view"`
  118. Comment int `json:"comment"`
  119. Title string `json:"title"`
  120. Desc string `json:"description"`
  121. Pictures []*Pictures `json:"pictures"`
  122. }
  123. // Pictures struct
  124. type Pictures struct {
  125. ImgSrc string `json:"img_src"`
  126. ImgWidth string `json:"img_width"`
  127. ImgHeight string `json:"img_height"`
  128. }
  129. // Tag tag.
  130. type Tag struct {
  131. Tid int64 `json:"tid"`
  132. Name string `json:"name"`
  133. }
  134. // FromArc3 func
  135. func (i *Item) FromArc3(a *api.Arc) {
  136. i.ID = a.Aid
  137. i.Title = a.Title
  138. i.Cover = a.Pic
  139. i.TypeName = a.TypeName
  140. i.Param = strconv.FormatInt(a.Aid, 10)
  141. i.Goto = model.GotoAv
  142. i.URI = model.FillURI(i.Goto, i.Param, nil)
  143. i.Danmaku = int(a.Stat.Danmaku)
  144. i.Duration = a.Duration
  145. i.CTime = a.PubDate
  146. i.Play = int(a.Stat.View)
  147. }
  148. // FromArticle func
  149. func (i *Item) FromArticle(a *article.Meta) {
  150. i.ID = a.ID
  151. i.Title = a.Title
  152. i.Category = a.Category
  153. i.Desc = a.Summary
  154. i.ImageURLs = a.ImageURLs
  155. i.CTime = a.Ctime
  156. i.Tags = a.Tags
  157. i.Banner = a.BannerURL
  158. i.Param = strconv.FormatInt(a.ID, 10)
  159. i.Goto = model.GotoArticle
  160. i.URI = model.FillURI(i.Goto, i.Param, nil)
  161. i.Stats = a.Stats
  162. }
  163. // FromClip func
  164. func (i *Item) FromClip(c *bplus.Clip) {
  165. i.ID = c.ID
  166. i.Duration = c.Duration
  167. i.CTime = c.CTime
  168. i.Play = c.View
  169. i.Danmaku = c.Damaku
  170. i.Param = strconv.FormatInt(c.ID, 10)
  171. i.Goto = model.GotoClip
  172. i.URI = model.FillURI(i.Goto, i.Param, nil)
  173. i.Title = c.Title
  174. i.Cover = c.Cover
  175. i.Tag = c.Tag
  176. }
  177. // FromAlbum func
  178. func (i *Item) FromAlbum(a *bplus.Album) {
  179. i.ID = a.ID
  180. i.CTime = a.CTime
  181. i.Count = a.Count
  182. i.Play = a.View
  183. i.Comment = a.Comment
  184. i.Param = strconv.FormatInt(a.ID, 10)
  185. i.Goto = model.GotoAlbum
  186. i.URI = model.FillURI(i.Goto, i.Param, nil)
  187. i.Title = a.Title
  188. i.Desc = a.Desc
  189. i.Pictures = a.Pictures
  190. }
  191. // FromAudio func
  192. func (i *Item) FromAudio(a *audio.Audio) {
  193. i.ID = a.ID
  194. i.CTime = a.CTime
  195. i.Play = a.Play
  196. i.Reply = a.Reply
  197. i.Param = strconv.FormatInt(a.ID, 10)
  198. i.Goto = model.GotoAudio
  199. i.URI = a.Schema
  200. i.Cover = a.Cover
  201. i.Title = a.Title
  202. i.AuthType = a.AuthType
  203. i.Duration = a.Duration
  204. }
  205. // FormatKey func
  206. func (i *Item) FormatKey() {
  207. switch i.Goto {
  208. case model.GotoAv:
  209. i.Member = i.ID<<6 | _gotoAv
  210. case model.GotoArticle:
  211. i.Member = i.ID<<6 | _gotoArticle
  212. case model.GotoClip:
  213. i.Member = i.ID<<6 | _gotoClip
  214. case model.GotoAlbum:
  215. i.Member = i.ID<<6 | _gotoAlbum
  216. case model.GotoAudio:
  217. i.Member = i.ID<<6 | _gotoAudio
  218. default:
  219. i.Member = i.ID
  220. }
  221. }
  222. // ParseKey func
  223. func (i *Item) ParseKey() {
  224. i.ID = i.Member >> 6
  225. switch int(i.Member & 0x3f) {
  226. case _gotoAv:
  227. i.Goto = model.GotoAv
  228. case _gotoArticle:
  229. i.Goto = model.GotoArticle
  230. case _gotoClip:
  231. i.Goto = model.GotoClip
  232. case _gotoAlbum:
  233. i.Goto = model.GotoAlbum
  234. case _gotoAudio:
  235. i.Goto = model.GotoAudio
  236. }
  237. }
  238. // Attrs struct
  239. type Attrs struct {
  240. Archive bool `json:"archive,omitempty"`
  241. Article bool `json:"article,omitempty"`
  242. Clip bool `json:"clip,omitempty"`
  243. Album bool `json:"album,omitempty"`
  244. Audio bool `json:"audio,omitempty"`
  245. }