계정 제재 개선
This commit is contained in:
54
core/api.go
54
core/api.go
@ -160,9 +160,12 @@ func (caller apiCaller) uploadAPI(w http.ResponseWriter, r *http.Request) error
|
||||
|
||||
func (caller apiCaller) blockAPI(w http.ResponseWriter, r *http.Request) error {
|
||||
mg := caller.mg
|
||||
logger.Println("blockAPI :", r.Method)
|
||||
if r.Method == "GET" {
|
||||
target, ok := gocommon.ReadObjectIDFormValue(r.Form, "accid")
|
||||
logger.Println("Get :", target, ok)
|
||||
if !ok {
|
||||
// 페이지네이션 해야할 듯
|
||||
json.NewEncoder(w).Encode(mg.bl.all())
|
||||
} else if !target.IsZero() {
|
||||
if blocked, ok := mg.bl.get(target); ok && blocked != nil {
|
||||
@ -170,37 +173,34 @@ func (caller apiCaller) blockAPI(w http.ResponseWriter, r *http.Request) error {
|
||||
}
|
||||
}
|
||||
} else if r.Method == "PUT" {
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
|
||||
var bipl blockinfoWithStringId
|
||||
if err := json.Unmarshal(body, &bipl); err != nil {
|
||||
var targets struct {
|
||||
Start primitive.DateTime
|
||||
End primitive.DateTime
|
||||
Accounts map[primitive.ObjectID]primitive.M // accid->meta
|
||||
}
|
||||
if err := gocommon.MakeDecoder(r).Decode(&targets); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
accid, err := primitive.ObjectIDFromHex(bipl.StrId)
|
||||
if err != nil {
|
||||
return err
|
||||
for accid, meta := range targets.Accounts {
|
||||
bi := blockinfo{
|
||||
Start: targets.Start,
|
||||
End: targets.End,
|
||||
Meta: meta,
|
||||
}
|
||||
|
||||
_, _, err := mg.mongoClient.Update(CollectionBlock, bson.M{
|
||||
"_id": accid,
|
||||
}, bson.M{
|
||||
"$set": &bi,
|
||||
}, options.Update().SetUpsert(true))
|
||||
if err != nil {
|
||||
logger.Println("account is not blocked. err :", err)
|
||||
} else {
|
||||
logger.Println("account is blocked :", meta)
|
||||
mg.sessionProvider.Delete(accid)
|
||||
}
|
||||
}
|
||||
|
||||
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{
|
||||
"$set": &bi,
|
||||
}, options.Update().SetUpsert(true))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mg.sessionProvider.Delete(accid)
|
||||
} else if r.Method == "DELETE" {
|
||||
id := r.URL.Query().Get("id")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user