archive.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package result
  2. import (
  3. "database/sql/driver"
  4. "sync"
  5. "time"
  6. )
  7. const (
  8. AttrYes = int32(1)
  9. AttrNo = int32(0)
  10. AttrBitIsPGC = uint(9)
  11. AttrBitIsBangumi = uint(11)
  12. )
  13. type ArchiveUpInfo struct {
  14. Table string
  15. Action string
  16. Nw *Archive
  17. Old *Archive
  18. }
  19. type ResultDelay struct {
  20. Lock sync.RWMutex
  21. AIDs map[int64]struct{}
  22. }
  23. // Result archive result
  24. type Archive struct {
  25. ID int64 `json:"id"`
  26. AID int64 `json:"aid"`
  27. Mid int64 `json:"mid"`
  28. TypeID int16 `json:"typeid"`
  29. Videos int `json:"videos"`
  30. Title string `json:"title"`
  31. Cover string `json:"cover"`
  32. Content string `json:"content"`
  33. Duration int `json:"duration"`
  34. Attribute int32 `json:"attribute"`
  35. Copyright int8 `json:"copyright"`
  36. Access int `json:"access"`
  37. PubTime wocaoTime `json:"pubtime"`
  38. CTime wocaoTime `json:"ctime"`
  39. MTime wocaoTime `json:"mtime"`
  40. State int `json:"state"`
  41. MissionID int64 `json:"mission_id"`
  42. OrderID int64 `json:"order_id"`
  43. RedirectURL string `json:"redirect_url"`
  44. Forward int64 `json:"forward"`
  45. Dynamic string `json:"dynamic"`
  46. }
  47. type wocaoTime string
  48. // Scan scan time.
  49. func (jt *wocaoTime) Scan(src interface{}) (err error) {
  50. switch sc := src.(type) {
  51. case time.Time:
  52. *jt = wocaoTime(sc.Format("2006-01-02 15:04:05"))
  53. case string:
  54. *jt = wocaoTime(sc)
  55. }
  56. return
  57. }
  58. // Value get time value.
  59. func (jt wocaoTime) Value() (driver.Value, error) {
  60. return time.Parse("2006-01-02 15:04:05", string(jt))
  61. }
  62. // AttrSet set attribute.
  63. func (a *Archive) AttrSet(v int32, bit uint) {
  64. a.Attribute = a.Attribute&(^(1 << bit)) | (v << bit)
  65. }
  66. // AttrVal get attribute.
  67. func (a *Archive) AttrVal(bit uint) int32 {
  68. return (a.Attribute >> bit) & int32(1)
  69. }