A bunch of fixes
This commit is contained in:
1 parent
65534ecfd5
commit
2a4e03e611
20 files changed
+146
-160
No files matched your search
+17
-6
@@ -27,7 +27,6 @@ var (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load .env first (lowest priority; system env wins).
|
||||
if err := env.LoadEnvDefault(); err != nil {
|
||||
log.Printf("Warning: no .env file found: %v", err)
|
||||
}
|
||||
@@ -53,7 +52,7 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
db.SetMaxOpenConns(1) // SQLite does not support concurrent writes
|
||||
db.SetMaxOpenConns(1)
|
||||
|
||||
if _, err := db.Exec("PRAGMA foreign_keys = ON"); err != nil {
|
||||
appLog.Error("Failed to set PRAGMA foreign_keys: %v", err)
|
||||
@@ -154,7 +153,7 @@ func main() {
|
||||
|
||||
webSvc := web.New(userRepo, authRepo, views, db, jitsiCfg, trustedDomains, appLog)
|
||||
|
||||
// ── Start background session cleanup ──
|
||||
// -- Start background session cleanup --
|
||||
const defaultCleanupInterval = 5 * time.Minute
|
||||
go func() {
|
||||
cleanupInterval := defaultCleanupInterval
|
||||
@@ -186,6 +185,13 @@ func main() {
|
||||
} else if deleted > 0 {
|
||||
appLog.Info("cleaned up %d expired sessions", deleted)
|
||||
}
|
||||
|
||||
deleted, err = authRepo.DeleteExpiredInvites(ctx)
|
||||
if err != nil {
|
||||
appLog.Warn("invites cleanup failed: %v", err)
|
||||
} else if deleted > 0 {
|
||||
appLog.Info("cleaned up %d expired invites", deleted)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -199,7 +205,6 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// mustExec runs a DDL/DML statement and fatally logs on error.
|
||||
func mustExec(db *sql.DB, ddl string) {
|
||||
if _, err := db.Exec(ddl); err != nil {
|
||||
log.Fatalf("Migration failed: %v\nSQL: %s", err, ddl)
|
||||
@@ -218,9 +223,15 @@ func seed(ctx context.Context, userRepo *user.Repository, authRepo *auth.Reposit
|
||||
return
|
||||
}
|
||||
|
||||
password, err := auth.GenerateToken(16)
|
||||
if err != nil {
|
||||
appLog.Error("Failed to generate admin password: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
appLog.Info("Seeding: no users found, creating admin account and first invite")
|
||||
|
||||
hashed, err := auth.HashPassword("admin")
|
||||
hashed, err := auth.HashPassword(password)
|
||||
if err != nil {
|
||||
appLog.Error("Failed to hash admin password: %v", err)
|
||||
os.Exit(1)
|
||||
@@ -232,7 +243,7 @@ func seed(ctx context.Context, userRepo *user.Repository, authRepo *auth.Reposit
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
appLog.Info("Seeded admin user — id=%d login=admin password=admin", user.Id)
|
||||
appLog.Info("Seeded admin user — id=%d login=admin password=%s", user.Id, password)
|
||||
|
||||
// userRepo.СreateUser does not set superuser, so update it directly.
|
||||
if _, err := db.Exec("UPDATE users SET superuser = 1 WHERE id = ?", user.Id); err != nil {
|
||||
|
||||
Reference in new issue
Block a user