summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gotosocial/action/admin/account/account.go49
-rw-r--r--cmd/gotosocial/action/admin/media/prune/orphaned.go8
-rw-r--r--cmd/gotosocial/action/admin/trans/export.go8
-rw-r--r--cmd/gotosocial/action/admin/trans/import.go8
-rw-r--r--cmd/gotosocial/action/server/server.go12
5 files changed, 74 insertions, 11 deletions
diff --git a/cmd/gotosocial/action/admin/account/account.go b/cmd/gotosocial/action/admin/account/account.go
index 35c2f68ab..5cde9bdf3 100644
--- a/cmd/gotosocial/action/admin/account/account.go
+++ b/cmd/gotosocial/action/admin/account/account.go
@@ -27,17 +27,24 @@ import (
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
+ "github.com/superseriousbusiness/gotosocial/internal/state"
"github.com/superseriousbusiness/gotosocial/internal/validate"
"golang.org/x/crypto/bcrypt"
)
// Create creates a new account in the database using the provided flags.
var Create action.GTSAction = func(ctx context.Context) error {
- dbConn, err := bundb.NewBunDBService(ctx)
+ var state state.State
+ state.Caches.Init()
+
+ dbConn, err := bundb.NewBunDBService(ctx, &state)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
+ // Set the state DB connection
+ state.DB = dbConn
+
username := config.GetAdminAccountUsername()
if username == "" {
return errors.New("no username set")
@@ -88,11 +95,17 @@ var Create action.GTSAction = func(ctx context.Context) error {
// Confirm sets a user to Approved, sets Email to the current UnconfirmedEmail value, and sets ConfirmedAt to now.
var Confirm action.GTSAction = func(ctx context.Context) error {
- dbConn, err := bundb.NewBunDBService(ctx)
+ var state state.State
+ state.Caches.Init()
+
+ dbConn, err := bundb.NewBunDBService(ctx, &state)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
+ // Set the state DB connection
+ state.DB = dbConn
+
username := config.GetAdminAccountUsername()
if username == "" {
return errors.New("no username set")
@@ -125,11 +138,17 @@ var Confirm action.GTSAction = func(ctx context.Context) error {
// Promote sets a user to admin.
var Promote action.GTSAction = func(ctx context.Context) error {
- dbConn, err := bundb.NewBunDBService(ctx)
+ var state state.State
+ state.Caches.Init()
+
+ dbConn, err := bundb.NewBunDBService(ctx, &state)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
+ // Set the state DB connection
+ state.DB = dbConn
+
username := config.GetAdminAccountUsername()
if username == "" {
return errors.New("no username set")
@@ -159,11 +178,17 @@ var Promote action.GTSAction = func(ctx context.Context) error {
// Demote sets admin on a user to false.
var Demote action.GTSAction = func(ctx context.Context) error {
- dbConn, err := bundb.NewBunDBService(ctx)
+ var state state.State
+ state.Caches.Init()
+
+ dbConn, err := bundb.NewBunDBService(ctx, &state)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
+ // Set the state DB connection
+ state.DB = dbConn
+
username := config.GetAdminAccountUsername()
if username == "" {
return errors.New("no username set")
@@ -193,11 +218,17 @@ var Demote action.GTSAction = func(ctx context.Context) error {
// Disable sets Disabled to true on a user.
var Disable action.GTSAction = func(ctx context.Context) error {
- dbConn, err := bundb.NewBunDBService(ctx)
+ var state state.State
+ state.Caches.Init()
+
+ dbConn, err := bundb.NewBunDBService(ctx, &state)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
+ // Set the state DB connection
+ state.DB = dbConn
+
username := config.GetAdminAccountUsername()
if username == "" {
return errors.New("no username set")
@@ -227,11 +258,17 @@ var Disable action.GTSAction = func(ctx context.Context) error {
// Password sets the password of target account.
var Password action.GTSAction = func(ctx context.Context) error {
- dbConn, err := bundb.NewBunDBService(ctx)
+ var state state.State
+ state.Caches.Init()
+
+ dbConn, err := bundb.NewBunDBService(ctx, &state)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
+ // Set the state DB connection
+ state.DB = dbConn
+
username := config.GetAdminAccountUsername()
if username == "" {
return errors.New("no username set")
diff --git a/cmd/gotosocial/action/admin/media/prune/orphaned.go b/cmd/gotosocial/action/admin/media/prune/orphaned.go
index 4ceb356bd..ede00dca2 100644
--- a/cmd/gotosocial/action/admin/media/prune/orphaned.go
+++ b/cmd/gotosocial/action/admin/media/prune/orphaned.go
@@ -27,12 +27,16 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/media"
+ "github.com/superseriousbusiness/gotosocial/internal/state"
gtsstorage "github.com/superseriousbusiness/gotosocial/internal/storage"
)
// Orphaned prunes orphaned media from storage.
var Orphaned action.GTSAction = func(ctx context.Context) error {
- dbService, err := bundb.NewBunDBService(ctx)
+ var state state.State
+ state.Caches.Init()
+
+ dbService, err := bundb.NewBunDBService(ctx, &state)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
@@ -54,7 +58,7 @@ var Orphaned action.GTSAction = func(ctx context.Context) error {
return fmt.Errorf("error pruning: %s", err)
}
- if dry {
+ if dry /* dick heyyoooooo */ {
log.Infof("DRY RUN: %d stored items are orphaned and eligible to be pruned", pruned)
} else {
log.Infof("%d stored items were orphaned and pruned", pruned)
diff --git a/cmd/gotosocial/action/admin/trans/export.go b/cmd/gotosocial/action/admin/trans/export.go
index 2b5f82ee8..aa2cc9c26 100644
--- a/cmd/gotosocial/action/admin/trans/export.go
+++ b/cmd/gotosocial/action/admin/trans/export.go
@@ -26,16 +26,22 @@ import (
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
+ "github.com/superseriousbusiness/gotosocial/internal/state"
"github.com/superseriousbusiness/gotosocial/internal/trans"
)
// Export exports info from the database into a file
var Export action.GTSAction = func(ctx context.Context) error {
- dbConn, err := bundb.NewBunDBService(ctx)
+ var state state.State
+
+ dbConn, err := bundb.NewBunDBService(ctx, &state)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
+ // Set the state DB connection
+ state.DB = dbConn
+
exporter := trans.NewExporter(dbConn)
path := config.GetAdminTransPath()
diff --git a/cmd/gotosocial/action/admin/trans/import.go b/cmd/gotosocial/action/admin/trans/import.go
index 75f2d6a5e..7d27f79a1 100644
--- a/cmd/gotosocial/action/admin/trans/import.go
+++ b/cmd/gotosocial/action/admin/trans/import.go
@@ -26,16 +26,22 @@ import (
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
+ "github.com/superseriousbusiness/gotosocial/internal/state"
"github.com/superseriousbusiness/gotosocial/internal/trans"
)
// Import imports info from a file into the database
var Import action.GTSAction = func(ctx context.Context) error {
- dbConn, err := bundb.NewBunDBService(ctx)
+ var state state.State
+
+ dbConn, err := bundb.NewBunDBService(ctx, &state)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
+ // Set the state DB connection
+ state.DB = dbConn
+
importer := trans.NewImporter(dbConn)
path := config.GetAdminTransPath()
diff --git a/cmd/gotosocial/action/server/server.go b/cmd/gotosocial/action/server/server.go
index 3da9e997c..9fb916850 100644
--- a/cmd/gotosocial/action/server/server.go
+++ b/cmd/gotosocial/action/server/server.go
@@ -65,6 +65,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oidc"
"github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
+ "github.com/superseriousbusiness/gotosocial/internal/state"
gtsstorage "github.com/superseriousbusiness/gotosocial/internal/storage"
"github.com/superseriousbusiness/gotosocial/internal/transport"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
@@ -73,11 +74,20 @@ import (
// Start creates and starts a gotosocial server
var Start action.GTSAction = func(ctx context.Context) error {
- dbService, err := bundb.NewBunDBService(ctx)
+ var state state.State
+
+ // Initialize caches
+ state.Caches.Init()
+
+ // Open connection to the database
+ dbService, err := bundb.NewBunDBService(ctx, &state)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
+ // Set the state DB connection
+ state.DB = dbService
+
if err := dbService.CreateInstanceAccount(ctx); err != nil {
return fmt.Errorf("error creating instance account: %s", err)
}