-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: allan716 <525223688@qq.com>
- Loading branch information
1 parent
91b599c
commit ec84c3b
Showing
5 changed files
with
71 additions
and
0 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
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] | ||
} | ||
} |
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,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 功能 | ||
} |
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