🚧 添加model
This commit is contained in:
@@ -61,6 +61,10 @@ func start() {
|
||||
log.Errorf("初始化阿里云盘出现错误,启动失败.")
|
||||
return
|
||||
}
|
||||
if !InitModel() {
|
||||
log.Errorf("初始化数据库出现错误,启动失败.")
|
||||
return
|
||||
}
|
||||
InitCache()
|
||||
InitCron()
|
||||
server()
|
||||
|
37
bootstrap/model.go
Normal file
37
bootstrap/model.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"github.com/Xhofe/alist/conf"
|
||||
"github.com/Xhofe/alist/server/models"
|
||||
"github.com/Xhofe/alist/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func InitModel() bool {
|
||||
log.Infof("初始化数据库...")
|
||||
switch conf.Conf.Database.Type {
|
||||
case "sqlite3":{
|
||||
needMigrate := !utils.Exists(conf.Conf.Database.DBFile)
|
||||
db, err := gorm.Open(sqlite.Open(conf.Conf.Database.DBFile), &gorm.Config{})
|
||||
if err!=nil {
|
||||
log.Errorf("连接数据库出现错误:%s", err.Error())
|
||||
return false
|
||||
}
|
||||
conf.DB = db
|
||||
if needMigrate {
|
||||
log.Infof("迁移数据库...")
|
||||
err = conf.DB.AutoMigrate(&models.File{})
|
||||
if err !=nil {
|
||||
log.Errorf("数据库迁移失败:%s",err.Error())
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
default:
|
||||
log.Errorf("不支持的数据库类型:%s", conf.Conf.Database.Type)
|
||||
return false
|
||||
}
|
||||
}
|
@@ -16,7 +16,7 @@ type GithubRelease struct {
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
// check updtae
|
||||
// check update
|
||||
func CheckUpdate() {
|
||||
log.Infof("检查更新...")
|
||||
url:="https://api.github.com/repos/Xhofe/alist/releases/latest"
|
||||
|
Reference in New Issue
Block a user