From 86488ee0567ad3582cd2ce77fa86155479396ccd Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 25 Feb 2022 13:34:39 +0530 Subject: [PATCH] minor changes and refactoring --- sentry.client.config.js | 5 ++++ src/pages/shared-albums/index.tsx | 33 +++++++++++-------------- src/services/publicCollectionService.ts | 10 ++++---- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/sentry.client.config.js b/sentry.client.config.js index 34ad71aa9..4cb6db2df 100644 --- a/sentry.client.config.js +++ b/sentry.client.config.js @@ -29,6 +29,11 @@ Sentry.init({ event.request.url = currentURL; return event; }, + integrations: function (i) { + return i.filter(function (i) { + return i.name !== 'Breadcrumbs'; + }); + }, // ... // Note: if you want to override the automatic release value, do not set a // `release` value here - use the environment variable `SENTRY_RELEASE`, so diff --git a/src/pages/shared-albums/index.tsx b/src/pages/shared-albums/index.tsx index 14008c8cd..4aeadfe69 100644 --- a/src/pages/shared-albums/index.tsx +++ b/src/pages/shared-albums/index.tsx @@ -3,12 +3,12 @@ import PhotoFrame from 'components/PhotoFrame'; import React, { useContext, useEffect, useRef, useState } from 'react'; import { getLocalPublicCollection, + getLocalPublicCollectionPassword, getLocalPublicFiles, getPublicCollection, - getPublicCollectionPassword, getPublicCollectionUID, removePublicCollectionWithFiles, - setPublicCollectionPassword, + savePublicCollectionPassword, syncPublicFiles, verifyPublicCollectionPassword, } from 'services/publicCollectionService'; @@ -47,7 +47,7 @@ const bs58 = require('bs58'); export default function PublicCollectionGallery() { const token = useRef(null); // passwordJWTToken refers to the jwt token which is used for album protected by password. - const passwordJWTToken = useRef(null); + const [passwordJWTToken, setPasswordJWTToken] = useState(null); const collectionKey = useRef(null); const url = useRef(null); const [publicFiles, setPublicFiles] = useState(null); @@ -125,9 +125,11 @@ export default function PublicCollectionGallery() { const localPublicFiles = sortFiles( mergeMetadata(localFiles) ); + const localPasswordJWTToken = + await getLocalPublicCollectionPassword(collectionUID); + setPublicFiles(localPublicFiles); - passwordJWTToken.current = - await getPublicCollectionPassword(collectionUID); + setPasswordJWTToken(localPasswordJWTToken); } await syncWithRemote(); } finally { @@ -146,16 +148,14 @@ export default function PublicCollectionGallery() { token.current, collectionKey.current ); - const collectionUID = getPublicCollectionUID(token.current); setPublicCollection(collection); setErrorMessage(null); // check if we need to prompt user for the password if ( (collection?.publicURLs?.[0]?.passwordEnabled ?? false) && - (await getPublicCollectionPassword(collectionUID)) === '' + !passwordJWTToken ) { setIsPasswordProtected(true); - return; } else { await syncPublicFiles( token.current, @@ -190,7 +190,6 @@ export default function PublicCollectionGallery() { const verifyLinkPassword = async (password, setFieldError) => { try { - console.log('verify link password'); const cryptoWorker = await new CryptoWorker(); let hashedPassword: string = null; try { @@ -202,6 +201,7 @@ export default function PublicCollectionGallery() { publicUrl.memLimit ); } catch (e) { + logError(e, 'failed to derive key for verifyLinkPassword'); setFieldError( 'passphrase', `${constants.UNKNOWN_ERROR} ${e.message}` @@ -214,12 +214,10 @@ export default function PublicCollectionGallery() { token.current, hashedPassword ); - setPublicCollectionPassword(collectionUID, jwtToken); - passwordJWTToken.current = jwtToken; + setPasswordJWTToken(jwtToken); + savePublicCollectionPassword(collectionUID, jwtToken); } catch (e) { // reset local password token - passwordJWTToken.current = null; - setPublicCollectionPassword(collectionUID, ''); logError(e, 'failed to validate password for album'); const parsedError = parseSharingErrorCodes(e); if (parsedError.message === CustomError.TOKEN_EXPIRED) { @@ -229,7 +227,6 @@ export default function PublicCollectionGallery() { throw e; } await syncWithRemote(); - setIsPasswordProtected(false); finishLoadingBar(); } catch (e) { setFieldError( @@ -246,16 +243,16 @@ export default function PublicCollectionGallery() { if (errorMessage && !loading) { return {errorMessage}; } - if (isPasswordProtected && !loading) { + if (isPasswordProtected && !passwordJWTToken && !loading) { return ( - + {constants.PASSWORD} - + {/* */} {constants.LINK_PASSWORD} @@ -280,7 +277,7 @@ export default function PublicCollectionGallery() { value={{ ...defaultPublicCollectionGalleryContext, token: token.current, - passwordToken: passwordJWTToken.current, + passwordToken: passwordJWTToken, accessedThroughSharedURL: true, setDialogMessage, openReportForm, diff --git a/src/services/publicCollectionService.ts b/src/services/publicCollectionService.ts index 4ede4cd15..2fd15ad50 100644 --- a/src/services/publicCollectionService.ts +++ b/src/services/publicCollectionService.ts @@ -59,7 +59,7 @@ export const savePublicCollectionFiles = async ( ); }; -export const getPublicCollectionPassword = async ( +export const getLocalPublicCollectionPassword = async ( collectionKey: string ): Promise => { return ( @@ -69,7 +69,7 @@ export const getPublicCollectionPassword = async ( ); }; -export const setPublicCollectionPassword = async ( +export const savePublicCollectionPassword = async ( collectionKey: string, passToken: string ): Promise => { @@ -158,7 +158,7 @@ export const syncPublicFiles = async ( const lastSyncTime = await getPublicCollectionLastSyncTime( collectionUID ); - const passwordToken = await getPublicCollectionPassword( + const passwordToken = await getLocalPublicCollectionPassword( collectionUID ); // if (collection.updationTime === lastSyncTime) { @@ -284,7 +284,7 @@ export const getPublicCollection = async ( null, { 'Cache-Control': 'no-cache', 'X-Auth-Access-Token': token } ); - const fetchedCollection = resp.data?.collection; + const fetchedCollection = resp.data.collection; const collectionName = await decryptCollectionName( fetchedCollection, collectionKey @@ -313,7 +313,7 @@ export const verifyPublicCollectionPassword = async ( null, { 'Cache-Control': 'no-cache', 'X-Auth-Access-Token': token } ); - const jwtToken = resp.data?.jwtToken; + const jwtToken = resp.data.jwtToken; return jwtToken; } catch (e) { logError(e, 'failed to get public collection');