♻️ Container 常量化

This commit is contained in:
Liang Ding 2022-08-31 12:25:55 +08:00
parent 379e27aefe
commit 7f9c598061
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
7 changed files with 17 additions and 10 deletions

View file

@ -82,7 +82,7 @@ func html2BlockDOM(c *gin.Context) {
n.Unlink()
}
if "std" == model.Conf.System.Container {
if util.ContainerStd == model.Conf.System.Container {
// 处理本地资源文件复制
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || ast.NodeLinkDest != n.Type {

View file

@ -31,7 +31,7 @@ import (
var assetsWatcher *fsnotify.Watcher
func WatchAssets() {
if "android" == util.Container || "ios" == util.Container {
if util.ContainerAndroid == util.Container || util.ContainerIOS == util.Container {
return
}

View file

@ -70,7 +70,7 @@ func Serve(fastMode bool) {
api.ServeAPI(ginServer)
var addr string
if model.Conf.System.NetworkServe || "docker" == util.Container {
if model.Conf.System.NetworkServe || util.ContainerDocker == util.Container {
addr = "0.0.0.0:" + util.ServerPort
} else {
addr = "127.0.0.1:" + util.ServerPort
@ -227,7 +227,7 @@ func serveDebug(ginServer *gin.Engine) {
func serveWebSocket(ginServer *gin.Engine) {
util.WebSocketServer.Config.MaxMessageSize = 1024 * 1024 * 8
if "docker" == util.Container { // Docker 容器运行时启用 WebSocket 传输压缩
if util.ContainerDocker == util.Container { // Docker 容器运行时启用 WebSocket 传输压缩
util.WebSocketServer.Config.EnableCompression = true
util.WebSocketServer.Config.CompressionLevel = 4
}

View file

@ -125,7 +125,7 @@ func queryBlockIDByParentID(parentID string) (ret []string) {
func QueryRecentUpdatedBlocks() (ret []*Block) {
sqlStmt := "SELECT * FROM blocks WHERE type = 'p' AND length > 1 ORDER BY updated DESC LIMIT 16"
if "ios" == util.Container || "android" == util.Container {
if util.ContainerIOS == util.Container || util.ContainerAndroid == util.Container {
sqlStmt = "SELECT * FROM blocks WHERE type = 'd' ORDER BY updated DESC LIMIT 16"
}
rows, err := query(sqlStmt)

View file

@ -87,7 +87,7 @@ func IsIDPattern(str string) bool {
var LocalIPs []string
func GetLocalIPs() (ret []string) {
if "android" == Container {
if ContainerAndroid == Container {
// Android 上用不了 net.InterfaceAddrs() https://github.com/golang/go/issues/40569所以前面使用启动内核传入的参数 localIPs
LocalIPs = append(LocalIPs, "127.0.0.1")
LocalIPs = gulu.Str.RemoveDuplicatedElem(LocalIPs)

View file

@ -67,7 +67,7 @@ func RandomSleep(minMills, maxMills int) {
}
func GetDeviceID() string {
if "std" == Container {
if ContainerStd == Container {
machineID, err := machineid.ID()
if nil != err {
return gulu.Rand.String(12)

View file

@ -77,9 +77,9 @@ func Boot() {
Resident = *resident
ReadOnly = *readOnly
AccessAuthCode = *accessAuthCode
Container = "std"
Container = ContainerStd
if isRunningInDockerContainer() {
Container = "docker"
Container = ContainerDocker
}
UserAgent = UserAgent + " " + Container
@ -177,7 +177,7 @@ func initWorkspaceDir(workspaceArg string) {
userHomeConfDir := filepath.Join(HomeDir, ".config", "siyuan")
workspaceConf := filepath.Join(userHomeConfDir, "workspace.json")
if !gulu.File.IsExist(workspaceConf) {
IsNewbie = "std" == Container // 只有桌面端需要设置新手标识,前端自动挂载帮助文档
IsNewbie = ContainerStd == Container // 只有桌面端需要设置新手标识,前端自动挂载帮助文档
if err := os.MkdirAll(userHomeConfDir, 0755); nil != err && !os.IsExist(err) {
log.Printf("create user home conf folder [%s] failed: %s", userHomeConfDir, err)
os.Exit(ExitCodeCreateConfDirErr)
@ -276,6 +276,13 @@ var (
Container string // docker, android, ios, std
)
const (
ContainerStd = "std" // 桌面端
ContainerDocker = "docker" // Docker 容器端
ContainerAndroid = "android" // Android 端
ContainerIOS = "ios" // iOS 端
)
func initPathDir() {
if err := os.MkdirAll(ConfDir, 0755); nil != err && !os.IsExist(err) {
log.Fatalf("create conf folder [%s] failed: %s", ConfDir, err)