Skip to content

Commit

Permalink
修复视频列表和用户列表问题
Browse files Browse the repository at this point in the history
  • Loading branch information
vclass committed Apr 28, 2024
1 parent 330a84d commit 1640ede
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
1 change: 1 addition & 0 deletions consts/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
)

const (
VIDEO_STATUS_INIT = -1
VIDEO_STATUS_TO_BE_DOWNLOAD = 0
VIDEO_STATUS_DOWNLOADING = 1
VIDEO_STATUS_DOWNLOAD_DONE = 2
Expand Down
6 changes: 4 additions & 2 deletions services/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ type AccountInfo struct {
func AccountList(page, pageSize int) (*[]*AccountInfo, int64) {
db := models.GetDB()
accountMap := make(map[int]*AccountInfo, 0)
accountMids := make([]int, 0)
total := AccountTotal()
if total > 0 {
var datas []models.BiliAccounts
db.Model(&models.BiliAccounts{}).Limit(pageSize).Offset((page - 1) * pageSize).Find(&datas)
db.Model(&models.BiliAccounts{}).Order("updated_at DESC").Limit(pageSize).Offset((page - 1) * pageSize).Find(&datas)
for _, data := range datas {
item := AccountInfo{
Mid: data.Mid,
Expand All @@ -114,10 +115,11 @@ func AccountList(page, pageSize int) (*[]*AccountInfo, int64) {
FoldersCount: 0,
}
accountMap[data.Mid] = &item
accountMids = append(accountMids, data.Mid)
}

var favourFolderInfos []models.FavourFoldersInfo
db.Where("mid IN (?)", maps.Keys(accountMap)).Find(&favourFolderInfos)
db.Where("mid IN (?)", accountMids).Find(&favourFolderInfos)
for _, v := range favourFolderInfos {
folders := FavourFolders{
Mlid: v.Mlid,
Expand Down
3 changes: 3 additions & 0 deletions services/favour.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func GetAccountFavourInfoByMid(mid int) *[]*FavourFolders {
func SetFavourSyncStatus(mid, mlid, status int) {
db := models.GetDB()
db.Model(&models.FavourFoldersInfo{}).Where("mlid = ?", mlid).Update("sync", status)
if status == consts.FAVOUR_NEED_SYNC {
db.Model(&models.FavourVideos{}).Where("mid = ? AND mlid = ? AND status = ?", mid, mlid, consts.VIDEO_STATUS_INIT).Update("status", consts.VIDEO_STATUS_TO_BE_DOWNLOAD)
}
}

type FavFile struct {
Expand Down
44 changes: 18 additions & 26 deletions services/favour_video.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func (f *FavourVideoService) Save() {
}).FirstOrInit(&favourVideo)
needUpdata := false
if favourVideo.ID == 0 {
favourVideo.Status = consts.VIDEO_STATUS_TO_BE_DOWNLOAD
favInfo := GetFavourInfoByMlid(f.V.Mlid)
favourVideo.Status = consts.VIDEO_STATUS_INIT
if favInfo != nil && favInfo.Sync == consts.FAVOUR_NEED_SYNC {
favourVideo.Status = consts.VIDEO_STATUS_TO_BE_DOWNLOAD
}
needUpdata = true
}
if favourVideo.Part != f.V.Part {
Expand Down Expand Up @@ -147,41 +151,29 @@ type VideoInfo struct {
AccountName string `json:"account_name"`
}

func handleQueryStatus(status int) []int {
statusList := []int{status}
if status == consts.VIDEO_STATUS_DOWNLOAD_FAIL {
statusList = append(statusList, consts.VIDEO_STATUS_DOWNLOAD_RETRY)
}
return statusList

}

func GetVideosByStatus(status, page, pageSize int) (*[]*VideoInfo, int64) {
result := make([]*VideoInfo, 0)
db := models.GetDB()
var total int64

statusList := []int{status}
statusList := handleQueryStatus(status)

var mlids []int
if status == consts.VIDEO_STATUS_TO_BE_DOWNLOAD {
var syncFav []models.FavourFoldersInfo
db.Model(&models.FavourFoldersInfo{}).Where(&models.FavourFoldersInfo{Sync: consts.FAVOUR_NEED_SYNC}).Find(&syncFav)
for _, v := range syncFav {
mlids = append(mlids, v.Mlid)
}
}

if status == consts.VIDEO_STATUS_DOWNLOAD_FAIL {
statusList = append(statusList, consts.VIDEO_STATUS_DOWNLOAD_RETRY)
}
query := db.Model(&models.FavourVideos{}).Where("status IN (?)", statusList)

if len(mlids) > 0 && status == consts.VIDEO_STATUS_TO_BE_DOWNLOAD {
db.Model(&models.FavourVideos{}).Where("mlid IN (?) AND status = ?", mlids, status).Count(&total)
} else if len(mlids) < 1 && status == consts.VIDEO_STATUS_TO_BE_DOWNLOAD {
return &result, 0
} else {
db.Model(&models.FavourVideos{}).Where("status IN (?)", statusList).Count(&total)
}
query.Count(&total)

if total > 0 {
var favourVideos []models.FavourVideos
if status == consts.VIDEO_STATUS_TO_BE_DOWNLOAD {
db.Model(&models.FavourVideos{}).Where("mlid IN (?) AND status = ?", mlids, status).Limit(pageSize).Offset((page - 1) * pageSize).Find(&favourVideos)
} else {
db.Model(&models.FavourVideos{}).Where("status IN (?)", statusList).Limit(pageSize).Offset((page - 1) * pageSize).Find(&favourVideos)
}
query.Order("updated_at DESC").Limit(pageSize).Offset((page - 1) * pageSize).Find(&favourVideos)
accountMap := make(map[int]*AccountInfo, 0)
favMap := make(map[int]*FavourFolders, 0)
for _, v := range favourVideos {
Expand Down

0 comments on commit 1640ede

Please sign in to comment.