1 import { getAppHref } from '@proton/shared/lib/apps/helper';
2 import { APPS } from '@proton/shared/lib/constants';
3 import { SHARE_GENERATED_PASSWORD_LENGTH } from '@proton/shared/lib/drive/constants';
4 import { hasBit } from '@proton/shared/lib/helpers/bitset';
5 import { SharedURLFlags } from '@proton/shared/lib/interfaces/drive/sharing';
7 import { replaceLocalURL } from '../../utils/replaceLocalURL';
9 export const isLegacySharedUrl = (sharedURL?: { flags?: number }) =>
10 !!sharedURL && (sharedURL.flags === SharedURLFlags.CustomPassword || sharedURL.flags === SharedURLFlags.Legacy);
12 export const hasCustomPassword = (sharedURL?: { flags?: number }): boolean => {
13 return !!sharedURL && hasBit(sharedURL.flags, SharedURLFlags.CustomPassword);
16 export const hasGeneratedPasswordIncluded = (sharedURL?: { flags?: number }): boolean => {
17 return !!sharedURL && hasBit(sharedURL.flags, SharedURLFlags.GeneratedPasswordIncluded);
20 export const splitGeneratedAndCustomPassword = (password: string, sharedURL?: { flags?: number }): [string, string] => {
21 if (hasCustomPassword(sharedURL)) {
22 if (hasGeneratedPasswordIncluded(sharedURL)) {
24 password.substring(0, SHARE_GENERATED_PASSWORD_LENGTH),
25 password.substring(SHARE_GENERATED_PASSWORD_LENGTH),
28 // This is legacy custom password mode; new shares should not create it.
29 return ['', password];
31 return [password, ''];
34 export const getSharedLink = (sharedURL?: {
39 }): string | undefined => {
44 const [generatedPassword] = splitGeneratedAndCustomPassword(sharedURL.password, sharedURL);
46 const url = sharedURL.publicUrl
47 ? replaceLocalURL(sharedURL.publicUrl)
48 : getAppHref(`/urls/${sharedURL.token}`, APPS.PROTONDRIVE);
49 return `${url}${generatedPassword !== '' ? `#${generatedPassword}` : ''}`;