(false);
+ const [state, setState] = useRecoilState(CreateModalAtom);
+ const { create } = useDriveActions();
+
+ const createLink = async () => {
+ let finalLink = link.trim();
+ if (!/^https?:\/\//i.test(finalLink)) finalLink = 'http://' + finalLink;
+ const file = new File(['[InternetShortcut]\nURL=' + finalLink], name?.trim() + '.url', {
+ type: 'text/uri-list',
+ });
+
+ await FileUploadService.upload([file], {
+ context: {
+ parentId: state.parent_id,
+ },
+ callback: (file, context) => {
+ if (file)
+ create(
+ { name, parent_id: context.parentId, size: file.upload_data?.size },
+ {
+ provider: 'internal',
+ application_id: '',
+ file_metadata: {
+ name: file.metadata?.name,
+ size: file.upload_data?.size,
+ mime: file.metadata?.mime,
+ thumbnails: file?.thumbnails,
+ source: 'internal',
+ external_id: file.id,
+ },
+ },
+ );
+ },
+ });
+ };
+
+ return (
+ <>
+ Create a link
+
+ setName(e.target.value)}
+ />
+
+ setLink(e.target.value)}
+ />
+
+
+ >
+ );
+};
diff --git a/twake/frontend/src/app/views/client/body/drive/modals/create/index.tsx b/twake/frontend/src/app/views/client/body/drive/modals/create/index.tsx
index b73d9085..584d7e0b 100644
--- a/twake/frontend/src/app/views/client/body/drive/modals/create/index.tsx
+++ b/twake/frontend/src/app/views/client/body/drive/modals/create/index.tsx
@@ -1,11 +1,10 @@
import { Transition } from '@headlessui/react';
import {
ChevronLeftIcon,
- DesktopComputerIcon,
DocumentDownloadIcon,
FolderAddIcon,
FolderDownloadIcon,
- FolderIcon,
+ LinkIcon,
} from '@heroicons/react/outline';
import Avatar from 'app/atoms/avatar';
import A from 'app/atoms/link';
@@ -17,6 +16,7 @@ import { ReactNode } from 'react';
import { atom, useRecoilState } from 'recoil';
import { slideXTransition, slideXTransitionReverted } from 'src/utils/transitions';
import { CreateFolder } from './create-folder';
+import { CreateLink } from './create-link';
export type CreateModalAtomType = {
open: boolean;
@@ -93,6 +93,11 @@ export const CreateModal = ({
text="Upload folders from device"
onClick={() => selectFolderFromDevice()}
/>
+ }
+ text="Create a link file"
+ onClick={() => setState({ ...state, type: 'link' })}
+ />
{(applications || [])
.filter(app => app.display?.twake?.files?.editor?.empty_files?.length)
@@ -148,6 +153,18 @@ export const CreateModal = ({
>
+
+
+
+
diff --git a/twake/frontend/src/app/views/client/viewer/drive-display.tsx b/twake/frontend/src/app/views/client/viewer/drive-display.tsx
index 58277012..ea469805 100644
--- a/twake/frontend/src/app/views/client/viewer/drive-display.tsx
+++ b/twake/frontend/src/app/views/client/viewer/drive-display.tsx
@@ -9,6 +9,7 @@ import PdfDisplay from './pdf/display';
import CodeDisplay from './code/display';
import ArchiveDisplay from './archive/display';
import OtherDisplay from './other/display';
+import LinkDisplay from './link/display';
export default (): React.ReactElement => {
const { download, type, name, id } = useDrivePreviewDisplayData();
@@ -39,6 +40,8 @@ export default (): React.ReactElement => {
return ;
case 'pdf':
return ;
+ case 'link':
+ return ;
default:
return ;
}
diff --git a/twake/frontend/src/app/views/client/viewer/link/display.tsx b/twake/frontend/src/app/views/client/viewer/link/display.tsx
new file mode 100644
index 00000000..4a15df57
--- /dev/null
+++ b/twake/frontend/src/app/views/client/viewer/link/display.tsx
@@ -0,0 +1,70 @@
+import { Button } from 'app/atoms/button/button';
+import { useDrivePreviewDisplayData } from 'app/features/drive/hooks/use-drive-preview';
+import { useEffect, useState } from 'react';
+
+export default (props: { download: string; name: string }) => {
+ const { size } = useDrivePreviewDisplayData();
+ const [error, setError] = useState(false);
+ const [loading, setLoading] = useState(true);
+
+ const openLink = async () => {
+ if ((size || 10000000) < 10000) {
+ setLoading(true);
+ //Download file content and extract link from url props.download
+ try {
+ const response = await fetch(props.download);
+ const blob = await response.blob();
+ const reader = new FileReader();
+ reader.readAsText(blob);
+ reader.onloadend = () => {
+ const result = reader.result as string;
+ const link = result.match(/URL=(.*)/);
+ if (link && link[1]) {
+ window.open(link[1], '_blank');
+ } else {
+ setError(true);
+ }
+ setLoading(false);
+ };
+ } catch (e) {
+ setError(true);
+ setLoading(false);
+ }
+ return;
+ }
+ setError(true);
+ };
+
+ useEffect(() => {
+ openLink();
+ }, []);
+
+ if (loading) {
+ return (
+
+ Opening link...
+
+ );
+ }
+
+ if (error) {
+ return (
+
+
+ We can't open '{props.name}' as a link. You can download it instead.
+
+
+ );
+ }
+
+ return (
+
+
+ Link was open on another tab.
+
+
+
+
+
+ );
+};