Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+70
View File
@@ -0,0 +1,70 @@
package fsuidmod
import (
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/models"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var mdb *db.MongoDB
const table = models.Fsid2UID
func coll(t *db.MongoTool) *db.MongoTool {
if t == nil {
return mdb.Coll(table)
}
return t.Coll(table)
}
// initIndex 初始化索引
func initIndex() {
many := []mongo.IndexModel{
{
Keys: bson.D{{Key: "fsid", Value: 1}, {Key: "uid", Value: 1}},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{{Key: "createdAt", Value: -1}},
},
}
if _, err := coll(nil).CreateIndex(many); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
}
}
// InsertFsid2UID 插入一条映射关系
func InsertFsid2UID(fsid string, uid uint64) error {
record := Fs2UID{
Fsid: fsid,
UID: uid,
CreatedAt: time.Now(),
}
if _, err := coll(nil).InsertOne(&record); err != nil {
if mongo.IsDuplicateKeyError(err) {
return nil
}
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "InsertFsid2UID", table, "InsertOne", err),
log.Any("uid", uid), log.Any("fsid", fsid))
return err
}
return nil
}
// FindFsid2UID 查找条映射关系
func FindFsid2UID(fsid string) (uint64, error) {
var record Fs2UID
if err := coll(nil).FindOne(&record, bson.M{"fsid": fsid}); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "InsertFsid2UID", table, "InsertOne", err),
log.Any("fsid", fsid))
return 0, err
}
return record.UID, nil
}