const.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package model
  2. import (
  3. "fmt"
  4. "strings"
  5. "go-common/app/interface/main/app-resource/model/tab"
  6. )
  7. const (
  8. // PlatAndroid is int8 for android.
  9. PlatAndroid = int8(0)
  10. // PlatIPhone is int8 for iphone.
  11. PlatIPhone = int8(1)
  12. // PlatIPad is int8 for ipad.
  13. PlatIPad = int8(2)
  14. // PlatWPhone is int8 for wphone.
  15. PlatWPhone = int8(3)
  16. // PlatAndroidG is int8 for Android Global.
  17. PlatAndroidG = int8(4)
  18. // PlatIPhoneI is int8 for Iphone Global.
  19. PlatIPhoneI = int8(5)
  20. // PlatIPadI is int8 for IPAD Global.
  21. PlatIPadI = int8(6)
  22. // PlatAndroidTV is int8 for AndroidTV Global.
  23. PlatAndroidTV = int8(7)
  24. // PlatAndroidI is int8 for Android Global.
  25. PlatAndroidI = int8(8)
  26. // PlatAndroidB is int8 for Android Blue.
  27. PlatAndroidB = int8(9)
  28. // PlatIPhoneB is int8 for Ios Blue
  29. PlatIPhoneB = int8(10)
  30. // PlatBilistudio is int8 for bilistudio
  31. PlatBilistudio = int8(11)
  32. // PlatAndroidTVYST is int8 for AndroidTV_YST Global.
  33. PlatAndroidTVYST = int8(12)
  34. GotoAv = "av"
  35. GotoWeb = "web"
  36. GotoBangumi = "bangumi"
  37. GotoSp = "sp"
  38. GotoLive = "live"
  39. GotoGame = "game"
  40. GotoPegasusTab = "pegasus"
  41. )
  42. var (
  43. PegasusHandler = func(m *tab.Menu) func(uri string) string {
  44. return func(uri string) string {
  45. if m == nil {
  46. return uri
  47. }
  48. if m.Name != "" {
  49. return fmt.Sprintf("%s?name=%s", uri, m.Name)
  50. }
  51. return uri
  52. }
  53. }
  54. )
  55. // Plat return plat by platStr or mobiApp
  56. func Plat(mobiApp, device string) int8 {
  57. switch mobiApp {
  58. case "iphone":
  59. if device == "pad" {
  60. return PlatIPad
  61. }
  62. return PlatIPhone
  63. case "white":
  64. return PlatIPhone
  65. case "ipad":
  66. return PlatIPad
  67. case "android":
  68. return PlatAndroid
  69. case "win":
  70. return PlatWPhone
  71. case "android_G":
  72. return PlatAndroidG
  73. case "android_i":
  74. return PlatAndroidI
  75. case "android_b":
  76. return PlatAndroidB
  77. case "iphone_i":
  78. if device == "pad" {
  79. return PlatIPadI
  80. }
  81. return PlatIPhoneI
  82. case "ipad_i":
  83. return PlatIPadI
  84. case "iphone_b":
  85. return PlatIPhoneB
  86. case "android_tv":
  87. return PlatAndroidTV
  88. case "android_tv_yst":
  89. return PlatAndroidTVYST
  90. case "bilistudio":
  91. return PlatBilistudio
  92. case "biliLink":
  93. return PlatIPhone
  94. }
  95. return PlatIPhone
  96. }
  97. // InvalidBuild check source build is not allow by config build and condition.
  98. // eg: when condition is gt, means srcBuild must gt cfgBuild, otherwise is invalid srcBuild.
  99. func InvalidBuild(srcBuild, cfgBuild int, cfgCond string) bool {
  100. if cfgBuild != 0 && cfgCond != "" {
  101. switch cfgCond {
  102. case "gt":
  103. if cfgBuild >= srcBuild {
  104. return true
  105. }
  106. case "lt":
  107. if cfgBuild <= srcBuild {
  108. return true
  109. }
  110. case "eq":
  111. if cfgBuild != srcBuild {
  112. return true
  113. }
  114. case "ne":
  115. if cfgBuild == srcBuild {
  116. return true
  117. }
  118. }
  119. }
  120. return false
  121. }
  122. // IsAndroid check plat is android or ipad.
  123. func IsAndroid(plat int8) bool {
  124. return plat == PlatAndroid || plat == PlatAndroidG || plat == PlatAndroidB || plat == PlatAndroidI ||
  125. plat == PlatBilistudio || plat == PlatAndroidTV || plat == PlatAndroidTVYST
  126. }
  127. // IsIOS check plat is iphone or ipad.
  128. func IsIOS(plat int8) bool {
  129. return plat == PlatIPad || plat == PlatIPhone || plat == PlatIPadI || plat == PlatIPhoneI || plat == PlatIPhoneB
  130. }
  131. // FillURI deal app schema.
  132. func FillURI(gt, param string, f func(uri string) string) (uri string) {
  133. if param == "" {
  134. return
  135. }
  136. switch gt {
  137. case GotoAv, "":
  138. uri = "bilibili://video/" + param
  139. case GotoLive:
  140. uri = "bilibili://live/" + param
  141. case GotoBangumi:
  142. uri = "bilibili://bangumi/season/" + param
  143. case GotoGame:
  144. uri = "bilibili://game/" + param
  145. case GotoSp:
  146. uri = "bilibili://splist/" + param
  147. case GotoWeb:
  148. uri = param
  149. case GotoPegasusTab:
  150. uri = "bilibili://pegasus/op/" + param
  151. }
  152. if f != nil {
  153. uri = f(uri)
  154. }
  155. return
  156. }
  157. // MobiAPPBuleChange
  158. func MobiAPPBuleChange(mobiApp string) string {
  159. switch mobiApp {
  160. case "android_b":
  161. return "android"
  162. case "iphone_b":
  163. return "iphone"
  164. }
  165. return mobiApp
  166. }
  167. func URLHTTPS(uri string) (url string) {
  168. if strings.HasPrefix(uri, "http://") {
  169. url = "https://" + uri[7:]
  170. } else {
  171. url = uri
  172. }
  173. return
  174. }
  175. // IsOverseas is overseas
  176. func IsOverseas(plat int8) bool {
  177. return plat == PlatAndroidI || plat == PlatIPhoneI || plat == PlatIPadI
  178. }
  179. func PlatAPPBuleChange(plat int8) int8 {
  180. switch plat {
  181. case PlatAndroidB:
  182. return PlatAndroid
  183. case PlatIPhoneB:
  184. return PlatIPhone
  185. }
  186. return plat
  187. }