minor changes and refactoring
This commit is contained in:
parent
3c8366e9e1
commit
86488ee056
|
@ -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
|
||||
|
|
|
@ -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<string>(null);
|
||||
// passwordJWTToken refers to the jwt token which is used for album protected by password.
|
||||
const passwordJWTToken = useRef<string>(null);
|
||||
const [passwordJWTToken, setPasswordJWTToken] = useState<string>(null);
|
||||
const collectionKey = useRef<string>(null);
|
||||
const url = useRef<string>(null);
|
||||
const [publicFiles, setPublicFiles] = useState<EnteFile[]>(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 <Container>{errorMessage}</Container>;
|
||||
}
|
||||
if (isPasswordProtected && !loading) {
|
||||
if (isPasswordProtected && !passwordJWTToken && !loading) {
|
||||
return (
|
||||
<Container>
|
||||
<Card style={{ minWidth: '320px' }} className="text-center">
|
||||
<Card style={{ width: '332px' }} className="text-center">
|
||||
<Card.Body style={{ padding: '40px 30px' }}>
|
||||
<Card.Title style={{ marginBottom: '24px' }}>
|
||||
<LogoImg src="/icon.svg" />
|
||||
{constants.PASSWORD}
|
||||
</Card.Title>
|
||||
<Card.Subtitle style={{ marginBottom: '32px' }}>
|
||||
<Card.Subtitle style={{ marginBottom: '2rem' }}>
|
||||
{/* <LogoImg src="/icon.svg" /> */}
|
||||
{constants.LINK_PASSWORD}
|
||||
</Card.Subtitle>
|
||||
|
@ -280,7 +277,7 @@ export default function PublicCollectionGallery() {
|
|||
value={{
|
||||
...defaultPublicCollectionGalleryContext,
|
||||
token: token.current,
|
||||
passwordToken: passwordJWTToken.current,
|
||||
passwordToken: passwordJWTToken,
|
||||
accessedThroughSharedURL: true,
|
||||
setDialogMessage,
|
||||
openReportForm,
|
||||
|
|
|
@ -59,7 +59,7 @@ export const savePublicCollectionFiles = async (
|
|||
);
|
||||
};
|
||||
|
||||
export const getPublicCollectionPassword = async (
|
||||
export const getLocalPublicCollectionPassword = async (
|
||||
collectionKey: string
|
||||
): Promise<string> => {
|
||||
return (
|
||||
|
@ -69,7 +69,7 @@ export const getPublicCollectionPassword = async (
|
|||
);
|
||||
};
|
||||
|
||||
export const setPublicCollectionPassword = async (
|
||||
export const savePublicCollectionPassword = async (
|
||||
collectionKey: string,
|
||||
passToken: string
|
||||
): Promise<string> => {
|
||||
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue