π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix link for locker
Neeraj Guptabc6506cb10fa
diff --git a/server/pkg/controller/collections/share.go b/server/pkg/controller/collections/share.goindex 6002c7b493..55dc0e729a 100644--- a/server/pkg/controller/collections/share.go+++ b/server/pkg/controller/collections/share.go@@ -181,7 +181,7 @@ func (c *CollectionController) UpdateShareeMagicMetadata(ctx *gin.Context, req e}// ShareURL generates a public auth-token for the given collectionID-func (c *CollectionController) ShareURL(ctx context.Context, userID int64, req ente.CreatePublicAccessTokenRequest) (+func (c *CollectionController) ShareURL(ctx *gin.Context, userID int64, req ente.CreatePublicAccessTokenRequest) (ente.PublicURL, error) {collection, err := c.CollectionRepo.Get(req.CollectionID)if err != nil {@@ -206,7 +206,7 @@ func (c *CollectionController) ShareURL(ctx context.Context, userID int64, req e// UpdateShareURL updates the shared url configurationfunc (c *CollectionController) UpdateShareURL(- ctx context.Context,+ ctx *gin.Context,userID int64,req ente.UpdatePublicAccessTokenRequest,) (*ente.PublicURL, error) {diff --git a/server/pkg/controller/public/collection_link.go b/server/pkg/controller/public/collection_link.goindex ead744bfbf..0f592c2d8e 100644--- a/server/pkg/controller/public/collection_link.go+++ b/server/pkg/controller/public/collection_link.go@@ -60,13 +60,14 @@ type CollectionLinkController struct {JwtSecret []byte}-func (c *CollectionLinkController) CreateLink(ctx context.Context, req ente.CreatePublicAccessTokenRequest) (ente.PublicURL, error) {+func (c *CollectionLinkController) CreateLink(ctx *gin.Context, req ente.CreatePublicAccessTokenRequest) (ente.PublicURL, error) {accessToken := shortuuid.New()[0:AccessTokenLength]+ app := auth.GetApp(ctx)err := c.CollectionLinkRepo.Insert(ctx, req.CollectionID, accessToken, req.ValidTill, req.DeviceLimit, req.EnableCollect, req.EnableJoin)if err != nil {if errors.Is(err, ente.ErrActiveLinkAlreadyExists) {- collectionToPubUrlMap, err2 := c.CollectionLinkRepo.GetCollectionToActivePublicURLMap(ctx, []int64{req.CollectionID})+ collectionToPubUrlMap, err2 := c.CollectionLinkRepo.GetCollectionToActivePublicURLMap(ctx, []int64{req.CollectionID}, app)if err2 != nil {return ente.PublicURL{}, stacktrace.Propagate(err2, "")}@@ -81,8 +82,9 @@ func (c *CollectionLinkController) CreateLink(ctx context.Context, req ente.Creareturn ente.PublicURL{}, stacktrace.Propagate(err, "")}}+response := ente.PublicURL{- URL: c.CollectionLinkRepo.GetAlbumUrl(accessToken),+ URL: c.CollectionLinkRepo.GetAlbumUrl(app, accessToken),ValidTill: req.ValidTill,DeviceLimit: req.DeviceLimit,EnableDownload: true,@@ -124,7 +126,7 @@ func (c *CollectionLinkController) Disable(ctx context.Context, cID int64) errorreturn stacktrace.Propagate(err, "")}-func (c *CollectionLinkController) UpdateSharedUrl(ctx context.Context, req ente.UpdatePublicAccessTokenRequest) (ente.PublicURL, error) {+func (c *CollectionLinkController) UpdateSharedUrl(ctx *gin.Context, req ente.UpdatePublicAccessTokenRequest) (ente.PublicURL, error) {publicCollectionToken, err := c.CollectionLinkRepo.GetActiveCollectionLinkRow(ctx, req.CollectionID)if err != nil {return ente.PublicURL{}, err@@ -159,8 +161,9 @@ func (c *CollectionLinkController) UpdateSharedUrl(ctx context.Context, req enteif err != nil {return ente.PublicURL{}, stacktrace.Propagate(err, "")}+ app := auth.GetApp(ctx)return ente.PublicURL{- URL: c.CollectionLinkRepo.GetAlbumUrl(publicCollectionToken.Token),+ URL: c.CollectionLinkRepo.GetAlbumUrl(app, publicCollectionToken.Token),DeviceLimit: publicCollectionToken.DeviceLimit,ValidTill: publicCollectionToken.ValidTill,EnableDownload: publicCollectionToken.EnableDownload,diff --git a/server/pkg/repo/collection.go b/server/pkg/repo/collection.goindex c76b40da50..dc403e8bf3 100644--- a/server/pkg/repo/collection.go+++ b/server/pkg/repo/collection.go@@ -61,12 +61,12 @@ func (repo *CollectionRepository) Create(c ente.Collection) (ente.Collection, er// Get returns a collection identified by the collectionIDfunc (repo *CollectionRepository) Get(collectionID int64) (ente.Collection, error) {- row := repo.DB.QueryRow(`SELECT collection_id, owner_id, encrypted_key, key_decryption_nonce, name, encrypted_name, name_decryption_nonce, type, attributes, updation_time, is_deleted, magic_metadata, pub_magic_metadata+ row := repo.DB.QueryRow(`SELECT collection_id, app, owner_id, encrypted_key, key_decryption_nonce, name, encrypted_name, name_decryption_nonce, type, attributes, updation_time, is_deleted, magic_metadata, pub_magic_metadataFROM collectionsWHERE collection_id = $1`, collectionID)var c ente.Collectionvar name, encryptedName, nameDecryptionNonce sql.NullString- if err := row.Scan(&c.ID, &c.Owner.ID, &c.EncryptedKey, &c.KeyDecryptionNonce, &name, &encryptedName, &nameDecryptionNonce, &c.Type, &c.Attributes, &c.UpdationTime, &c.IsDeleted, &c.MagicMetadata, &c.PublicMagicMetadata); err != nil {+ if err := row.Scan(&c.ID, &c.App, &c.Owner.ID, &c.EncryptedKey, &c.KeyDecryptionNonce, &name, &encryptedName, &nameDecryptionNonce, &c.Type, &c.Attributes, &c.UpdationTime, &c.IsDeleted, &c.MagicMetadata, &c.PublicMagicMetadata); err != nil {return c, stacktrace.Propagate(err, "")}if name.Valid && len(name.String) > 0 {@@ -75,7 +75,11 @@ func (repo *CollectionRepository) Get(collectionID int64) (ente.Collection, erroc.EncryptedName = encryptedName.Stringc.NameDecryptionNonce = nameDecryptionNonce.String}- urlMap, err := repo.CollectionLinkRepo.GetCollectionToActivePublicURLMap(context.Background(), []int64{collectionID})+ app := ente.Photos+ if len(c.App) > 0 && ente.App(c.App).IsValid() {+ app = ente.App(c.App)+ }+ urlMap, err := repo.CollectionLinkRepo.GetCollectionToActivePublicURLMap(context.Background(), []int64{collectionID}, app)if err != nil {return ente.Collection{}, stacktrace.Propagate(err, "failed to get publicURL info")}@@ -175,7 +179,7 @@ pct.access_token, pct.valid_till, pct.device_limit, pct.created_at, pct.updated_if _, ok := addPublicUrlMap[pctToken.String]; !ok {addPublicUrlMap[pctToken.String] = trueurl := ente.PublicURL{- URL: repo.CollectionLinkRepo.GetAlbumUrl(pctToken.String),+ URL: repo.CollectionLinkRepo.GetAlbumUrl(app, pctToken.String),DeviceLimit: int(pctDeviceLimit.Int32),ValidTill: pctValidTill.Int64,EnableDownload: pctEnableDownload.Bool,diff --git a/server/pkg/repo/public/collection_link.go b/server/pkg/repo/public/collection_link.goindex 3271a850b7..dfbc93679c 100644--- a/server/pkg/repo/public/collection_link.go+++ b/server/pkg/repo/public/collection_link.go@@ -5,6 +5,7 @@ import ("database/sql""errors""fmt"+ "github.com/spf13/viper""github.com/ente-io/museum/ente""github.com/ente-io/stacktrace"@@ -14,8 +15,9 @@ import (// CollectionLinkRepo defines the methods for inserting, updating and// retrieving entities related to public collectionstype CollectionLinkRepo struct {- DB *sql.DB- albumHost string+ DB *sql.DB+ albumHost string+ lockerHost string}// NewCollectionLinkRepository ..@@ -23,13 +25,21 @@ func NewCollectionLinkRepository(db *sql.DB, albumHost string) *CollectionLinkReif albumHost == "" {albumHost = "https://albums.ente.io"}+ lockerHost := viper.GetString("apps.public-locker")+ if lockerHost == "" {+ lockerHost = "https://locker.ente.io"+ }return &CollectionLinkRepo{- DB: db,- albumHost: albumHost,+ DB: db,+ albumHost: albumHost,+ lockerHost: lockerHost,}}-func (pcr *CollectionLinkRepo) GetAlbumUrl(token string) string {+func (pcr *CollectionLinkRepo) GetAlbumUrl(app ente.App, token string) string {+ if app == ente.Locker {+ return fmt.Sprintf("%s/?t=%s", pcr.lockerHost, token)+ }return fmt.Sprintf("%s/?t=%s", pcr.albumHost, token)}@@ -57,7 +67,7 @@ func (pcr *CollectionLinkRepo) DisableSharing(ctx context.Context, cID int64) er// GetCollectionToActivePublicURLMap will return map of collectionID to PublicURLs which are not disabled yet.// Note: The url could be expired or deviceLimit is already reached-func (pcr *CollectionLinkRepo) GetCollectionToActivePublicURLMap(ctx context.Context, collectionIDs []int64) (map[int64][]ente.PublicURL, error) {+func (pcr *CollectionLinkRepo) GetCollectionToActivePublicURLMap(ctx context.Context, collectionIDs []int64, app ente.App) (map[int64][]ente.PublicURL, error) {rows, err := pcr.DB.QueryContext(ctx, `SELECT collection_id, access_token, valid_till, device_limit, enable_download, enable_collect, enable_join, pw_nonce, mem_limit, ops_limit FROMpublic_collection_tokens WHERE collection_id = ANY($1) and is_disabled = FALSE`,pq.Array(collectionIDs))@@ -78,7 +88,7 @@ func (pcr *CollectionLinkRepo) GetCollectionToActivePublicURLMap(ctx context.Conif err = rows.Scan(&collectionID, &accessToken, &publicUrl.ValidTill, &publicUrl.DeviceLimit, &publicUrl.EnableDownload, &publicUrl.EnableCollect, &publicUrl.EnableJoin, &nonce, &memLimit, &opsLimit); err != nil {return nil, stacktrace.Propagate(err, "")}- publicUrl.URL = pcr.GetAlbumUrl(accessToken)+ publicUrl.URL = pcr.GetAlbumUrl(app, accessToken)if nonce != nil {publicUrl.Nonce = noncepublicUrl.MemLimit = memLimit