diff --git a/package.json b/package.json
index b30b0b2d3..699e2837a 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,7 @@
"@iconscout/react-unicons": "^1.1.6",
"@internxt/inxt-js": "=1.2.21",
"@internxt/lib": "^1.2.0",
- "@internxt/sdk": "1.4.52",
+ "@internxt/sdk": "1.4.53",
"@phosphor-icons/react": "^2.0.10",
"@popperjs/core": "^2.11.6",
"@reduxjs/toolkit": "^1.6.0",
diff --git a/src/app/core/config/app.json b/src/app/core/config/app.json
index dea285716..1934ceb05 100644
--- a/src/app/core/config/app.json
+++ b/src/app/core/config/app.json
@@ -188,7 +188,7 @@
{
"id": "share-token",
"layout": "share",
- "path": "/sh/file/:token([a-z0-9]{20})/:code?",
+ "path": "/sh/file/:token/:code?",
"exact": false
},
{
diff --git a/src/app/drive/components/ShareDialog/ShareDialog.tsx b/src/app/drive/components/ShareDialog/ShareDialog.tsx
index fe28aa236..276cd3d54 100644
--- a/src/app/drive/components/ShareDialog/ShareDialog.tsx
+++ b/src/app/drive/components/ShareDialog/ShareDialog.tsx
@@ -12,7 +12,6 @@ import { ArrowLeft, CaretDown, Check, CheckCircle, Globe, Link, UserPlus, Users,
import Avatar from 'app/shared/components/Avatar';
import Spinner from 'app/shared/components/Spinner/Spinner';
import { sharedThunks } from '../../../store/slices/sharedLinks';
-import { DriveItemData } from '../../types';
import './ShareDialog.scss';
import shareService, { getSharingRoles } from '../../../share/services/share.service';
import errorService from '../../../core/services/error.service';
@@ -21,6 +20,9 @@ import notificationsService, { ToastType } from '../../../notifications/services
import { Role } from 'app/store/slices/sharedLinks/types';
import copy from 'copy-to-clipboard';
+import crypto from 'crypto';
+import { aes } from '@internxt/lib';
+
type AccessMode = 'public' | 'restricted';
type UserRole = 'owner' | 'editor' | 'reader';
type Views = 'general' | 'invite' | 'requests';
@@ -213,17 +215,55 @@ const ShareDialog = (props: ShareDialogProps): JSX.Element => {
dispatch(uiActions.setIsShareDialogOpen(false));
};
- const onCopyLink = (): void => {
- if (accessMode === 'restricted') {
+ const getPublicShareLink = async (uuid: string, itemType: 'folder' | 'file') => {
+ const user = props.user;
+ const { mnemonic } = user;
+ const code = crypto.randomBytes(32).toString('hex');
+
+ const encryptedMnemonic = aes.encrypt(mnemonic, code);
+
+ try {
+ const publicSharingItemData = await shareService.createPublicSharingItem({
+ encryptionAlgorithm: 'inxt-v2',
+ encryptionKey: encryptedMnemonic,
+ itemType,
+ itemId: uuid,
+ });
+ const { id: sharingId } = publicSharingItemData;
+
+ copy(`${process.env.REACT_APP_HOSTNAME}/sh/${itemType}/${sharingId}/${code}`);
+ notificationsService.show({ text: translate('shared-links.toast.copy-to-clipboard'), type: ToastType.Success });
+ } catch (error) {
+ notificationsService.show({
+ text: translate('modals.shareModal.errors.copy-to-clipboard'),
+ type: ToastType.Error,
+ });
+ }
+ };
+
+ const getPrivateShareLink = () => {
+ try {
copy(`${process.env.REACT_APP_HOSTNAME}/app/shared/?folderuuid=${itemToShare?.item.uuid}`);
notificationsService.show({ text: translate('shared-links.toast.copy-to-clipboard'), type: ToastType.Success });
+ } catch (error) {
+ notificationsService.show({
+ text: translate('modals.shareModal.errors.copy-to-clipboard'),
+ type: ToastType.Error,
+ });
+ }
+ };
+
+ const onCopyLink = (): void => {
+ if (accessMode === 'restricted') {
+ getPrivateShareLink();
closeSelectedUserPopover();
return;
}
- dispatch(sharedThunks.getSharedLinkThunk({ item: itemToShare?.item as DriveItemData }));
-
- closeSelectedUserPopover();
+ if (itemToShare?.item.uuid) {
+ getPublicShareLink(itemToShare?.item.uuid, itemToShare.item.isFolder ? 'folder' : 'file');
+ closeSelectedUserPopover();
+ }
};
const onInviteUser = () => {
@@ -450,7 +490,7 @@ const ShareDialog = (props: ShareDialogProps): JSX.Element => {
{({ close }) => (
<>
{/* Public */}
- {/* */}
+
{/* Restricted */}