Skip to content

Commit

Permalink
添加 feedback 逻辑
Browse files Browse the repository at this point in the history
Signed-off-by: allan716 <525223688@qq.com>
  • Loading branch information
allanpk716 committed Jul 14, 2022
1 parent 91b599c commit ec84c3b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/chinesesubfinder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strings"
"time"

"github.com/allanpk716/ChineseSubFinder/internal/dao"

"github.com/allanpk716/ChineseSubFinder/pkg/logic/cron_helper"
"github.com/allanpk716/ChineseSubFinder/pkg/logic/file_downloader"
"github.com/allanpk716/ChineseSubFinder/pkg/logic/pre_job"
Expand Down Expand Up @@ -66,6 +68,9 @@ func init() {
if my_util.OSCheck() == false {
loggerBase.Panicln(`You should search runtime.GOOS in the project, Implement unimplemented function`)
}
// --------------------------------------------------
// 初始化设备的信息
dao.UpdateInfo(AppVersion, settings.GetSettings())
}

func main() {
Expand Down
40 changes: 40 additions & 0 deletions internal/dao/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package dao

import (
"github.com/allanpk716/ChineseSubFinder/internal/models"
"github.com/allanpk716/ChineseSubFinder/pkg/my_util"
"github.com/allanpk716/ChineseSubFinder/pkg/settings"
)

func UpdateInfo(version string, settings *settings.Settings) *models.Info {
var infos []models.Info
GetDb().Find(&infos)

mediaServerName := ""
if settings.EmbySettings.Enable == true {
mediaServerName = "Emby"
} else {
mediaServerName = "None"
}
if len(infos) == 0 {
// 不存在则新增
saveInfo := &models.Info{
Id: my_util.RandStringBytesMaskImprSrcSB(64),
MediaServer: mediaServerName,
Version: version,
EnableShare: settings.ExperimentalFunction.ShareSubSettings.ShareSubEnabled,
EnableApiKey: settings.ExperimentalFunction.ApiKeySettings.Enabled,
}
GetDb().Save(saveInfo)

return saveInfo
} else {
// 存在则更新
infos[0].Version = version
infos[0].MediaServer = mediaServerName
infos[0].EnableShare = settings.ExperimentalFunction.ShareSubSettings.ShareSubEnabled
infos[0].EnableApiKey = settings.ExperimentalFunction.ApiKeySettings.Enabled
GetDb().Save(&infos[0])
return &infos[0]
}
}
1 change: 1 addition & 0 deletions internal/dao/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func InitDb() error {
&models.ThirdPartSetVideoPlayedInfo{},
&models.MediaInfo{},
&models.LowVideoSubInfo{},
&models.Info{},
)
if err != nil {
return errors.New(fmt.Sprintf("db AutoMigrate error, %s", err.Error()))
Expand Down
12 changes: 12 additions & 0 deletions internal/models/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package models

import "gorm.io/gorm"

type Info struct {
gorm.Model
Id string // 当前设备的随机ID
Version string // 当前设备的版本
MediaServer string // 媒体服务的名称,没有使用则是 None
EnableShare bool // 是否开启了共享功能
EnableApiKey bool // 是否开启本地 http api 功能
}
13 changes: 13 additions & 0 deletions pkg/logic/cron_helper/cron_helper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cron_helper

import (
"github.com/allanpk716/ChineseSubFinder/internal/dao"
"github.com/allanpk716/ChineseSubFinder/pkg/global_value"
"github.com/allanpk716/ChineseSubFinder/pkg/logic/file_downloader"
"github.com/allanpk716/ChineseSubFinder/pkg/logic/scan_played_video_subinfo"

Expand Down Expand Up @@ -246,6 +248,17 @@ func (ch *CronHelper) Stop() {

func (ch *CronHelper) scanPlayedVideoSub() {

ch.log.Infoln("Update Info...")
nowInfo := dao.UpdateInfo(global_value.AppVersion(), ch.Settings)
_, err := ch.FileDownloader.SubtitleBestApi.FeedBack(
nowInfo.Id,
nowInfo.Version, nowInfo.MediaServer,
nowInfo.EnableShare, nowInfo.EnableApiKey)
if err != nil {
ch.log.Errorln("FeedBack Error:", err)
return
}

ch.log.Infoln("------------------------------------------------------")
ch.log.Infoln("scanPlayedVideoSub Start")
startT := time.Now()
Expand Down

0 comments on commit ec84c3b

Please sign in to comment.