shared-url: use base58 encoding for ck

This commit is contained in:
Neeraj Gupta 2022-02-13 23:41:58 +05:30
parent 3fc214962f
commit 94adaaf020
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1

View file

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