mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 03:32:25 -05:00 
			
		
		
		
	add a lil helper for generating user uris
This commit is contained in:
		
					parent
					
						
							
								f5224ad3a7
							
						
					
				
			
			
				commit
				
					
						dba33c2c5c
					
				
			
		
					 2 changed files with 57 additions and 16 deletions
				
			
		|  | @ -37,6 +37,7 @@ import ( | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| 	"github.com/superseriousbusiness/gotosocial/internal/config" | 	"github.com/superseriousbusiness/gotosocial/internal/config" | ||||||
| 	"github.com/superseriousbusiness/gotosocial/internal/db/model" | 	"github.com/superseriousbusiness/gotosocial/internal/db/model" | ||||||
|  | 	"github.com/superseriousbusiness/gotosocial/internal/util" | ||||||
| 	"github.com/superseriousbusiness/gotosocial/pkg/mastotypes" | 	"github.com/superseriousbusiness/gotosocial/pkg/mastotypes" | ||||||
| 	"golang.org/x/crypto/bcrypt" | 	"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") | 		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 | 	// we can confidently return this useable postgres service now | ||||||
| 	return &postgresService{ | 	return ps, nil | ||||||
| 		config:       c, |  | ||||||
| 		conn:         conn, |  | ||||||
| 		log:          log, |  | ||||||
| 		cancel:       cancel, |  | ||||||
| 		federationDB: newPostgresFederation(conn), |  | ||||||
| 	}, nil |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* | /* | ||||||
|  | @ -437,17 +442,21 @@ func (ps *postgresService) NewSignup(username string, reason string, requireAppr | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// should be something like https://example.org/@some_username | 	uris := util.GenerateURIs(username, ps.config.Protocol, ps.config.Host) | ||||||
| 	url := fmt.Sprintf("%s://%s/@%s", ps.config.Protocol, ps.config.Host, username) |  | ||||||
| 
 | 
 | ||||||
| 	a := &model.Account{ | 	a := &model.Account{ | ||||||
| 		Username:    username, | 		Username:              username, | ||||||
| 		DisplayName: username, | 		DisplayName:           username, | ||||||
| 		Reason:      reason, | 		Reason:                reason, | ||||||
| 		URL:         url, | 		URL:                   uris.UserURL, | ||||||
| 		PrivateKey:  key, | 		PrivateKey:            key, | ||||||
| 		PublicKey:   &key.PublicKey, | 		PublicKey:             &key.PublicKey, | ||||||
| 		ActorType:   "Person", | 		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 { | 	if _, err = ps.conn.Model(a).Insert(); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
|  |  | ||||||
							
								
								
									
										32
									
								
								internal/util/parse.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								internal/util/parse.go
									
										
									
									
									
										Normal file
									
								
							|  | @ -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, | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue