subtitle.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package model
  2. import (
  3. "fmt"
  4. )
  5. var (
  6. _upTpl = `由#{%s}{"http://space.bilibili.com/%d"}在您的稿件《#{%s}{"http://www.bilibili.com/video/av%d"}》下创作的%s语言版本的字幕,已被管理员流转到%s。《#{查看详情}{"https://member.bilibili.com/v2#/zimu/my-zimu/zimu-editor?aid=%d&cid=%d&subtitleId=%d"}》)`
  7. _userTpl = `您在稿件《#{%s}{"http://www.bilibili.com/video/av%d"}》下创作的%s语言版本的字幕,已被管理员流转到%s状态。《#{查看详情}{"https://member.bilibili.com/v2#/zimu/my-zimu/zimu-editor?aid=%d&cid=%d&subtitleId=%d"}》)`
  8. // StatusContent .
  9. StatusContent = map[uint8]string{
  10. uint8(SubtitleStatusDraft): "草稿",
  11. uint8(SubtitleStatusToAudit): "待审核",
  12. uint8(SubtitleStatusAuditBack): "驳回",
  13. uint8(SubtitleStatusRemove): "删除",
  14. uint8(SubtitleStatusPublish): "发布",
  15. uint8(SubtitleStatusManagerBack): "管理员驳回",
  16. uint8(SubtitleStatusManagerRemove): "管理员删除",
  17. }
  18. )
  19. // WorkFlowSubtitleDispose .
  20. const (
  21. WorkFlowSubtitleDisposeManagerBack = int32(2) // 管理员回退
  22. WorkFlowSubtitleDisposeManagerDelete = int32(3) // 管理员删除
  23. )
  24. // SubtitleStatus .
  25. type SubtitleStatus uint8
  26. // SubtitleStatus
  27. const (
  28. SubtitleStatusUnknown SubtitleStatus = iota
  29. SubtitleStatusDraft
  30. SubtitleStatusToAudit
  31. SubtitleStatusAuditBack
  32. SubtitleStatusRemove
  33. SubtitleStatusPublish
  34. SubtitleStatusCheckToAudit
  35. SubtitleStatusCheckPublish
  36. SubtitleStatusManagerBack
  37. SubtitleStatusManagerRemove
  38. )
  39. // WorkFlowSubtitleArg .
  40. type WorkFlowSubtitleArg struct {
  41. Object *WorkFlowObject `json:"object"`
  42. Targets []*WorkFlowTarget `json:"targets"`
  43. }
  44. // WorkFlowObject .
  45. type WorkFlowObject struct {
  46. Ids []int64 `json:"id"`
  47. Business int64 `json:"business"`
  48. Reason string `json:"reason"`
  49. DisposeMode int32 `json:"dispose_mode"`
  50. }
  51. // WorkFlowTarget .
  52. type WorkFlowTarget struct {
  53. ID int64 `json:"id"`
  54. Eid int64 `json:"eid"`
  55. Oid int64 `json:"oid"`
  56. }
  57. // SearchSubtitleResult result from search
  58. type SearchSubtitleResult struct {
  59. Page *Page
  60. Result []*struct {
  61. Oid int64 `json:"oid"`
  62. ID int64 `json:"id"`
  63. } `json:"result"`
  64. }
  65. // SubtitleList .
  66. type SubtitleList struct {
  67. Page *Page `json:"page"`
  68. Subtitles []*SearchSubtitle `json:"subtitles"`
  69. }
  70. // SearchSubtitle .
  71. type SearchSubtitle struct {
  72. ID int64 `json:"subtitle_id"`
  73. Oid int64 `json:"oid"`
  74. Aid int64 `json:"aid"`
  75. ArchiveName string `json:"archive_name"`
  76. VideoName string `json:"video_name"`
  77. AuthorID int64 `json:"author_id"`
  78. Lan string `json:"lan"`
  79. LanDoc string `json:"lan_doc"`
  80. Status uint8 `json:"status"`
  81. IsSign bool `json:"is_sign"`
  82. IsLock bool `json:"is_lock"`
  83. SubtitleURL string `json:"subtitle_url"`
  84. Mtime int64 `json:"mtime"`
  85. }
  86. // SubtitlePub .
  87. type SubtitlePub struct {
  88. Oid int64
  89. Type int32
  90. Lan uint8
  91. SubtitleID int64
  92. IsDelete bool
  93. }
  94. // Subtitle .
  95. type Subtitle struct {
  96. ID int64 `json:"id"`
  97. Oid int64 `json:"oid"`
  98. Type int32 `json:"type"`
  99. Lan uint8 `json:"lan"`
  100. Aid int64 `json:"aid"`
  101. Mid int64 `json:"mid"`
  102. AuthorID int64 `json:"author_id"`
  103. UpMid int64 `json:"up_mid"`
  104. IsSign bool `json:"is_sign"`
  105. IsLock bool `json:"is_lock"`
  106. Status SubtitleStatus `json:"status"`
  107. PubTime int64 `json:"-"`
  108. SubtitleURL string `json:"subtitle_url"`
  109. Mtime int64 `json:"mtime"`
  110. }
  111. // SubtitleSearchArg .
  112. type SubtitleSearchArg struct {
  113. Aid int64
  114. Oid int64
  115. Mid int64
  116. UpperMid int64
  117. Status uint8
  118. Lan uint8
  119. Ps int32
  120. Pn int32
  121. }
  122. // SubtitleArg .
  123. type SubtitleArg struct {
  124. Aid int64 `form:"aid"`
  125. Oid int64 `form:"oid"`
  126. Mid int64 `form:"mid"`
  127. UpperMid int64 `form:"up_mid"`
  128. Status uint8 `form:"status"`
  129. Lan string `form:"lan"`
  130. Ps int32 `form:"ps" validate:"required"`
  131. Pn int32 `form:"pn" validate:"required"`
  132. }
  133. // EditSubtitleArg .
  134. type EditSubtitleArg struct {
  135. Oid int64 `form:"oid" validate:"required"`
  136. SubtileID int64 `form:"subtitle_id" validate:"required"`
  137. Status uint8 `form:"status"`
  138. NotifyAuthor bool `form:"notify_author"`
  139. NotifyUpper bool `form:"notify_upper"`
  140. }
  141. // SubtitleContext .
  142. type SubtitleContext struct {
  143. // UpdateStatus bool // 更新状态 无事务
  144. DraftCache bool // 删除草稿缓存
  145. SubtitleCache bool // 删除字幕个体缓存 (必须)
  146. RebuildPub bool // 触发到发布状态
  147. CheckHasDraft bool // 处罚到草稿状态
  148. }
  149. // Build .
  150. func (sc *SubtitleContext) Build(origin, dst SubtitleStatus) {
  151. sc.SubtitleCache = true
  152. switch origin {
  153. case SubtitleStatusDraft, SubtitleStatusToAudit:
  154. sc.DraftCache = true
  155. case SubtitleStatusPublish:
  156. sc.RebuildPub = true
  157. }
  158. switch dst {
  159. case SubtitleStatusDraft, SubtitleStatusToAudit:
  160. sc.CheckHasDraft = true
  161. case SubtitleStatusPublish:
  162. sc.RebuildPub = true
  163. }
  164. }
  165. // SubtitleLans .
  166. type SubtitleLans []*SubtitleLan
  167. // SubtitleLan .
  168. type SubtitleLan struct {
  169. Code int64 `json:"code"`
  170. Lan string `json:"lan"`
  171. DocZh string `json:"doc_zh"`
  172. DocEn string `json:"-"`
  173. }
  174. // GetByLan .
  175. func (ss SubtitleLans) GetByLan(lan string) (code int64) {
  176. for _, s := range ss {
  177. if s.Lan == lan {
  178. return s.Code
  179. }
  180. }
  181. return 0
  182. }
  183. // GetByID .
  184. func (ss SubtitleLans) GetByID(lanID int64) (lan string, doc string) {
  185. for _, s := range ss {
  186. if s.Code == lanID {
  187. return s.Lan, s.DocZh
  188. }
  189. }
  190. return
  191. }
  192. // NotifySubtitleUser .
  193. type NotifySubtitleUser struct {
  194. Mid int64
  195. Aid int64
  196. Oid int64
  197. SubtitleID int64
  198. ArchiveName string
  199. LanDoc string
  200. Status string
  201. }
  202. // NotifySubtitleUp .
  203. type NotifySubtitleUp struct {
  204. Mid int64
  205. AuthorID int64
  206. AuthorName string
  207. Aid int64
  208. Oid int64
  209. SubtitleID int64
  210. ArchiveName string
  211. LanDoc string
  212. Status string
  213. }
  214. // Msg .
  215. func (ns *NotifySubtitleUp) Msg() string {
  216. return fmt.Sprintf(_upTpl, ns.AuthorName, ns.AuthorID, ns.ArchiveName, ns.Aid, ns.LanDoc, ns.Status, ns.Aid, ns.Oid, ns.SubtitleID)
  217. }
  218. // Msg .
  219. func (ns *NotifySubtitleUser) Msg() string {
  220. return fmt.Sprintf(_userTpl, ns.ArchiveName, ns.Aid, ns.LanDoc, ns.Status, ns.Aid, ns.Oid, ns.SubtitleID)
  221. }