diff --git a/internal/db/pg.go b/internal/db/pg.go index 5ad953720..df01132c2 100644 --- a/internal/db/pg.go +++ b/internal/db/pg.go @@ -37,6 +37,7 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db/model" + "github.com/superseriousbusiness/gotosocial/internal/util" "github.com/superseriousbusiness/gotosocial/pkg/mastotypes" "golang.org/x/crypto/bcrypt" ) @@ -104,14 +105,18 @@ func newPostgresService(ctx context.Context, c *config.Config, log *logrus.Entry return nil, errors.New("db connection timeout") } + ps := &postgresService{ + config: c, + conn: conn, + log: log, + cancel: cancel, + } + + federatingDB := newFederatingDB(ps, c) + ps.federationDB = federatingDB + // we can confidently return this useable postgres service now - return &postgresService{ - config: c, - conn: conn, - log: log, - cancel: cancel, - federationDB: newPostgresFederation(conn), - }, nil + return ps, nil } /* @@ -437,17 +442,21 @@ func (ps *postgresService) NewSignup(username string, reason string, requireAppr return nil, err } - // should be something like https://example.org/@some_username - url := fmt.Sprintf("%s://%s/@%s", ps.config.Protocol, ps.config.Host, username) + uris := util.GenerateURIs(username, ps.config.Protocol, ps.config.Host) a := &model.Account{ - Username: username, - DisplayName: username, - Reason: reason, - URL: url, - PrivateKey: key, - PublicKey: &key.PublicKey, - ActorType: "Person", + Username: username, + DisplayName: username, + Reason: reason, + URL: uris.UserURL, + PrivateKey: key, + PublicKey: &key.PublicKey, + ActorType: "Person", + URI: uris.UserURI, + InboxURL: uris.InboxURL, + OutboxURL: uris.OutboxURL, + FollowersURL: uris.FollowersURL, + FeaturedCollectionURL: uris.CollectionURL, } if _, err = ps.conn.Model(a).Insert(); err != nil { return nil, err diff --git a/internal/util/parse.go b/internal/util/parse.go new file mode 100644 index 000000000..375ab97f2 --- /dev/null +++ b/internal/util/parse.go @@ -0,0 +1,32 @@ +package util + +import "fmt" + +type URIs struct { + HostURL string + UserURL string + UserURI string + InboxURL string + OutboxURL string + FollowersURL string + CollectionURL string +} + +func GenerateURIs(username string, protocol string, host string) *URIs { + hostURL := fmt.Sprintf("%s://%s", protocol, host) + userURL := fmt.Sprintf("%s/@%s", hostURL, username) + userURI := fmt.Sprintf("%s/users/%s", hostURL, username) + inboxURL := fmt.Sprintf("%s/inbox", userURI) + outboxURL := fmt.Sprintf("%s/outbox", userURI) + followersURL := fmt.Sprintf("%s/followers", userURI) + collectionURL := fmt.Sprintf("%s/collections/featured", userURI) + return &URIs{ + HostURL: hostURL, + UserURL: userURL, + UserURI: userURI, + InboxURL: inboxURL, + OutboxURL: outboxURL, + FollowersURL: followersURL, + CollectionURL: collectionURL, + } +}