Merge pull request #370 from ente-io/release-base58

Release base58
This commit is contained in:
Vishnu Mohandas 2022-02-14 23:36:34 +05:30 committed by GitHub
commit f8fa81b4df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 6 deletions

View file

@ -23,6 +23,7 @@
"axios": "^0.21.3", "axios": "^0.21.3",
"bip39": "^3.0.4", "bip39": "^3.0.4",
"bootstrap": "^4.5.2", "bootstrap": "^4.5.2",
"bs58" : "^4.0.1",
"chrono-node": "^2.2.6", "chrono-node": "^2.2.6",
"comlink": "^4.3.0", "comlink": "^4.3.0",
"debounce-promise": "^3.1.2", "debounce-promise": "^3.1.2",

View file

@ -36,6 +36,7 @@ const Loader = () => (
</EnteSpinner> </EnteSpinner>
</Container> </Container>
); );
const bs58 = require('bs58');
export default function PublicCollectionGallery() { export default function PublicCollectionGallery() {
const token = useRef<string>(null); const token = useRef<string>(null);
const collectionKey = useRef<string>(null); const collectionKey = useRef<string>(null);
@ -92,10 +93,13 @@ export default function PublicCollectionGallery() {
const currentURL = new URL(url.current); const currentURL = new URL(url.current);
const t = currentURL.searchParams.get('t'); const t = currentURL.searchParams.get('t');
const ck = currentURL.hash.slice(1); const ck = currentURL.hash.slice(1);
const dck = await worker.fromHex(ck); if (!t || !ck) {
if (!t || !dck) {
return; return;
} }
const dck =
ck.length < 50
? await worker.toB64(bs58.decode(ck))
: await worker.fromHex(ck);
token.current = t; token.current = t;
collectionKey.current = dck; collectionKey.current = dck;
url.current = window.location.href; url.current = window.location.href;

View file

@ -16,7 +16,6 @@ import { logError } from 'utils/sentry';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
import { Collection } from 'types/collection'; import { Collection } from 'types/collection';
import { CollectionType } from 'constants/collection'; import { CollectionType } from 'constants/collection';
import CryptoWorker from 'utils/crypto';
import { getAlbumSiteHost } from 'constants/pages'; import { getAlbumSiteHost } from 'constants/pages';
export enum COLLECTION_OPS_TYPE { export enum COLLECTION_OPS_TYPE {
@ -114,15 +113,16 @@ export async function appendCollectionKeyToShareURL(
url: string, url: string,
collectionKey: string collectionKey: string
) { ) {
const worker = await new CryptoWorker();
if (!url) { if (!url) {
return null; return null;
} }
const bs58 = require('bs58');
const sharableURL = new URL(url); const sharableURL = new URL(url);
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
sharableURL.host = getAlbumSiteHost(); sharableURL.host = getAlbumSiteHost();
sharableURL.protocol = 'http'; sharableURL.protocol = 'http';
} }
sharableURL.hash = await worker.toHex(collectionKey); const bytes = Buffer.from(collectionKey, 'base64');
sharableURL.hash = bs58.encode(bytes);
return sharableURL.href; return sharableURL.href;
} }

View file

@ -2079,6 +2079,13 @@ balanced-match@^1.0.0:
resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz" resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
base-x@^3.0.2:
version "3.0.9"
resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.9.tgz#6349aaabb58526332de9f60995e548a53fe21320"
integrity sha512-H7JU6iBHTal1gp56aKoaa//YUxEaAOUiydvrV/pILqIHXTtqxSkATOnDA2u+jZ/61sD+L/412+7kzXRtWukhpQ==
dependencies:
safe-buffer "^5.0.1"
base64-js@^1.0.2: base64-js@^1.0.2:
version "1.5.1" version "1.5.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
@ -2269,6 +2276,13 @@ browserslist@^4.16.6, browserslist@^4.17.0:
escalade "^3.1.1" escalade "^3.1.1"
node-releases "^1.1.75" node-releases "^1.1.75"
bs58@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/bs58/-/bs58-4.0.1.tgz#be161e76c354f6f788ae4071f63f34e8c4f0a42a"
integrity sha1-vhYedsNU9veIrkBx9j806MTwpCo=
dependencies:
base-x "^3.0.2"
buffer-from@^1.0.0: buffer-from@^1.0.0:
version "1.1.2" version "1.1.2"
resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz" resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz"
@ -5086,7 +5100,7 @@ peek-readable@^4.0.1:
integrity sha512-7qmhptnR0WMSpxT5rMHG9bW/mYSR1uqaPFj2MHvT+y/aOUu6msJijpKt5SkTDKySwg65OWG2JwTMBlgcbwMHrQ== integrity sha512-7qmhptnR0WMSpxT5rMHG9bW/mYSR1uqaPFj2MHvT+y/aOUu6msJijpKt5SkTDKySwg65OWG2JwTMBlgcbwMHrQ==
"photoswipe@file:./thirdparty/photoswipe": "photoswipe@file:./thirdparty/photoswipe":
version "4.1.4" version "4.1.3"
picomatch@^2.0.4, picomatch@^2.2.1: picomatch@^2.0.4, picomatch@^2.2.1:
version "2.3.1" version "2.3.1"