module.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package model
  2. const (
  3. _OldIdx = 0
  4. _OldZone = 1
  5. _PgcIdx = 2
  6. _UgcIdx = 3
  7. _homepageID = 0
  8. )
  9. // Module def.
  10. type Module struct {
  11. ID int `json:"id"`
  12. PageID int `json:"page_id"`
  13. Type int `json:"type"`
  14. Title string `json:"title"`
  15. Icon string `json:"icon"`
  16. Source int `json:"source"`
  17. Flexible int `json:"flexible"`
  18. Capacity int `json:"capacity"`
  19. More int `json:"more"`
  20. MoreType int `json:"more_type"`
  21. MoreNewPage int `json:"more_new_page"`
  22. MorePage int `json:"more_page"`
  23. Order int `json:"order"`
  24. Data []*ModCard `json:"data"`
  25. SrcType int `json:"src_type"`
  26. }
  27. // JumpNewIdx tells whether this modules jumps to the new idx page
  28. func (m *Module) JumpNewIdx() bool {
  29. return m.MoreType == _PgcIdx || m.MoreType == _UgcIdx
  30. }
  31. // OnHomepage tells whether the module is on the homepage
  32. func (m *Module) OnHomepage() bool {
  33. return m.PageID == _homepageID
  34. }
  35. // MoreTreat treats the morepage and moretype related, used for zone/modpages, not homepage
  36. func (m *Module) MoreTreat() {
  37. if m.MorePage == 0 {
  38. return
  39. }
  40. if m.MoreType == _OldIdx || m.MoreType == _OldZone { // if more jump setting is old zone/idx (<=1.13), set more_new_page = more_page
  41. m.MoreNewPage = m.MorePage
  42. }
  43. if m.MoreType == _PgcIdx || m.MoreType == _UgcIdx { // if more jump setting is new ugc/pgc idx, set more_new_page = Idx category, more_page = page_id
  44. m.MoreNewPage = m.MorePage
  45. m.MorePage = m.PageID
  46. }
  47. }
  48. // IsUGC returns whether the module is filled by ugc or not
  49. func (m Module) IsUGC() bool {
  50. return m.SrcType == _TypeUGC
  51. }
  52. // ModCard structure, based on normal Card, 4 more fields for Follow Module
  53. type ModCard struct {
  54. Card
  55. LastEPIndex string `json:"last_ep_index"`
  56. NewestEPIndex string `json:"newest_ep_index"`
  57. TotalCount string `json:"total_count"`
  58. IsFinish string `json:"is_finish"`
  59. }
  60. // ReqModData is the request body to modData function
  61. type ReqModData struct {
  62. Mod *Module
  63. PGCListM map[int][]*Card
  64. UGCListM map[int][]*Card
  65. }
  66. // ReqPageFollow is the request body to PageFollow function
  67. type ReqPageFollow struct {
  68. AccessKey string `form:"access_key"`
  69. PageID int `form:"page_id" validate:"min=0"`
  70. Build int `form:"build"`
  71. }
  72. // ReqHomeFollow is the request body to HomeFollow function
  73. type ReqHomeFollow struct {
  74. AccessKey string `form:"access_key"`
  75. Build int `form:"build"`
  76. }