audit_v2.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package model
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "go-common/library/ecode"
  7. )
  8. // audit related consts
  9. const (
  10. _ugcPrefix = "ugc"
  11. _pgcPrefix = "xds"
  12. // the field valid options
  13. _hidden = 0
  14. _online = 1
  15. // pgc audit status
  16. _seasonReject = 0
  17. _seasonPass = 1
  18. // ugc audit status
  19. _ugcPass = 1
  20. _ugcReject = 2
  21. // audit type
  22. _reject = "1"
  23. // IDlist's type field
  24. _season = "1"
  25. // content type
  26. PgcSn = "7"
  27. PgcEp = "8"
  28. UgcArc = "9"
  29. UgcVideo = "10"
  30. )
  31. // IDList def.
  32. type IDList struct {
  33. Type string `json:"type"`
  34. VID string `json:"vid"`
  35. Action string `json:"action"`
  36. AuditMsg string `json:"audit_msg"`
  37. }
  38. // IsReject def.
  39. func (v *IDList) IsReject() bool {
  40. return v.Action == _reject
  41. }
  42. // IsShell tells whether it's about archive/season
  43. func (v *IDList) IsShell() bool {
  44. return v.Type == _season
  45. }
  46. // AuditOp def.
  47. type AuditOp struct {
  48. KID int64 // aid/cid/sid/epid
  49. Result int // pgc sn: `check`, pgc ep: state, ugc: result
  50. Valid int
  51. AuditMsg string
  52. ContentType string // type
  53. }
  54. // ToMsg def
  55. func (v *AuditOp) ToMsg() string {
  56. return fmt.Sprintf("audit_Type(%s)_KID(%d)", v.ContentType, v.KID)
  57. }
  58. // parse prefix and get the real ID
  59. func parsePrefix(value string, prefix string) (res bool, vid int64) {
  60. if strings.Contains(value, prefix) {
  61. res = true
  62. ids := strings.Split(value, prefix)
  63. vid, _ = strconv.ParseInt(ids[1], 10, 64)
  64. }
  65. return
  66. }
  67. // FromIDList def.
  68. func (v *AuditOp) FromIDList(req *IDList) (err error) {
  69. var (
  70. isUGC, isPGC bool
  71. )
  72. // auditMsg treatment
  73. v.AuditMsg = req.AuditMsg
  74. // KID & content type treatment
  75. if isPGC, v.KID = parsePrefix(req.VID, _pgcPrefix); !isPGC { // not pgc, try ugc
  76. if isUGC, v.KID = parsePrefix(req.VID, _ugcPrefix); !isUGC { // not ugc, unknown type
  77. return ecode.RequestErr // unknown type
  78. }
  79. }
  80. // Valid treatment
  81. if req.IsReject() { // decide the valid value
  82. v.Valid = _hidden
  83. } else {
  84. v.Valid = _online
  85. }
  86. // Result & Content Type treatment
  87. if isPGC { // pgc
  88. if req.IsShell() { // season
  89. v.ContentType = PgcSn
  90. if req.IsReject() {
  91. v.Result = _seasonReject
  92. } else {
  93. v.Result = _seasonPass
  94. }
  95. } else { // ep
  96. v.ContentType = PgcEp
  97. if req.IsReject() {
  98. v.Result = _epRejected
  99. } else {
  100. v.Result = _epPass
  101. }
  102. }
  103. } else { // ugc
  104. if req.IsShell() {
  105. v.ContentType = UgcArc
  106. } else {
  107. v.ContentType = UgcVideo
  108. }
  109. if req.IsReject() {
  110. v.Result = _ugcReject
  111. } else {
  112. v.Result = _ugcPass
  113. }
  114. }
  115. return
  116. }