refactor: Gitea 式目录改组,移除本分支 SPA 与杂项产物
将 model/service/handler/middleware 迁至 models/services/routers/api/modules/auth,并删除 frontend、embed_static、scripts 及误入库缓存/二进制。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
62
services/friend_link_reciprocal_async.go
Normal file
62
services/friend_link_reciprocal_async.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.iioio.com/freefire/jiang13-forum/model"
|
||||
)
|
||||
|
||||
const reciprocalCheckConcurrency = 3
|
||||
|
||||
var (
|
||||
reciprocalCheckMu sync.Mutex
|
||||
reciprocalCheckGen = map[uint]uint64{}
|
||||
reciprocalCheckSem = make(chan struct{}, reciprocalCheckConcurrency)
|
||||
)
|
||||
|
||||
func init() {
|
||||
for i := 0; i < reciprocalCheckConcurrency; i++ {
|
||||
reciprocalCheckSem <- struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// EnqueueReciprocalCheck 异步检测回链;同一申请多次入队时仅保留最后一次结果
|
||||
func EnqueueReciprocalCheck(applyID uint, pageURL, ourSiteURL string) {
|
||||
reciprocalCheckMu.Lock()
|
||||
reciprocalCheckGen[applyID]++
|
||||
gen := reciprocalCheckGen[applyID]
|
||||
reciprocalCheckMu.Unlock()
|
||||
|
||||
go runReciprocalCheck(applyID, gen, pageURL, ourSiteURL)
|
||||
}
|
||||
|
||||
func runReciprocalCheck(applyID uint, gen uint64, pageURL, ourSiteURL string) {
|
||||
reciprocalCheckSem <- struct{}{}
|
||||
defer func() { <-reciprocalCheckSem }()
|
||||
|
||||
verified, note := VerifyReciprocalLink(pageURL, ourSiteURL)
|
||||
now := time.Now()
|
||||
|
||||
reciprocalCheckMu.Lock()
|
||||
if reciprocalCheckGen[applyID] != gen {
|
||||
reciprocalCheckMu.Unlock()
|
||||
return
|
||||
}
|
||||
reciprocalCheckMu.Unlock()
|
||||
|
||||
_ = model.DB.Model(&model.FriendLinkApply{}).Where("id = ?", applyID).Updates(map[string]interface{}{
|
||||
"reciprocal_verified": verified,
|
||||
"reciprocal_check_note": note,
|
||||
"reciprocal_checked_at": now,
|
||||
}).Error
|
||||
}
|
||||
|
||||
// ResetReciprocalCheckState 重置为检测中,供重新检测使用
|
||||
func ResetReciprocalCheckState(applyID uint) {
|
||||
_ = model.DB.Model(&model.FriendLinkApply{}).Where("id = ?", applyID).Updates(map[string]interface{}{
|
||||
"reciprocal_verified": false,
|
||||
"reciprocal_check_note": "",
|
||||
"reciprocal_checked_at": nil,
|
||||
}).Error
|
||||
}
|
||||
Reference in New Issue
Block a user