1 import type { Location } from 'history';
3 import { CryptoProxy } from '@proton/crypto';
4 import type { ShareMapLink } from '@proton/shared/lib/interfaces/drive/link';
6 import type { ESLink } from './types';
8 export const createItemId = (shareId: string, linkId: string) => {
9 return `${shareId}:${linkId}`;
12 export const parseItemId = (esItemId: string) => {
13 const [shareId, linkId] = esItemId.split(':');
14 return { shareId, linkId };
17 export const generateOrder = async (ID: string) => {
18 const numericalID = ID.split('').map((char) => char.charCodeAt(0));
19 const digest = await CryptoProxy.computeHash({ algorithm: 'unsafeMD5', data: Uint8Array.from(numericalID) });
20 const orderArray = new Uint32Array(digest.buffer);
25 export const convertLinkToESItem = async (link: ShareMapLink, shareId: string): Promise<ESLink> => {
26 const id = createItemId(shareId, link.LinkID);
27 const order = await generateOrder(id);
28 const processedLink = {
30 createTime: link.CreateTime,
31 decryptedName: link.Name,
33 MIMEType: link.MIMEType,
34 modifiedTime: link.ModifyTime,
35 parentLinkId: link.ParentLinkID,
43 export const getDefaultSessionValue = () => ({
51 * Transforms url hash into an object
52 * @param urlHash Example: `#q=query&sort=acs`
54 export const parseHashParams = (urlHash: string) => {
55 const result: Record<string, string> = {};
60 .reduce(function (res, item) {
61 const [key, value] = item.split('=');
67 export const extractSearchParameters = (location: Location): string => {
68 const hashParams = parseHashParams(location.hash);
69 const { q } = hashParams;
70 return q ? decodeURIComponent(q) : '';