[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
This commit is contained in:
Neeraj Gupta 2024-04-15 09:56:21 +05:30 committed by GitHub
parent 2387d7875c
commit 8ed2c7cff9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 27 additions and 6 deletions

View file

@ -163,7 +163,7 @@ func main() {
ObjectCopiesRepo: objectCopiesRepo, UsageRepo: usageRepo}
familyRepo := &repo.FamilyRepository{DB: db}
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,
TrashRepo: trashRepo, SecretEncryptionKey: secretEncryptionKeyBytes, QueueRepo: queueRepo, LatencyLogger: latencyLogger}
pushRepo := &repo.PushTokenRepository{DB: db}

View file

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

View file

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

View file

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

View file

@ -16,7 +16,23 @@ const BaseShareURL = "https://albums.ente.io?t=%s"
// PublicCollectionRepository defines the methods for inserting, updating and
// retrieving entities related to public collections
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,
@ -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 {
return nil, stacktrace.Propagate(err, "")
}
publicUrl.URL = fmt.Sprintf(BaseShareURL, accessToken)
publicUrl.URL = pcr.GetAlbumUrl(accessToken)
if nonce != nil {
publicUrl.Nonce = nonce
publicUrl.MemLimit = memLimit