feat: 从黄果 NET hgdjnet-server 9bfbafe 导入 HKDJ 官网后端
来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83 项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet 测试目录 /server/hkdj_net,App/Web API 30331/30332 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
package consts
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RunMod string
|
||||
|
||||
const (
|
||||
RunModeDev RunMod = "dev"
|
||||
RunModeTest RunMod = "test"
|
||||
RunModeProd RunMod = "prod"
|
||||
RunModRelease RunMod = "release"
|
||||
)
|
||||
|
||||
// gin中ctx使用的key
|
||||
const (
|
||||
CtxUserID = "USER_ID"
|
||||
CtxUpUserID = "UP_USER_ID"
|
||||
CtxUpInfo = "UP_INFO"
|
||||
CtxUA = "UA"
|
||||
CtxUAH5 = "UAH5"
|
||||
CtxIP = "IP"
|
||||
CtxDevId = "DEVID"
|
||||
CtxDevType = "DEVTYPE"
|
||||
CtxSysType = "SYSTYPE"
|
||||
CtxVersion = "VERSION"
|
||||
CtxBuildId = "BUILDID"
|
||||
CtxSystemName = "SYSTEM_NAME"
|
||||
CtxSystemVersion = "SYSTEM_VERSION"
|
||||
CtxToken = "TOKEN"
|
||||
CtxOnlineTime = "ONLINE_TIME"
|
||||
)
|
||||
|
||||
const (
|
||||
AppSysType_And = ""
|
||||
AppSysType_Ios = ""
|
||||
)
|
||||
|
||||
// Etcd 的Key
|
||||
const (
|
||||
EtcdWarmupDB = "/micro/config/com.sz.api.server/warmupdb"
|
||||
EtcdSzDB = "/micro/config/com.sz.api.server/db"
|
||||
EtcdRds = "/micro/config/com.sz.api.server/redis"
|
||||
)
|
||||
|
||||
const (
|
||||
AdminJwtTokenExpire = 30 * 24 * time.Hour
|
||||
UserJwtTokenExpire = 30 * 24 * time.Hour
|
||||
UserSignInExpire = 60 * 24 * time.Hour
|
||||
)
|
||||
|
||||
const (
|
||||
UAHeader = "User-Agent"
|
||||
)
|
||||
|
||||
const (
|
||||
IOS = "ios"
|
||||
Android = "android"
|
||||
H5 = "h5"
|
||||
PC = "pc"
|
||||
H5IOS = "h5_ios"
|
||||
H5Android = "h5_android"
|
||||
H5PC = "h5_pc"
|
||||
Light = "light"
|
||||
)
|
||||
|
||||
const (
|
||||
CaptchaLen = 6 //验证码长度
|
||||
)
|
||||
|
||||
const (
|
||||
TypeIOS = "ios"
|
||||
TypeAndroid = "and"
|
||||
TypeWeb = "h5"
|
||||
)
|
||||
|
||||
// 机型
|
||||
const (
|
||||
WebTypeIOS = "ios"
|
||||
WebTypeAndroid = "android"
|
||||
WebSysTypeH5 = "h5"
|
||||
)
|
||||
|
||||
// func HandleSysType(sysType string) (sys string) {
|
||||
// if strings.Contains(strings.ToLower(sysType), TypeIOS) {
|
||||
// sys = IOS
|
||||
// }
|
||||
//
|
||||
// if strings.Contains(strings.ToLower(sysType), TypeAndroid) {
|
||||
// sys = Android
|
||||
// }
|
||||
//
|
||||
// if strings.Contains(strings.ToLower(sysType), TypeWeb) {
|
||||
// sys = H5
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
func ToWebSysType(sysType string) (sys string) {
|
||||
if strings.Contains(strings.ToLower(sysType), TypeIOS) {
|
||||
sys = WebTypeIOS
|
||||
}
|
||||
|
||||
if strings.Contains(strings.ToLower(sysType), TypeAndroid) {
|
||||
sys = WebTypeAndroid
|
||||
}
|
||||
|
||||
if strings.Contains(strings.ToLower(sysType), TypeWeb) {
|
||||
sys = WebSysTypeH5
|
||||
}
|
||||
return
|
||||
}
|
||||
func ToNewSysType(sysType string) (sys string) {
|
||||
if strings.Contains(strings.ToLower(sysType), TypeIOS) {
|
||||
sys = WebTypeIOS
|
||||
}
|
||||
|
||||
if strings.Contains(strings.ToLower(sysType), TypeAndroid) {
|
||||
sys = WebTypeAndroid
|
||||
}
|
||||
|
||||
if strings.Contains(strings.ToLower(sysType), TypeWeb) {
|
||||
sys = WebSysTypeH5
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
package redisconst
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hkdj-web-server/pub/pubdef"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
visitLogFmt = "bd_visitlog:%s:%d"
|
||||
FiveMVisit = "bd_visitFmt:%s"
|
||||
BloomUser = "bd_bloom_user:%d"
|
||||
AppUserToken = "bd_app_user_token:%d"
|
||||
captchaKey = "bd_captcha_mobile_%s"
|
||||
CaptchaExpire = 5 * time.Minute
|
||||
replayNonceKey = "bd_replay:nonce:_%s"
|
||||
mediaM3U8Fmt = "m3u8cache:%s"
|
||||
MediaM3U8CacheExpire = time.Hour * 24 * 7
|
||||
appPlayletHomeCacheFmt = "app:playlet:home:%d:%s"
|
||||
appPlayletHomeCacheKeyFmt = "app:playlet:home:%d"
|
||||
appPlayletHomeCacheVersionFmt = "app:playlet:home:version:%d"
|
||||
AppPlayletHomeCacheExpire = 10 * time.Minute
|
||||
AppPlayletForwardHeatExpire = 3 * time.Second
|
||||
|
||||
//禁止登陆设置
|
||||
userForbit = "userForbit:%d"
|
||||
ipForbit = "ipForbit:%s"
|
||||
|
||||
//每分钟Ip注册次数
|
||||
registerLimist = "registerLimit:%s"
|
||||
RegisterLimistExpire = time.Minute * 30
|
||||
|
||||
//用户关注限制
|
||||
careLimitKey = "carelimit:%d"
|
||||
CareLimitKeyExpire = 15 * time.Second
|
||||
|
||||
//用户评论限制
|
||||
commentLimitKey = "commentlimit:%s"
|
||||
CommentLimitKeyExpire = 5 * time.Second
|
||||
CommentDayLimitKeyExpire = 10 * time.Hour
|
||||
|
||||
ContactUsLimitKey = "contactuslimit:%s"
|
||||
ContactusLimitKeyExpire = 1 * time.Minute
|
||||
ContactusLimitKeyDayExpire = 10
|
||||
//每用户访问次数限制
|
||||
userCallLimit = "userCall:%d"
|
||||
ipCallLimit = "ipCall:%s"
|
||||
CallLimitExpire = time.Second * 10
|
||||
|
||||
userSidKey = "userSid:%d"
|
||||
UserSidKeyExpire = time.Minute * 30
|
||||
|
||||
// 访问 IP 去重统计:每个 appId 每天一个 SET
|
||||
ipStatKey = "ipstat:%d:%s"
|
||||
IpStatExpire = 49 * time.Hour
|
||||
|
||||
// m3u8 / enkey 防盗链
|
||||
m3u8DayRateLimitIp = "m3u8dayrate:ip:%s:%s"
|
||||
m3u8DayRateLimitUser = "m3u8dayrate:user:%d:%s"
|
||||
m3u8DailyMediaIpFmt = "m3u8:daily:media:ip:%s:%d:%s"
|
||||
m3u8DailyMediaUserFmt = "m3u8:daily:media:user:%d:%d:%s"
|
||||
m3u8UserVipExpireFmt = "m3u8:user:vipExpire:%d"
|
||||
M3U8DayRateLimitMax = int64(500) // 非有效会员/未登录:按 IP 日限
|
||||
M3U8DayRateLimitVipMax = int64(1000) // 有效会员:按用户日限
|
||||
M3U8UserVipExpireCache = 5 * time.Minute
|
||||
)
|
||||
|
||||
func BloomUserKey(userId int64) string {
|
||||
return fmt.Sprintf(BloomUser, userId)
|
||||
}
|
||||
|
||||
func FiveMVisitKey(time string) string {
|
||||
return fmt.Sprintf(FiveMVisit, time)
|
||||
}
|
||||
|
||||
func UserVisitLogKey(uid int64, t time.Time) string {
|
||||
return fmt.Sprintf(visitLogFmt, t.Format("20060102"), uid)
|
||||
}
|
||||
|
||||
func MobileCaptchaKey(mobile string) string {
|
||||
return fmt.Sprintf(captchaKey, mobile)
|
||||
}
|
||||
|
||||
func AppUserTokenKey(userId int64) string {
|
||||
return fmt.Sprintf(AppUserToken, userId)
|
||||
}
|
||||
|
||||
func MediaM3U8Key(name string) string {
|
||||
return fmt.Sprintf(mediaM3U8Fmt, name)
|
||||
}
|
||||
|
||||
func AppPlayletHomeCacheKey() string {
|
||||
return fmt.Sprintf(appPlayletHomeCacheKeyFmt, pubdef.AppId)
|
||||
}
|
||||
|
||||
func AppPlayletHomeCacheVersionKey() string {
|
||||
return fmt.Sprintf(appPlayletHomeCacheVersionFmt, pubdef.AppId)
|
||||
}
|
||||
|
||||
func AppPlayletHomeCacheDataKey(version string) string {
|
||||
return fmt.Sprintf(appPlayletHomeCacheFmt, pubdef.AppId, version)
|
||||
}
|
||||
|
||||
func AppPlayletForwardHeatKey(operator string, playletId int64) string {
|
||||
operator = strings.ReplaceAll(operator, ":", "-")
|
||||
return fmt.Sprintf("app:playlet:forward:heat:%s:%d", operator, playletId)
|
||||
}
|
||||
|
||||
func UserForbitKey(userId int64) string {
|
||||
return fmt.Sprintf(userForbit, userId)
|
||||
}
|
||||
|
||||
func RegisterLimitKey(ip string) string {
|
||||
ip = strings.ReplaceAll(ip, ":", "-")
|
||||
return fmt.Sprintf(registerLimist, ip)
|
||||
}
|
||||
|
||||
func CareLimitKey(userId int64) string {
|
||||
return fmt.Sprintf(careLimitKey, userId)
|
||||
}
|
||||
func ReplayNonceKey(nonce string) string {
|
||||
return fmt.Sprintf(replayNonceKey, nonce)
|
||||
}
|
||||
|
||||
func CommentLimitKey(ip string) string {
|
||||
return fmt.Sprintf(commentLimitKey, ip)
|
||||
}
|
||||
func CommentOneDayLimitKey(ip string) string {
|
||||
return fmt.Sprintf("commentdaylimit:%s", ip)
|
||||
}
|
||||
|
||||
func UserCallLimitKey(userId int64) string {
|
||||
return fmt.Sprintf(userCallLimit, userId)
|
||||
}
|
||||
|
||||
func IpCallLimitKey(ip string) string {
|
||||
return fmt.Sprintf(ipCallLimit, ip)
|
||||
}
|
||||
|
||||
func IpForbitKey(ip string) string {
|
||||
ip = strings.ReplaceAll(ip, ":", "-")
|
||||
return fmt.Sprintf(ipForbit, ip)
|
||||
}
|
||||
|
||||
func UserSidKey(userId int64) string {
|
||||
return fmt.Sprintf(userSidKey, userId)
|
||||
}
|
||||
|
||||
func IpStatKey(appId int64, date string) string {
|
||||
return fmt.Sprintf(ipStatKey, appId, date)
|
||||
}
|
||||
|
||||
func M3U8DayRateLimitIpKey(ip string) string {
|
||||
ip = normalizeM3U8Ip(ip)
|
||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
if err != nil {
|
||||
loc = time.Local
|
||||
}
|
||||
day := time.Now().In(loc).Format("20060102")
|
||||
return fmt.Sprintf(m3u8DayRateLimitIp, ip, day)
|
||||
}
|
||||
|
||||
func M3U8DayRateLimitUserKey(userId int64) string {
|
||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
if err != nil {
|
||||
loc = time.Local
|
||||
}
|
||||
day := time.Now().In(loc).Format("20060102")
|
||||
return fmt.Sprintf(m3u8DayRateLimitUser, userId, day)
|
||||
}
|
||||
|
||||
func M3U8DayRateLimitExpire() time.Duration {
|
||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
if err != nil {
|
||||
loc = time.Local
|
||||
}
|
||||
now := time.Now().In(loc)
|
||||
next := time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, loc)
|
||||
d := next.Sub(now)
|
||||
if d < time.Minute {
|
||||
return time.Minute
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func normalizeM3U8Ip(ip string) string {
|
||||
return strings.ReplaceAll(ip, ":", "-")
|
||||
}
|
||||
|
||||
func M3U8DailyMediaIpKey(ip string, mediaId int64) string {
|
||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
if err != nil {
|
||||
loc = time.Local
|
||||
}
|
||||
day := time.Now().In(loc).Format("20060102")
|
||||
return fmt.Sprintf(m3u8DailyMediaIpFmt, normalizeM3U8Ip(ip), mediaId, day)
|
||||
}
|
||||
|
||||
func M3U8DailyMediaUserKey(userId int64, mediaId int64) string {
|
||||
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||
if err != nil {
|
||||
loc = time.Local
|
||||
}
|
||||
day := time.Now().In(loc).Format("20060102")
|
||||
return fmt.Sprintf(m3u8DailyMediaUserFmt, userId, mediaId, day)
|
||||
}
|
||||
|
||||
func M3U8UserVipExpireKey(userId int64) string {
|
||||
return fmt.Sprintf(m3u8UserVipExpireFmt, userId)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package video
|
||||
|
||||
type VideoType int64
|
||||
type videoStatus int64
|
||||
|
||||
// 0-上架、1-未上架
|
||||
const (
|
||||
Enable videoStatus = iota
|
||||
Disable
|
||||
)
|
||||
|
||||
// 1是AV、2是SP
|
||||
const (
|
||||
_ VideoType = iota
|
||||
AV
|
||||
SP
|
||||
)
|
||||
|
||||
const AVLimit = 1
|
||||
|
||||
type recordType int64
|
||||
|
||||
const (
|
||||
_ recordType = iota
|
||||
Watch
|
||||
Downlaoad
|
||||
)
|
||||
Reference in New Issue
Block a user