1 import { useApi } from '@proton/components';
2 import { querySharedURLInformation, querySubmitAbuseReport } from '@proton/shared/lib/api/drive/sharing';
3 import type { SharedURLInfo } from '@proton/shared/lib/interfaces/drive/sharing';
5 import { usePublicSession } from '../_api';
6 import { useLink } from '../_links';
7 import { useDecryptPublicShareLink } from './useDecryptPublicShareLink';
10 * usePublicShare loads shared share with link to the store and decrypts them.
12 export default function usePublicShare() {
14 const { user, request, getSessionInfo } = usePublicSession();
15 const { decryptPublicShareLink } = useDecryptPublicShareLink();
16 const { getLinkPassphraseAndSessionKey } = useLink();
18 const loadPublicShare = async (abortSignal: AbortSignal) => {
19 const sessionInfo = getSessionInfo();
21 throw new Error('Unauthenticated session');
24 const { Token } = await request<{ Token: SharedURLInfo }>({
25 ...querySharedURLInformation(sessionInfo.token),
29 const link = await decryptPublicShareLink(abortSignal, {
30 token: sessionInfo.token,
31 urlPassword: sessionInfo.password,
36 token: sessionInfo.token,
38 permissions: Token.Permissions,
42 const submitAbuseReport = async (params: {
44 abuseCategory: string;
45 reporterEmail?: string;
46 reporterMessage?: string;
47 }): Promise<void> => {
48 const sessionInfo = getSessionInfo();
50 throw new Error('Unauthenticated session');
52 const { token, password } = sessionInfo;
53 const ac = new AbortController();
54 const { passphrase } = await getLinkPassphraseAndSessionKey(ac.signal, token, params.linkId);
57 querySubmitAbuseReport({
58 ShareURL: window.location.href,
60 AbuseCategory: params.abuseCategory,
61 ReporterEmail: params.reporterEmail,
62 ReporterMessage: params.reporterMessage,
63 ResourcePassphrase: passphrase,