From e265e28498b9d1b5fd034e29abeeffa73cc2fd6b Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Mon, 18 Dec 2023 19:31:11 +0800 Subject: [PATCH] Fix: bili movie cache time and after save need decrypo --- internal/cache/bilibili.go | 6 +++--- internal/model/movie.go | 6 +++++- internal/model/vendorBackend.go | 6 +++++- internal/model/vendorRecord.go | 18 +++++++++++++++--- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/internal/cache/bilibili.go b/internal/cache/bilibili.go index ef499e7..0262f49 100644 --- a/internal/cache/bilibili.go +++ b/internal/cache/bilibili.go @@ -304,9 +304,9 @@ type BilibiliMovieCache struct { func NewBilibiliMovieCache(movie *model.Movie) *BilibiliMovieCache { return &BilibiliMovieCache{ - NoSharedMovie: newMapCache(NewBilibiliNoSharedMovieCacheInitFunc(movie), time.Minute*115), - SharedMpd: refreshcache.NewRefreshCache(NewBilibiliSharedMpdCacheInitFunc(movie), time.Minute*115), - Subtitle: refreshcache.NewRefreshCache(NewBilibiliSubtitleCacheInitFunc(movie), time.Minute*60), + NoSharedMovie: newMapCache(NewBilibiliNoSharedMovieCacheInitFunc(movie), time.Minute*60), + SharedMpd: refreshcache.NewRefreshCache(NewBilibiliSharedMpdCacheInitFunc(movie), time.Minute*60), + Subtitle: refreshcache.NewRefreshCache(NewBilibiliSubtitleCacheInitFunc(movie), 0), } } diff --git a/internal/model/movie.go b/internal/model/movie.go index 804d4db..08a766c 100644 --- a/internal/model/movie.go +++ b/internal/model/movie.go @@ -99,7 +99,7 @@ func (a *AlistStreamingInfo) BeforeSave(tx *gorm.DB) error { return nil } -func (a *AlistStreamingInfo) AfterFind(tx *gorm.DB) error { +func (a *AlistStreamingInfo) AfterSave(tx *gorm.DB) error { if a.Password != "" { b, err := utils.DecryptoFromBase64(a.Password, utils.GenCryptoKey(a.Path)) if err != nil { @@ -109,3 +109,7 @@ func (a *AlistStreamingInfo) AfterFind(tx *gorm.DB) error { } return nil } + +func (a *AlistStreamingInfo) AfterFind(tx *gorm.DB) error { + return a.AfterSave(tx) +} diff --git a/internal/model/vendorBackend.go b/internal/model/vendorBackend.go index 7f2df2d..94fd94f 100644 --- a/internal/model/vendorBackend.go +++ b/internal/model/vendorBackend.go @@ -89,7 +89,7 @@ func (v *VendorBackend) BeforeSave(tx *gorm.DB) error { return nil } -func (v *VendorBackend) AfterFind(tx *gorm.DB) error { +func (v *VendorBackend) AfterSave(tx *gorm.DB) error { key := []byte(v.Backend.Endpoint) var ( err error @@ -125,3 +125,7 @@ func (v *VendorBackend) AfterFind(tx *gorm.DB) error { } return nil } + +func (v *VendorBackend) AfterFind(tx *gorm.DB) error { + return v.AfterSave(tx) +} diff --git a/internal/model/vendorRecord.go b/internal/model/vendorRecord.go index a32a90c..b3c3daf 100644 --- a/internal/model/vendorRecord.go +++ b/internal/model/vendorRecord.go @@ -23,7 +23,7 @@ func (b *BilibiliVendor) BeforeSave(tx *gorm.DB) error { return nil } -func (b *BilibiliVendor) AfterFind(tx *gorm.DB) error { +func (b *BilibiliVendor) AfterSave(tx *gorm.DB) error { key := []byte(b.UserID) for k, v := range b.Cookies { value, err := utils.DecryptoFromBase64(v, key) @@ -35,6 +35,10 @@ func (b *BilibiliVendor) AfterFind(tx *gorm.DB) error { return nil } +func (b *BilibiliVendor) AfterFind(tx *gorm.DB) error { + return b.AfterSave(tx) +} + type AlistVendor struct { UserID string `gorm:"primaryKey"` Backend string @@ -58,7 +62,7 @@ func (a *AlistVendor) BeforeSave(tx *gorm.DB) error { return nil } -func (a *AlistVendor) AfterFind(tx *gorm.DB) error { +func (a *AlistVendor) AfterSave(tx *gorm.DB) error { key := []byte(a.UserID) if v, err := utils.DecryptoFromBase64(a.Host, key); err != nil { return err @@ -78,6 +82,10 @@ func (a *AlistVendor) AfterFind(tx *gorm.DB) error { return nil } +func (a *AlistVendor) AfterFind(tx *gorm.DB) error { + return a.AfterSave(tx) +} + type EmbyVendor struct { UserID string `gorm:"primaryKey"` Backend string @@ -105,7 +113,7 @@ func (e *EmbyVendor) BeforeSave(tx *gorm.DB) error { return nil } -func (e *EmbyVendor) AfterFind(tx *gorm.DB) error { +func (e *EmbyVendor) AfterSave(tx *gorm.DB) error { key := []byte(e.UserID) if v, err := utils.DecryptoFromBase64(e.Host, key); err != nil { return err @@ -129,3 +137,7 @@ func (e *EmbyVendor) AfterFind(tx *gorm.DB) error { } return nil } + +func (e *EmbyVendor) AfterFind(tx *gorm.DB) error { + return e.AfterSave(tx) +}