2021-10-25 18:53:59 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-10-27 22:45:36 +08:00
|
|
|
"github.com/Xhofe/alist/bootstrap"
|
2021-10-25 18:53:59 +08:00
|
|
|
"github.com/Xhofe/alist/conf"
|
2021-12-06 15:55:05 +08:00
|
|
|
_ "github.com/Xhofe/alist/drivers"
|
2021-11-16 15:00:56 +08:00
|
|
|
"github.com/Xhofe/alist/model"
|
2021-10-26 22:28:37 +08:00
|
|
|
"github.com/Xhofe/alist/server"
|
2021-11-13 15:53:26 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2021-10-25 18:53:59 +08:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2021-11-16 15:00:56 +08:00
|
|
|
func Init() bool {
|
2021-12-06 15:55:05 +08:00
|
|
|
//bootstrap.InitLog()
|
2021-10-27 22:45:36 +08:00
|
|
|
bootstrap.InitConf()
|
|
|
|
bootstrap.InitCron()
|
|
|
|
bootstrap.InitModel()
|
2021-11-16 15:00:56 +08:00
|
|
|
if conf.Password {
|
|
|
|
pass, err := model.GetSettingByKey("password")
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf(err.Error())
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
log.Infof("current password: %s", pass.Value)
|
|
|
|
return false
|
|
|
|
}
|
2021-12-21 00:32:09 +08:00
|
|
|
server.InitIndex()
|
2021-11-16 15:00:56 +08:00
|
|
|
bootstrap.InitSettings()
|
|
|
|
bootstrap.InitAccounts()
|
2021-10-27 22:45:36 +08:00
|
|
|
bootstrap.InitCache()
|
2021-11-16 15:00:56 +08:00
|
|
|
return true
|
2021-10-25 18:53:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2021-11-03 19:51:19 +08:00
|
|
|
if conf.Version {
|
2021-11-05 19:03:54 +08:00
|
|
|
fmt.Printf("Built At: %s\nGo Version: %s\nAuthor: %s\nCommit ID: %s\nVersion: %s\n", conf.BuiltAt, conf.GoVersion, conf.GitAuthor, conf.GitCommit, conf.GitTag)
|
2021-11-03 19:51:19 +08:00
|
|
|
return
|
|
|
|
}
|
2021-11-16 15:00:56 +08:00
|
|
|
if !Init() {
|
|
|
|
return
|
|
|
|
}
|
2021-11-13 15:53:26 +08:00
|
|
|
if !conf.Debug {
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
}
|
|
|
|
r := gin.Default()
|
|
|
|
server.InitApiRouter(r)
|
2021-11-26 20:20:32 +08:00
|
|
|
base := fmt.Sprintf("%s:%d", conf.Conf.Address, conf.Conf.Port)
|
2021-11-26 20:23:33 +08:00
|
|
|
log.Infof("start server @ %s", base)
|
2021-12-01 00:19:06 +08:00
|
|
|
var err error
|
2021-12-30 20:42:37 +08:00
|
|
|
if conf.Conf.Scheme.Https {
|
|
|
|
err = r.RunTLS(base, conf.Conf.Scheme.CertFile, conf.Conf.Scheme.KeyFile)
|
2021-12-01 00:19:06 +08:00
|
|
|
} else {
|
|
|
|
err = r.Run(base)
|
|
|
|
}
|
2021-10-30 19:26:23 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed to start: %s", err.Error())
|
|
|
|
}
|
2021-10-25 18:53:59 +08:00
|
|
|
}
|