diff --git a/go/main/config/common.go b/go/main/config/common.go index a537665..ee6da4c 100644 --- a/go/main/config/common.go +++ b/go/main/config/common.go @@ -16,7 +16,7 @@ func InitApplication(applicationDir string) { databasesDir = path.Join(applicationDir, "databases") remoteDir = path.Join(applicationDir, "pictures", "remote") downloadDir = path.Join(applicationDir, "download") - tmpDir = path.Join(applicationDir, "download") + tmpDir = path.Join(applicationDir, "tmp") utils.Mkdir(databasesDir) utils.Mkdir(remoteDir) utils.Mkdir(downloadDir) diff --git a/go/main/controller/client.go b/go/main/controller/client.go index d63a159..3e21d7b 100644 --- a/go/main/controller/client.go +++ b/go/main/controller/client.go @@ -73,26 +73,12 @@ func changeProxyUrl(urlStr string) bool { return true } -func cacheable(key string, expire time.Duration, reload func() (interface{}, error)) (string, error) { - // CACHE - cache := network_cache.LoadCache(key, expire) - if cache != "" { - return cache, nil - } - // obj - obj, err := reload() - if err != nil { - return "", err - } - buff, err := json.Marshal(obj) - // push to cache - if err != nil { - return "", err - } - // return - cache = string(buff) - network_cache.SaveCache(key, cache) - return cache, nil +func userProfile() (string, error) { + return serialize(client.UserProfile()) +} + +func punchIn() (string, error) { + return serialize(client.PunchIn()) } func categories() (string, error) { @@ -106,24 +92,6 @@ func categories() (string, error) { if err != nil { return "", err } - var dbCategories []comic_center.Category - for _, c := range categories { - dbCategories = append(dbCategories, comic_center.Category{ - ID: c.Id, - Title: c.Title, - Description: c.Description, - IsWeb: c.IsWeb, - Active: c.Active, - Link: c.Link, - ThumbOriginalName: c.Thumb.OriginalName, - ThumbFileServer: c.Thumb.FileServer, - ThumbPath: c.Thumb.Path, - }) - } - err = comic_center.UpSetCategories(&dbCategories) - if err != nil { - return "", err - } buff, _ := json.Marshal(&categories) cache = string(buff) network_cache.SaveCache(key, cache) diff --git a/go/main/controller/common.go b/go/main/controller/common.go index aa26d1e..5406c14 100644 --- a/go/main/controller/common.go +++ b/go/main/controller/common.go @@ -3,6 +3,8 @@ package controller import ( "encoding/json" "pikapika/main/database/comic_center" + "pikapika/main/database/network_cache" + "time" ) // EventNotify EventChannel 总线 @@ -41,6 +43,29 @@ func notifyExport(str string) { onEvent("EXPORT", str) } +// 缓存接口 +func cacheable(key string, expire time.Duration, reload func() (interface{}, error)) (string, error) { + // CACHE + cache := network_cache.LoadCache(key, expire) + if cache != "" { + return cache, nil + } + // obj + obj, err := reload() + if err != nil { + return "", err + } + buff, err := json.Marshal(obj) + // push to cache + if err != nil { + return "", err + } + // return + cache = string(buff) + network_cache.SaveCache(key, cache) + return cache, nil +} + // 将interface序列化成字符串, 方便与flutter通信 func serialize(point interface{}, err error) (string, error) { if err != nil { diff --git a/go/main/controller/pikapika.go b/go/main/controller/pikapika.go index 5e3d196..3f7611d 100644 --- a/go/main/controller/pikapika.go +++ b/go/main/controller/pikapika.go @@ -181,14 +181,6 @@ func clearToken() error { return nil } -func userProfile() (string, error) { - return serialize(client.UserProfile()) -} - -func punchIn() (string, error) { - return serialize(client.PunchIn()) -} - func remoteImageData(params string) (string, error) { var paramsStruct struct { FileServer string `json:"fileServer"` diff --git a/go/main/database/comic_center/center.go b/go/main/database/comic_center/center.go index 989506c..afe1e6e 100644 --- a/go/main/database/comic_center/center.go +++ b/go/main/database/comic_center/center.go @@ -21,7 +21,6 @@ func InitDBConnect(databaseDir string) { if err != nil { panic("failed to connect database") } - db.AutoMigrate(&Category{}) db.AutoMigrate(&ComicView{}) db.AutoMigrate(&RemoteImage{}) db.AutoMigrate(&ComicDownload{}) @@ -35,47 +34,6 @@ func Transaction(t func(tx *gorm.DB) error) error { return db.Transaction(t) } -func UpSetCategories(categories *[]Category) error { - mutex.Lock() - defer mutex.Unlock() - return db.Transaction(func(tx *gorm.DB) error { - var in []string - for _, c := range *categories { - if c.ID == "" { - continue - } - in = append(in, c.ID) - err := tx.Clauses(clause.OnConflict{ - Columns: []clause.Column{{Name: "id"}}, - DoUpdates: clause.AssignmentColumns([]string{ - "updated_at", - "title", - "description", - "is_web", - "active", - "link", - "thumb_original_name", - "thumb_file_server", - "thumb_path", - }), - }).Create(&c).Error - if err != nil { - return err - } - } - err := tx.Unscoped().Model(&Category{}).Where(" id in ?", in).Update("deleted_at", gorm.DeletedAt{ - Valid: false, - }).Error - if err != nil { - return err - } - return tx.Unscoped().Model(&Category{}).Where(" id not in ?", in).Update("deleted_at", gorm.DeletedAt{ - Time: time.Now(), - Valid: true, - }).Error - }) -} - func NoLockActionViewComicUpdateInfoDB(view *ComicView, db *gorm.DB) error { view.LastViewTime = time.Now() return db.Clauses(clause.OnConflict{ diff --git a/go/main/database/comic_center/entities.go b/go/main/database/comic_center/entities.go index 6c34fb4..f2f6a6b 100644 --- a/go/main/database/comic_center/entities.go +++ b/go/main/database/comic_center/entities.go @@ -5,21 +5,6 @@ import ( "time" ) -type Category struct { - ID string `gorm:"primarykey"` - CreatedAt time.Time - UpdatedAt time.Time - DeletedAt gorm.DeletedAt `gorm:"index"` - Title string `json:"title"` - Description string `json:"description"` - IsWeb bool `json:"isWeb"` - Active bool `json:"active"` - Link string `json:"link"` - ThumbOriginalName string - ThumbFileServer string - ThumbPath string -} - type RemoteImage struct { gorm.Model FileServer string `gorm:"index:uk_fp,unique" json:"fileServer"`