init: web_hgcg_server 初始化提交
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package m3u8requestlogmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
var db *mongos.Collection
|
||||
|
||||
func Init(ctx context.Context) {
|
||||
db = mongos.Shop.Coll(TN.M3U8RequestLog)
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.M3U8RequestLog.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.M3U8RequestLog.VideoId, Value: 1},
|
||||
{Key: FN.M3U8RequestLog.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.M3U8RequestLog.M3U8Path, Value: 1},
|
||||
{Key: FN.M3U8RequestLog.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.M3U8RequestLog.ClientIP, Value: 1},
|
||||
{Key: FN.M3U8RequestLog.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.M3U8RequestLog.Host, Value: 1},
|
||||
{Key: FN.M3U8RequestLog.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.M3U8RequestLog.Status, Value: 1},
|
||||
{Key: FN.M3U8RequestLog.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.M3U8RequestLog.TokenOK, Value: 1},
|
||||
{Key: FN.M3U8RequestLog.PathOK, Value: 1},
|
||||
{Key: FN.M3U8RequestLog.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(m3u8requestlogmod:Init) Create M3U8RequestLog Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
func InsertOneM3U8RequestLog(ctx context.Context, doc *M3U8RequestLog) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, doc); err != nil {
|
||||
log.Warn("m3u8requestlogmod:InsertOneM3U8RequestLog db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package m3u8requestlogmod
|
||||
|
||||
type TagM3U8RequestLog struct {
|
||||
CDNDomain string
|
||||
CFConnectingIP string
|
||||
ClientIP string
|
||||
CostMs string
|
||||
CreatedAt string
|
||||
Error string
|
||||
Headers string
|
||||
Host string
|
||||
Id string
|
||||
IsOverseas string
|
||||
M3U8Path string
|
||||
PathOK string
|
||||
Query string
|
||||
RawQuery string
|
||||
Referer string
|
||||
RemoteAddr string
|
||||
RequestURI string
|
||||
Status string
|
||||
T string
|
||||
Token string
|
||||
TokenOK string
|
||||
UserAgent string
|
||||
VideoId string
|
||||
XForwardedFor string
|
||||
XRealIP string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
M3U8RequestLog TagM3U8RequestLog
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
M3U8RequestLog string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.M3U8RequestLog.CDNDomain = "cdnDomain"
|
||||
FN.M3U8RequestLog.CFConnectingIP = "cfConnectingIP"
|
||||
FN.M3U8RequestLog.ClientIP = "clientIP"
|
||||
FN.M3U8RequestLog.CostMs = "costMs"
|
||||
FN.M3U8RequestLog.CreatedAt = "createdAt"
|
||||
FN.M3U8RequestLog.Error = "error"
|
||||
FN.M3U8RequestLog.Headers = "headers"
|
||||
FN.M3U8RequestLog.Host = "host"
|
||||
FN.M3U8RequestLog.Id = "_id"
|
||||
FN.M3U8RequestLog.IsOverseas = "isOverseas"
|
||||
FN.M3U8RequestLog.M3U8Path = "m3u8Path"
|
||||
FN.M3U8RequestLog.PathOK = "pathOK"
|
||||
FN.M3U8RequestLog.Query = "query"
|
||||
FN.M3U8RequestLog.RawQuery = "rawQuery"
|
||||
FN.M3U8RequestLog.Referer = "referer"
|
||||
FN.M3U8RequestLog.RemoteAddr = "remoteAddr"
|
||||
FN.M3U8RequestLog.RequestURI = "requestURI"
|
||||
FN.M3U8RequestLog.Status = "status"
|
||||
FN.M3U8RequestLog.T = "t"
|
||||
FN.M3U8RequestLog.Token = "token"
|
||||
FN.M3U8RequestLog.TokenOK = "tokenOK"
|
||||
FN.M3U8RequestLog.UserAgent = "userAgent"
|
||||
FN.M3U8RequestLog.VideoId = "videoId"
|
||||
FN.M3U8RequestLog.XForwardedFor = "xForwardedFor"
|
||||
FN.M3U8RequestLog.XRealIP = "xRealIP"
|
||||
TN.M3U8RequestLog = "m3u8_request_log"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package m3u8requestlogmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// M3U8RequestLog records every HLS playlist request for hotlink analysis.
|
||||
// @table:m3u8_request_log
|
||||
type M3U8RequestLog struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||
CreatedAt time.Time `bson:"createdAt"`
|
||||
Host string `bson:"host"`
|
||||
RequestURI string `bson:"requestURI"`
|
||||
M3U8Path string `bson:"m3u8Path"`
|
||||
RawQuery string `bson:"rawQuery"`
|
||||
Query map[string][]string `bson:"query"`
|
||||
Headers map[string][]string `bson:"headers"`
|
||||
VideoId int64 `bson:"videoId"`
|
||||
T int64 `bson:"t"`
|
||||
Token string `bson:"token"`
|
||||
ClientIP string `bson:"clientIP"`
|
||||
RemoteAddr string `bson:"remoteAddr"`
|
||||
XForwardedFor string `bson:"xForwardedFor"`
|
||||
XRealIP string `bson:"xRealIP"`
|
||||
CFConnectingIP string `bson:"cfConnectingIP"`
|
||||
UserAgent string `bson:"userAgent"`
|
||||
Referer string `bson:"referer"`
|
||||
IsOverseas bool `bson:"isOverseas"`
|
||||
CDNDomain string `bson:"cdnDomain"`
|
||||
TokenOK bool `bson:"tokenOK"`
|
||||
PathOK bool `bson:"pathOK"`
|
||||
Status string `bson:"status"`
|
||||
Error string `bson:"error"`
|
||||
CostMs int64 `bson:"costMs"`
|
||||
}
|
||||
Reference in New Issue
Block a user