Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix shared-album download manager init

Abhinava275e7d76b32
diff --git a/apps/photos/src/pages/shared-albums/index.tsx b/apps/photos/src/pages/shared-albums/index.tsx
index 61c4be4445..6b41f30db7 100644
--- a/apps/photos/src/pages/shared-albums/index.tsx
+++ b/apps/photos/src/pages/shared-albums/index.tsx
@@ -158,6 +158,7 @@ export default function PublicCollectionGallery() {
let redirectingToWebsite = false;
try {
const cryptoWorker = await ComlinkCryptoWorker.getInstance();
+ await downloadManager.init(APPS.ALBUMS);
url.current = window.location.href;
const currentURL = new URL(url.current);
@@ -175,6 +176,7 @@ export default function PublicCollectionGallery() {
? await cryptoWorker.toB64(bs58.decode(ck))
: await cryptoWorker.fromHex(ck);
token.current = t;
+ downloadManager.updateToken(token.current);
collectionKey.current = dck;
url.current = window.location.href;
const localCollection = await getLocalPublicCollection(
@@ -197,10 +199,10 @@ export default function PublicCollectionGallery() {
setPublicFiles(localPublicFiles);
passwordJWTToken.current =
await getLocalPublicCollectionPassword(collectionUID);
- await downloadManager.init(APPS.PHOTOS, {
- token: token.current,
- passwordToken: passwordJWTToken.current,
- });
+ downloadManager.updateToken(
+ token.current,
+ passwordJWTToken.current
+ );
}
await syncWithRemote();
} finally {
@@ -386,10 +388,10 @@ export default function PublicCollectionGallery() {
hashedPassword
);
passwordJWTToken.current = jwtToken;
- await downloadManager.init(APPS.PHOTOS, {
- token: token.current,
- passwordToken: passwordJWTToken.current,
- });
+ downloadManager.updateToken(
+ token.current,
+ passwordJWTToken.current
+ );
await savePublicCollectionPassword(collectionUID, jwtToken);
} catch (e) {
const parsedError = parseSharingErrorCodes(e);
diff --git a/apps/photos/src/services/download/clients/publicAlbums.ts b/apps/photos/src/services/download/clients/publicAlbums.ts
index 1977d5650e..f21ec71a5a 100644
--- a/apps/photos/src/services/download/clients/publicAlbums.ts
+++ b/apps/photos/src/services/download/clients/publicAlbums.ts
@@ -57,7 +57,12 @@ export class PublicAlbumsDownloadClient implements DownloadClient {
HTTPService.get(
getPublicCollectionFileURL(file.id),
null,
- { 'X-Auth-Token': this.token },
+ {
+ 'X-Auth-Access-Token': this.token,
+ ...(this.passwordToken && {
+ 'X-Auth-Access-Token-JWT': this.passwordToken,
+ }),
+ },
{
responseType: 'arraybuffer',
timeout: this.timeout,
@@ -79,7 +84,10 @@ export class PublicAlbumsDownloadClient implements DownloadClient {
return retryAsyncFunction(() =>
fetch(getPublicCollectionFileURL(file.id), {
headers: {
- 'X-Auth-Token': this.token,
+ 'X-Auth-Access-Token': this.token,
+ ...(this.passwordToken && {
+ 'X-Auth-Access-Token-JWT': this.passwordToken,
+ }),
},
})
);
diff --git a/apps/photos/src/services/download/index.ts b/apps/photos/src/services/download/index.ts
index 6102b0c426..f9b719a008 100644
--- a/apps/photos/src/services/download/index.ts
+++ b/apps/photos/src/services/download/index.ts
@@ -55,9 +55,14 @@ class DownloadManager {
private progressUpdater: (value: Map<number, number>) => void = () => {};
+ constructor() {
+ const main = async () => {};
+ main();
+ }
+
async init(
app: APPS,
- tokens: { token: string; passwordToken?: string } | { token: string },
+ tokens?: { token: string; passwordToken?: string } | { token: string },
timeout?: number
) {
try {
@@ -422,13 +427,16 @@ async function openThumbnailCache() {
function createDownloadClient(
app: APPS,
- tokens: { token: string; passwordToken?: string } | { token: string },
+ tokens?: { token: string; passwordToken?: string } | { token: string },
timeout?: number
): DownloadClient {
if (!timeout) {
timeout = 300000; // 5 minute
}
if (app === APPS.ALBUMS) {
+ if (!tokens) {
+ tokens = { token: undefined, passwordToken: undefined };
+ }
const { token, passwordToken } = tokens as {
token: string;
passwordToken: string;