dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit ef1b9800962249945c20a8f3842ce728a381aa90
parent 91f8196fc38b03c7861f2d4c5bafdf771cdc3411
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu,  9 Mar 2023 23:32:47 -0800

cleanup

Diffstat:
Mpkg/actions/actions.go | 8++++++--
Mpkg/database/database.go | 3+--
2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/pkg/actions/actions.go b/pkg/actions/actions.go @@ -47,7 +47,8 @@ func Start(c *cli.Context) error { ensureProjectHome() - db := database.NewDkfDB() + dbPath := filepath.Join(config.Global.ProjectPath(), config.DbFileName) + db := database.NewDkfDB(dbPath) runMigrations(db) @@ -270,6 +271,9 @@ func BuildProhibitedPasswords(c *cli.Context) error { ensureProjectHome() + dbPath := filepath.Join(config.Global.ProjectPath(), config.DbFileName) + db := database.NewDkfDB(dbPath).DB() + readFile, _ := os.Open("rockyou.txt") fileScanner := bufio.NewScanner(readFile) fileScanner.Split(bufio.ScanLines) @@ -278,7 +282,7 @@ func BuildProhibitedPasswords(c *cli.Context) error { rows = append(rows, database.ProhibitedPassword{Password: fileScanner.Text()}) } readFile.Close() - if err := gormbulk.BulkInsert(database.NewDkfDB().DB(), rows, 10000); err != nil { + if err := gormbulk.BulkInsert(db, rows, 10000); err != nil { logrus.Error(err) } return nil diff --git a/pkg/database/database.go b/pkg/database/database.go @@ -221,8 +221,7 @@ type IDkfDB interface { WhitelistUser(roomID RoomID, userID UserID) (out ChatRoomWhitelistedUser, err error) } -func NewDkfDB() *DkfDB { - dbPath := filepath.Join(config.Global.ProjectPath(), config.DbFileName) +func NewDkfDB(dbPath string) *DkfDB { db, err := gorm.Open("sqlite3", dbPath) if err != nil { logrus.Fatal("Failed to open sqlite3 db : " + err.Error())