mirror of
https://github.com/khairul169/vaulterm.git
synced 2026-09-15 17:03:30 +07:00
fix: macos fix can't open the app
This commit is contained in:
+22
-3
@@ -3,13 +3,32 @@ package utils
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"rul.sh/vaulterm/server/lib"
|
||||
)
|
||||
|
||||
func GetDataPath(resolveFile string) string {
|
||||
// Resolve the app directory
|
||||
execPath, err := os.Executable()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
appDir := filepath.Dir(execPath)
|
||||
if resolveFile == "" {
|
||||
return appDir
|
||||
}
|
||||
return filepath.Join(appDir, resolveFile)
|
||||
}
|
||||
|
||||
func CheckAndCreateEnvFile() error {
|
||||
// Skip if ENCRYPTION_KEY is set
|
||||
if os.Getenv("ENCRYPTION_KEY") != "" {
|
||||
return nil
|
||||
}
|
||||
// Check if .env file exists
|
||||
if _, err := os.Stat(".env"); !os.IsNotExist(err) {
|
||||
envFile := GetDataPath(".env")
|
||||
if _, err := os.Stat(envFile); !os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -21,11 +40,11 @@ func CheckAndCreateEnvFile() error {
|
||||
|
||||
// Write the random key to the .env file
|
||||
envContent := fmt.Sprintf("ENCRYPTION_KEY=%s\n", randomKey)
|
||||
err = os.WriteFile(".env", []byte(envContent), 0644)
|
||||
err = os.WriteFile(envFile, []byte(envContent), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(".env file created with ENCRYPTION_KEY.")
|
||||
|
||||
fmt.Println(".env file created with ENCRYPTION_KEY.")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user