계정 제재 동작 오류 수정
This commit is contained in:
22
core/api.go
22
core/api.go
@ -165,13 +165,27 @@ func (caller apiCaller) blockAPI(w http.ResponseWriter, r *http.Request) error {
|
|||||||
enc.Encode(mg.bl.all())
|
enc.Encode(mg.bl.all())
|
||||||
} else if r.Method == "PUT" {
|
} else if r.Method == "PUT" {
|
||||||
body, _ := io.ReadAll(r.Body)
|
body, _ := io.ReadAll(r.Body)
|
||||||
var bi blockinfo
|
|
||||||
if err := json.Unmarshal(body, &bi); err != nil {
|
var bipl blockinfoWithStringId
|
||||||
|
if err := json.Unmarshal(body, &bipl); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err := mg.mongoClient.Update(CollectionBlock, bson.M{
|
accid, err := primitive.ObjectIDFromHex(bipl.StrId)
|
||||||
"_id": primitive.NewObjectID(),
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
bi := blockinfo{
|
||||||
|
Start: primitive.NewDateTimeFromTime(time.Unix(bipl.StartUnix, 0)),
|
||||||
|
End: primitive.NewDateTimeFromTime(time.Unix(bipl.EndUnix, 0)),
|
||||||
|
Reason: bipl.Reason,
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Println("bi :", accid, bi)
|
||||||
|
|
||||||
|
_, _, err = mg.mongoClient.Update(CollectionBlock, bson.M{
|
||||||
|
"_id": accid,
|
||||||
}, bson.M{
|
}, bson.M{
|
||||||
"$set": &bi,
|
"$set": &bi,
|
||||||
}, options.Update().SetUpsert(true))
|
}, options.Update().SetUpsert(true))
|
||||||
|
|||||||
39
core/api_test.go
Normal file
39
core/api_test.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
|
"repositories.action2quare.com/ayo/gocommon"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMakeLocalUniqueId(t *testing.T) {
|
||||||
|
ts := int64(1690815600)
|
||||||
|
start := primitive.NewDateTimeFromTime(time.Unix(ts, 0))
|
||||||
|
ts = int64(1693493999)
|
||||||
|
end := primitive.NewDateTimeFromTime(time.Unix(ts, 0))
|
||||||
|
|
||||||
|
fmt.Println(start.Time().Format(time.RFC3339))
|
||||||
|
fmt.Println(end.Time().Format(time.RFC3339))
|
||||||
|
|
||||||
|
mongoClient, err := gocommon.NewMongoClient(context.Background(), "mongodb://121.134.91.160:27018/?replicaSet=rs0&retrywrites=true", "mountain-maingate")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
bi := blockinfo{
|
||||||
|
Start: start,
|
||||||
|
End: end,
|
||||||
|
Reason: "test",
|
||||||
|
}
|
||||||
|
mongoClient.Update(CollectionBlock, bson.M{
|
||||||
|
"_id": primitive.NewObjectID(),
|
||||||
|
}, bson.M{
|
||||||
|
"$set": &bi,
|
||||||
|
}, options.Update().SetUpsert(true))
|
||||||
|
}
|
||||||
@ -340,10 +340,10 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = mg.mongoClient.MakeUniqueIndices(CollectionBlock, map[string]bson.D{
|
if *devflag {
|
||||||
"codeaccid": {{Key: "code", Value: 1}, {Key: "accid", Value: 1}},
|
if err = mg.mongoClient.DropIndex(CollectionBlock, "codeaccid"); err != nil {
|
||||||
}); err != nil {
|
return err
|
||||||
return err
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = mg.mongoClient.MakeExpireIndex(CollectionBlock, int32(3)); err != nil {
|
if err = mg.mongoClient.MakeExpireIndex(CollectionBlock, int32(3)); err != nil {
|
||||||
@ -417,7 +417,7 @@ func (mg *Maingate) prepare(context context.Context) (err error) {
|
|||||||
mg.wl.init(whites)
|
mg.wl.init(whites)
|
||||||
|
|
||||||
var blocks []*blockinfo
|
var blocks []*blockinfo
|
||||||
if err := mg.mongoClient.AllAs(CollectionBlock, &blocks, options.Find().SetReturnKey(false)); err != nil {
|
if err := mg.mongoClient.AllAs(CollectionBlock, &blocks); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
mg.bl.init(blocks)
|
mg.bl.init(blocks)
|
||||||
|
|||||||
@ -21,10 +21,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type blockinfo struct {
|
type blockinfo struct {
|
||||||
Accid primitive.ObjectID `bson:"_id" json:"_id"`
|
|
||||||
Start primitive.DateTime `bson:"start" json:"start"`
|
Start primitive.DateTime `bson:"start" json:"start"`
|
||||||
End primitive.DateTime `bson:"_ts"`
|
End primitive.DateTime `bson:"_ts" json:"_ts"`
|
||||||
Reason string `bson:"reason" json:"reason"`
|
Reason string `bson:"reason" json:"reason"`
|
||||||
|
Accid primitive.ObjectID `bson:"_id,omitempty" json:"_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type blockinfoWithStringId struct {
|
||||||
|
Reason string `bson:"reason" json:"reason"`
|
||||||
|
StrId string `bson:"id" json:"id"`
|
||||||
|
StartUnix int64 `bson:"start_unix" json:"start_unix"`
|
||||||
|
EndUnix int64 `bson:"end_unix" json:"end_unix"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type whitelistmember struct {
|
type whitelistmember struct {
|
||||||
@ -53,7 +60,7 @@ func (bi *blockinfo) Key() primitive.ObjectID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bi *blockinfo) Expired() bool {
|
func (bi *blockinfo) Expired() bool {
|
||||||
return bi.End.Time().Before(time.Now().UTC())
|
return bi.End.Time().Unix() < time.Now().UTC().Unix()
|
||||||
}
|
}
|
||||||
|
|
||||||
type usertokeninfo struct {
|
type usertokeninfo struct {
|
||||||
|
|||||||
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
|||||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||||
go.mongodb.org/mongo-driver v1.11.7
|
go.mongodb.org/mongo-driver v1.11.7
|
||||||
google.golang.org/api v0.128.0
|
google.golang.org/api v0.128.0
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230801051747-b501160efc3b
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230823084014-c34045e215fc
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|||||||
2
go.sum
2
go.sum
@ -329,3 +329,5 @@ repositories.action2quare.com/ayo/gocommon v0.0.0-20230710085810-8173216e9574 h1
|
|||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710085810-8173216e9574/go.mod h1:rn6NA28Mej+qgLNx/Bu2wsdGyIycmacqlNP6gUXX2a0=
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230710085810-8173216e9574/go.mod h1:rn6NA28Mej+qgLNx/Bu2wsdGyIycmacqlNP6gUXX2a0=
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230801051747-b501160efc3b h1:yV1cBeu0GFxkDD6TDxzKv/rM3OMtyt1JXpeqDF5IO3Y=
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230801051747-b501160efc3b h1:yV1cBeu0GFxkDD6TDxzKv/rM3OMtyt1JXpeqDF5IO3Y=
|
||||||
repositories.action2quare.com/ayo/gocommon v0.0.0-20230801051747-b501160efc3b/go.mod h1:PdpZ16O1czKKxCxn+0AFNaEX/0kssYwC3G8jR0V7ybw=
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230801051747-b501160efc3b/go.mod h1:PdpZ16O1czKKxCxn+0AFNaEX/0kssYwC3G8jR0V7ybw=
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230823084014-c34045e215fc h1:/nFKyjpcfMCdC7vrEZ7+IQOA5RoMmcBUHNRl40JN3ys=
|
||||||
|
repositories.action2quare.com/ayo/gocommon v0.0.0-20230823084014-c34045e215fc/go.mod h1:PdpZ16O1czKKxCxn+0AFNaEX/0kssYwC3G8jR0V7ybw=
|
||||||
|
|||||||
Reference in New Issue
Block a user