Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
anti spam
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2788 committed Apr 25, 2022
1 parent 4626a3d commit 0001e3d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 0 additions & 2 deletions controller/listening/listening.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ func GetListenRoom(c *gin.Context) {
if err != nil {

if err == blive.ErrNotFound {
log.Infof("用戶索取 %v 房間資訊時不存在 (%v)", id, c.ClientIP())
c.IndentedJSON(404, gin.H{
"error": "房間不存在",
})
return
}

log.Warnf("嘗試獲取房間 %v 的直播資訊時出現錯誤: %v (%v)", id, err, c.ClientIP())
c.IndentedJSON(400, gin.H{
"error": err.Error(),
})
Expand Down
3 changes: 1 addition & 2 deletions services/api/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"encoding/json"
"fmt"
"github.com/eric2788/biligo-live-ws/services/blive"
"github.com/eric2788/biligo-live-ws/services/database"
"github.com/sirupsen/logrus"
"io"
Expand All @@ -28,7 +27,7 @@ func GetRoomInfoCache(room int64) (*RoomInfo, error) {
return roomInfo, nil
} else {
if _, ok := err.(*database.EmptyError); ok {
return nil, blive.ErrCacheNotFound
return nil, ErrCacheNotFound
} else {
return nil, err
}
Expand Down
8 changes: 6 additions & 2 deletions services/api/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package api

import (
"encoding/json"
"errors"
"fmt"
"github.com/eric2788/biligo-live-ws/services/blive"
"github.com/eric2788/biligo-live-ws/services/database"
"io"
"net/http"
Expand All @@ -12,6 +12,10 @@ import (

const UserInfoApi = "https://api.bilibili.com/x/space/acc/info?mid=%v&jsonp=jsonp"

var (
ErrCacheNotFound = errors.New("緩存不存在")
)

func GetUserInfoCache(uid int64) (*UserInfo, error) {

dbKey := fmt.Sprintf("user:%v", uid)
Expand All @@ -21,7 +25,7 @@ func GetUserInfoCache(uid int64) (*UserInfo, error) {
return userInfo, nil
} else {
if _, ok := err.(*database.EmptyError); ok {
return nil, blive.ErrCacheNotFound
return nil, ErrCacheNotFound
} else {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions services/blive/live_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ var (
)

var (
ErrNotFound = errors.New("房間不存在")
ErrTooFast = errors.New("請求頻繁")
ErrCacheNotFound = errors.New("緩存不存在")
ErrNotFound = errors.New("房間不存在")
ErrTooFast = errors.New("請求頻繁")
)

func GetListening() []interface{} {
Expand Down

0 comments on commit 0001e3d

Please sign in to comment.