fix(contorller): env corrections on where to look for the file when running

This commit is contained in:
2025-09-30 19:54:10 -05:00
parent 18e57127e2
commit b84ecbf30c
26 changed files with 2637 additions and 27 deletions

View File

@@ -3,13 +3,15 @@ module lst.net
go 1.24.3
require (
github.com/bwmarrin/discordgo v0.29.0
github.com/gin-gonic/gin v1.10.1
github.com/googollee/go-socket.io v1.7.0
github.com/jackc/pgx/v5 v5.7.6
github.com/joho/godotenv v1.5.1
github.com/robfig/cron/v3 v3.0.0
)
require (
github.com/bwmarrin/discordgo v0.29.0 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
@@ -29,7 +31,6 @@ require (
github.com/hirochachacha/go-smb2 v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.6 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
@@ -39,7 +40,6 @@ require (
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/prometheus-community/pro-bing v0.7.0 // indirect
github.com/robfig/cron v1.2.0 // indirect
github.com/robfig/cron/v3 v3.0.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.8.0 // indirect

View File

@@ -180,22 +180,22 @@
{
name: "Houston",
server: "USHOU1VMS006",
location: "E$\\LST\\LST",
location: "E$\\LST",
},
{
name: "Sherman",
server: "USSHE1VMS006",
location: "E$\\LST\\LST",
location: "E$\\LST",
},
{
name: "West Bend",
server: "USWEB1VMS006",
location: "E$\\LST\\LST",
location: "E$\\LST",
},
{
name: "Jerfferson City",
server: "USJCI1VMS006",
location: "E$\\LST\\LST",
location: "E$\\LST",
},
];
@@ -324,9 +324,7 @@
});
logMessage(
"info",
`Copying to ${
srv.name
} (drive ${srv.drive.toUpperCase()})`
`Copying to ${srv.name} (location ${srv.location})`
);
});
@@ -364,15 +362,13 @@
currentServer = copyQueue.shift();
logMessage(
"info",
`🚀 Copying to ${
currentServer.name
} (drive ${currentServer.drive.toUpperCase()})`
`Copying to ${currentServer.name} (location ${currentServer.location})`
);
socket.emit("update", {
action: "copy",
target: currentServer.name,
drive: currentServer.drive,
target: currentServer.server,
location: currentServer.location,
});
}
@@ -381,7 +377,8 @@
// Only check queue progress if we're in All mode and have a currentServer
if (isRunningAll && currentServer) {
const expected = `✅ Copy to ${currentServer.name} successful`;
//const expected = `✅ Copy to ${currentServer.name} successful`;
const expected = "done";
if (msg.includes(expected)) {
logMessage(

45
controller/load_env.go Normal file
View File

@@ -0,0 +1,45 @@
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/joho/godotenv"
)
func loadEnv() {
exePath, _ := os.Executable()
exeDir := filepath.Dir(exePath)
// Normalize both to lowercase absolute paths for Windows safety
exePathLower := strings.ToLower(exePath)
tempDirLower := strings.ToLower(filepath.Clean(os.TempDir()))
// Heuristic: if exe lives *inside* the system temp dir → assume go run
if strings.HasPrefix(exePathLower, tempDirLower) {
fmt.Println("Detected go run loading ../.env")
err := godotenv.Load("../.env")
if err != nil {
fmt.Println("ERROR loading .env:", err)
} else {
fmt.Println(".env successfully loaded")
}
return
}
// Otherwise → normal compiled exe
fmt.Println("Detected compiled exe loading exeDir/.env")
if err := godotenv.Load(filepath.Join(exeDir, ".env")); err != nil {
fmt.Println("Didn't find exeDir/.env trying ../.env as fallback")
err := godotenv.Load("../.env")
if err != nil {
fmt.Println("ERROR loading .env:", err)
} else {
fmt.Println(".env successfully loaded")
}
}
}

View File

@@ -5,26 +5,18 @@ import (
"log"
"net/http"
"os"
"path/filepath"
"strings"
"time"
"github.com/gin-gonic/gin"
socketio "github.com/googollee/go-socket.io"
"github.com/joho/godotenv"
"lst.net/internal/bot"
"lst.net/pkg"
)
func main() {
exePath, _ := os.Executable()
exeDir := filepath.Dir(exePath)
if err := godotenv.Load(filepath.Join(exeDir, ".env")); err != nil {
// fallback dev path
_ = godotenv.Load("../.env")
}
loadEnv()
// gin stuff
basePath := "/api/controller"