-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
202 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package db | ||
|
||
const ( | ||
STATUS_PENDING = "pending" | ||
STATUS_APPROVED = "approved" | ||
STATUS_REJECTED = "rejected" | ||
) | ||
|
||
// OrderType 用于排序的升降序类型 | ||
type OrderType string | ||
|
||
const ( | ||
ORDER_TYPE_ASC OrderType = "asc" | ||
ORDER_TYPE_DESC OrderType = "desc" | ||
) | ||
|
||
func (o OrderType) Validate() bool { | ||
return o == "asc" || o == "desc" | ||
} | ||
|
||
// OrderByType 用于排序的字段类型 | ||
type OrderByType string | ||
|
||
const ( | ||
ORDER_BY_TYPE_DATE OrderByType = "date" | ||
ORDER_BY_TYPE_SIZE OrderByType = "size" | ||
) | ||
|
||
func (o OrderByType) Validate() bool { | ||
return o == "date" || o == "size" | ||
} | ||
|
||
// TorrentZone 种子区域类型 | ||
type TorrentZone string | ||
|
||
const ( | ||
TORRENT_ZONE_OFFICIAL TorrentZone = "official" | ||
TORRENT_ZONE_GENERAL TorrentZone = "general" | ||
TORRENT_ZONE_PENDING TorrentZone = "pending" | ||
) | ||
|
||
func (t TorrentZone) Validate() bool { | ||
return t == "official" || t == "general" || t == "pending" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,67 @@ | ||
package torrent | ||
|
||
import ( | ||
"github.com/TensoRaws/NuxBT-Backend/internal/common/db" | ||
"github.com/TensoRaws/NuxBT-Backend/module/code" | ||
"github.com/TensoRaws/NuxBT-Backend/module/log" | ||
"github.com/TensoRaws/NuxBT-Backend/module/resp" | ||
"github.com/TensoRaws/NuxBT-Backend/module/util" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type OfficialRequest struct { | ||
Order string `form:"order" binding:"required,oneof=asc desc"` | ||
OrderBy string `form:"order_by" binding:"required,oneof=date size"` | ||
Page int `form:"page" binding:"required,min=1"` | ||
PerPage int `form:"per_page" binding:"required,min=10"` | ||
Search *string `form:"search" binding:"omitempty"` | ||
} | ||
|
||
type OfficialResponse struct { | ||
Torrents []OfficialInfo `json:"torrents"` | ||
TotalPage int `json:"total_page"` | ||
} | ||
|
||
// Official 获取种子文件列表 (GET /official) | ||
func Official(c *gin.Context) { | ||
// 绑定参数 | ||
var req OfficialRequest | ||
if err := c.ShouldBindQuery(&req); err != nil { | ||
resp.AbortWithMsg(c, code.RequestErrorInvalidParams, err.Error()) | ||
return | ||
} | ||
|
||
search := "" | ||
if req.Search != nil { | ||
search = *req.Search | ||
} | ||
|
||
// 获取种子列表 | ||
bts, totalPage, err := db.GetTorrentList( | ||
db.TORRENT_ZONE_OFFICIAL, db.OrderByType(req.OrderBy), db.OrderType(req.Order), | ||
req.Page, req.PerPage, search) | ||
if err != nil { | ||
resp.AbortWithMsg(c, code.DatabaseErrorRecordNotFound, err.Error()) | ||
log.Logger.Error("failed to get official torrent list" + err.Error()) | ||
return | ||
} | ||
|
||
torrentsInfo := make([]OfficialInfo, 0, len(bts)) | ||
for _, bt := range bts { | ||
torrentsInfo = append(torrentsInfo, OfficialInfo{ | ||
CreatedAt: bt.CreatedAt.Format("2006-01-02 15:04:05"), | ||
Essay: bt.Essay, | ||
Img: bt.Img, | ||
Size: util.ByteCountBinary(uint64(bt.Size)), | ||
Subtitle: bt.Subtitle, | ||
Title: bt.Title, | ||
TorrentID: bt.TorrentID, | ||
UpdateAt: bt.UpdatedAt.Format("2006-01-02 15:04:05"), | ||
}) | ||
} | ||
|
||
resp.OKWithData(c, &OfficialResponse{ | ||
Torrents: torrentsInfo, | ||
TotalPage: totalPage, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters