mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-22 09:04:21 +01:00
added more sanity checks + restructured code a bit
This commit is contained in:
39
src/main.go
39
src/main.go
@@ -73,8 +73,45 @@ func main() {
|
||||
log.Fatal("Couldn't set env variable: ", err.Error())
|
||||
}
|
||||
|
||||
useNative := utils.GetEnv("USE_NATIVE", "")
|
||||
if useNative != "" {
|
||||
log.Warning("The env variable USE_NATIVE is deprecated. Please use the env variable MODE instead")
|
||||
}
|
||||
|
||||
signalCliMode := client.Normal
|
||||
mode := utils.GetEnv("MODE", "normal")
|
||||
if mode == "normal" {
|
||||
signalCliMode = client.Normal
|
||||
} else if mode == "json-rpc" {
|
||||
signalCliMode = client.JsonRpc
|
||||
} else if mode == "native" {
|
||||
signalCliMode = client.Native
|
||||
}
|
||||
|
||||
if useNative != "" {
|
||||
_, modeEnvVariableSet := os.LookupEnv("MODE")
|
||||
if modeEnvVariableSet {
|
||||
log.Fatal("You have both the USE_NATIVE and the MODE env variable set. Please remove the deprecated env variable USE_NATIVE!")
|
||||
}
|
||||
}
|
||||
|
||||
if useNative == "1" || signalCliMode == client.Native {
|
||||
if supportsSignalCliNative == "0" {
|
||||
log.Error("signal-cli-native is not support on this system...falling back to signal-cli")
|
||||
signalCliMode = client.Normal
|
||||
}
|
||||
}
|
||||
|
||||
if signalCliMode == client.JsonRpc {
|
||||
_, autoReceiveScheduleEnvVariableSet := os.LookupEnv("AUTO_RECEIVE_SCHEDULE")
|
||||
if autoReceiveScheduleEnvVariableSet {
|
||||
log.Fatal("Env variable AUTO_RECEIVE_SCHEDULE can't be used with mode json-rpc")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
jsonRpc2ClientConfigPathPath := *signalCliConfig + "/jsonrpc2.yml"
|
||||
signalClient := client.NewSignalClient(*signalCliConfig, *attachmentTmpDir, *avatarTmpDir, client.JsonRpc, jsonRpc2ClientConfigPathPath)
|
||||
signalClient := client.NewSignalClient(*signalCliConfig, *attachmentTmpDir, *avatarTmpDir, signalCliMode, jsonRpc2ClientConfigPathPath)
|
||||
err = signalClient.Init()
|
||||
if err != nil {
|
||||
log.Fatal("Couldn't init Signal Client: ", err.Error())
|
||||
|
||||
Reference in New Issue
Block a user