constants.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package common
  2. import (
  3. "sync"
  4. "time"
  5. "github.com/google/uuid"
  6. )
  7. var StartTime = time.Now().Unix() // unit: second
  8. var Version = "v0.0.0" // this hard coding will be replaced automatically when building, no need to manually change
  9. var SystemName = "One API"
  10. var ServerAddress = "http://localhost:3000"
  11. var Footer = ""
  12. var Logo = ""
  13. var TopUpLink = ""
  14. var UsingSQLite = false
  15. // Any options with "Secret", "Token" in its key won't be return by GetOptions
  16. var SessionSecret = uuid.New().String()
  17. var SQLitePath = "one-api.db"
  18. var OptionMap map[string]string
  19. var OptionMapRWMutex sync.RWMutex
  20. var ItemsPerPage = 10
  21. var MaxRecentItems = 100
  22. var PasswordLoginEnabled = true
  23. var PasswordRegisterEnabled = true
  24. var EmailVerificationEnabled = false
  25. var GitHubOAuthEnabled = false
  26. var WeChatAuthEnabled = false
  27. var TurnstileCheckEnabled = false
  28. var RegisterEnabled = true
  29. var LogConsumeEnabled = true
  30. var SMTPServer = ""
  31. var SMTPPort = 587
  32. var SMTPAccount = ""
  33. var SMTPFrom = ""
  34. var SMTPToken = ""
  35. var GitHubClientId = ""
  36. var GitHubClientSecret = ""
  37. var WeChatServerAddress = ""
  38. var WeChatServerToken = ""
  39. var WeChatAccountQRCodeImageURL = ""
  40. var TurnstileSiteKey = ""
  41. var TurnstileSecretKey = ""
  42. var QuotaForNewUser = 0
  43. var QuotaForInviter = 0
  44. var QuotaForInvitee = 0
  45. var ChannelDisableThreshold = 5.0
  46. var AutomaticDisableChannelEnabled = false
  47. var QuotaRemindThreshold = 1000
  48. var PreConsumedQuota = 500
  49. var RootUserEmail = ""
  50. const (
  51. RoleGuestUser = 0
  52. RoleCommonUser = 1
  53. RoleAdminUser = 10
  54. RoleRootUser = 100
  55. )
  56. var (
  57. FileUploadPermission = RoleGuestUser
  58. FileDownloadPermission = RoleGuestUser
  59. ImageUploadPermission = RoleGuestUser
  60. ImageDownloadPermission = RoleGuestUser
  61. )
  62. // All duration's unit is seconds
  63. // Shouldn't larger then RateLimitKeyExpirationDuration
  64. var (
  65. GlobalApiRateLimitNum = 180
  66. GlobalApiRateLimitDuration int64 = 3 * 60
  67. GlobalWebRateLimitNum = 60
  68. GlobalWebRateLimitDuration int64 = 3 * 60
  69. UploadRateLimitNum = 10
  70. UploadRateLimitDuration int64 = 60
  71. DownloadRateLimitNum = 10
  72. DownloadRateLimitDuration int64 = 60
  73. CriticalRateLimitNum = 20
  74. CriticalRateLimitDuration int64 = 20 * 60
  75. )
  76. var RateLimitKeyExpirationDuration = 20 * time.Minute
  77. const (
  78. UserStatusEnabled = 1 // don't use 0, 0 is the default value!
  79. UserStatusDisabled = 2 // also don't use 0
  80. )
  81. const (
  82. TokenStatusEnabled = 1 // don't use 0, 0 is the default value!
  83. TokenStatusDisabled = 2 // also don't use 0
  84. TokenStatusExpired = 3
  85. TokenStatusExhausted = 4
  86. )
  87. const (
  88. RedemptionCodeStatusEnabled = 1 // don't use 0, 0 is the default value!
  89. RedemptionCodeStatusDisabled = 2 // also don't use 0
  90. RedemptionCodeStatusUsed = 3 // also don't use 0
  91. )
  92. const (
  93. ChannelStatusUnknown = 0
  94. ChannelStatusEnabled = 1 // don't use 0, 0 is the default value!
  95. ChannelStatusDisabled = 2 // also don't use 0
  96. )
  97. const (
  98. ChannelTypeUnknown = 0
  99. ChannelTypeOpenAI = 1
  100. ChannelTypeAPI2D = 2
  101. ChannelTypeAzure = 3
  102. ChannelTypeCloseAI = 4
  103. ChannelTypeOpenAISB = 5
  104. ChannelTypeOpenAIMax = 6
  105. ChannelTypeOhMyGPT = 7
  106. ChannelTypeCustom = 8
  107. ChannelTypeAILS = 9
  108. ChannelTypeAIProxy = 10
  109. ChannelTypePaLM = 11
  110. ChannelTypeAPI2GPT = 12
  111. )
  112. var ChannelBaseURLs = []string{
  113. "", // 0
  114. "https://api.openai.com", // 1
  115. "https://oa.api2d.net", // 2
  116. "", // 3
  117. "https://api.openai-proxy.org", // 4
  118. "https://api.openai-sb.com", // 5
  119. "https://api.openaimax.com", // 6
  120. "https://api.ohmygpt.com", // 7
  121. "", // 8
  122. "https://api.caipacity.com", // 9
  123. "https://api.aiproxy.io", // 10
  124. "", // 11
  125. "https://api.api2gpt.com", // 12
  126. }