Jelajahi Sumber

[server] Pick base publicHost url from config (#1443)

## Description

## Tests
Ran locally with the config in local.yaml and verified that it's
modified as well when I had put localhost:3002 in the museum.yaml config
Neeraj Gupta 1 tahun lalu
induk
melakukan
8ed2c7cff9

+ 1 - 1
server/cmd/museum/main.go

@@ -163,7 +163,7 @@ func main() {
 		ObjectCopiesRepo: objectCopiesRepo, UsageRepo: usageRepo}
 		ObjectCopiesRepo: objectCopiesRepo, UsageRepo: usageRepo}
 	familyRepo := &repo.FamilyRepository{DB: db}
 	familyRepo := &repo.FamilyRepository{DB: db}
 	trashRepo := &repo.TrashRepository{DB: db, ObjectRepo: objectRepo, FileRepo: fileRepo, QueueRepo: queueRepo}
 	trashRepo := &repo.TrashRepository{DB: db, ObjectRepo: objectRepo, FileRepo: fileRepo, QueueRepo: queueRepo}
-	publicCollectionRepo := &repo.PublicCollectionRepository{DB: db}
+	publicCollectionRepo := repo.NewPublicCollectionRepository(db, viper.GetString("apps.public-albums"))
 	collectionRepo := &repo.CollectionRepository{DB: db, FileRepo: fileRepo, PublicCollectionRepo: publicCollectionRepo,
 	collectionRepo := &repo.CollectionRepository{DB: db, FileRepo: fileRepo, PublicCollectionRepo: publicCollectionRepo,
 		TrashRepo: trashRepo, SecretEncryptionKey: secretEncryptionKeyBytes, QueueRepo: queueRepo, LatencyLogger: latencyLogger}
 		TrashRepo: trashRepo, SecretEncryptionKey: secretEncryptionKeyBytes, QueueRepo: queueRepo, LatencyLogger: latencyLogger}
 	pushRepo := &repo.PushTokenRepository{DB: db}
 	pushRepo := &repo.PushTokenRepository{DB: db}

+ 5 - 0
server/configurations/local.yaml

@@ -71,6 +71,11 @@ http:
     # By default, this is false, and museum will bind to 8080 without TLS.
     # By default, this is false, and museum will bind to 8080 without TLS.
     # use-tls: true
     # use-tls: true
 
 
+# Specify the base endpoints for various apps
+apps:
+    public-albums: "https://albums.ente.io"
+
+
 # Database connection parameters
 # Database connection parameters
 db:
 db:
     host: localhost
     host: localhost

+ 2 - 2
server/pkg/controller/public_collection.go

@@ -80,7 +80,7 @@ func (c *PublicCollectionController) CreateAccessToken(ctx context.Context, req
 		}
 		}
 	}
 	}
 	response := ente.PublicURL{
 	response := ente.PublicURL{
-		URL:             fmt.Sprintf(repo.BaseShareURL, accessToken),
+		URL:             c.PublicCollectionRepo.GetAlbumUrl(accessToken),
 		ValidTill:       req.ValidTill,
 		ValidTill:       req.ValidTill,
 		DeviceLimit:     req.DeviceLimit,
 		DeviceLimit:     req.DeviceLimit,
 		EnableDownload:  true,
 		EnableDownload:  true,
@@ -151,7 +151,7 @@ func (c *PublicCollectionController) UpdateSharedUrl(ctx context.Context, req en
 		return ente.PublicURL{}, stacktrace.Propagate(err, "")
 		return ente.PublicURL{}, stacktrace.Propagate(err, "")
 	}
 	}
 	return ente.PublicURL{
 	return ente.PublicURL{
-		URL:             fmt.Sprintf(repo.BaseShareURL, publicCollectionToken.Token),
+		URL:             c.PublicCollectionRepo.GetAlbumUrl(publicCollectionToken.Token),
 		DeviceLimit:     publicCollectionToken.DeviceLimit,
 		DeviceLimit:     publicCollectionToken.DeviceLimit,
 		ValidTill:       publicCollectionToken.ValidTill,
 		ValidTill:       publicCollectionToken.ValidTill,
 		EnableDownload:  publicCollectionToken.EnableDownload,
 		EnableDownload:  publicCollectionToken.EnableDownload,

+ 1 - 1
server/pkg/repo/collection.go

@@ -216,7 +216,7 @@ pct.access_token, pct.valid_till, pct.device_limit, pct.created_at, pct.updated_
 			if _, ok := addPublicUrlMap[pctToken.String]; !ok {
 			if _, ok := addPublicUrlMap[pctToken.String]; !ok {
 				addPublicUrlMap[pctToken.String] = true
 				addPublicUrlMap[pctToken.String] = true
 				url := ente.PublicURL{
 				url := ente.PublicURL{
-					URL:             fmt.Sprintf(BaseShareURL, pctToken.String),
+					URL:             repo.PublicCollectionRepo.GetAlbumUrl(pctToken.String),
 					DeviceLimit:     int(pctDeviceLimit.Int32),
 					DeviceLimit:     int(pctDeviceLimit.Int32),
 					ValidTill:       pctValidTill.Int64,
 					ValidTill:       pctValidTill.Int64,
 					EnableDownload:  pctEnableDownload.Bool,
 					EnableDownload:  pctEnableDownload.Bool,

+ 18 - 2
server/pkg/repo/public_collection.go

@@ -16,7 +16,23 @@ const BaseShareURL = "https://albums.ente.io?t=%s"
 // PublicCollectionRepository defines the methods for inserting, updating and
 // PublicCollectionRepository defines the methods for inserting, updating and
 // retrieving entities related to public collections
 // retrieving entities related to public collections
 type PublicCollectionRepository struct {
 type PublicCollectionRepository struct {
-	DB *sql.DB
+	DB        *sql.DB
+	albumHost string
+}
+
+// NewPublicCollectionRepository ..
+func NewPublicCollectionRepository(db *sql.DB, albumHost string) *PublicCollectionRepository {
+	if albumHost == "" {
+		panic("albumHost can not be empty")
+	}
+	return &PublicCollectionRepository{
+		DB:        db,
+		albumHost: albumHost,
+	}
+}
+
+func (pcr *PublicCollectionRepository) GetAlbumUrl(token string) string {
+	return fmt.Sprintf("%s?t=%s", pcr.albumHost, token)
 }
 }
 
 
 func (pcr *PublicCollectionRepository) Insert(ctx context.Context,
 func (pcr *PublicCollectionRepository) Insert(ctx context.Context,
@@ -59,7 +75,7 @@ func (pcr *PublicCollectionRepository) GetCollectionToActivePublicURLMap(ctx con
 		if err = rows.Scan(&collectionID, &accessToken, &publicUrl.ValidTill, &publicUrl.DeviceLimit, &publicUrl.EnableDownload, &publicUrl.EnableCollect, &nonce, &memLimit, &opsLimit); err != nil {
 		if err = rows.Scan(&collectionID, &accessToken, &publicUrl.ValidTill, &publicUrl.DeviceLimit, &publicUrl.EnableDownload, &publicUrl.EnableCollect, &nonce, &memLimit, &opsLimit); err != nil {
 			return nil, stacktrace.Propagate(err, "")
 			return nil, stacktrace.Propagate(err, "")
 		}
 		}
-		publicUrl.URL = fmt.Sprintf(BaseShareURL, accessToken)
+		publicUrl.URL = pcr.GetAlbumUrl(accessToken)
 		if nonce != nil {
 		if nonce != nil {
 			publicUrl.Nonce = nonce
 			publicUrl.Nonce = nonce
 			publicUrl.MemLimit = memLimit
 			publicUrl.MemLimit = memLimit