diff --git a/src/components/FileBrowser.tsx b/src/components/FileBrowser.tsx index 44ee517..100087f 100644 --- a/src/components/FileBrowser.tsx +++ b/src/components/FileBrowser.tsx @@ -2,6 +2,8 @@ import React from "react" import { useState } from "react" import { useContextMenu } from "react-contexify" import { RouteComponentProps } from "react-router-dom" +import downloadFile from "../functions/downloadFile" +import genDownloadLink from "../functions/genDownloadLink" import normalizeDirPath from "../functions/normalizeDirPath" import uploadFile from "../functions/uploadFile" import { useCopyMutation, useCreateDirMutation, useDeleteDirMutation, useDeleteFileMutation, useMoveMutation, useOpenDirQuery } from "../generated/graphql" @@ -106,6 +108,9 @@ const FileBrowser: React.FC = (props) => { await deleteDirMutation({variables:{path:id}}) refetchDir() break + case Action.FileDownload: + downloadFile(genDownloadLink(id)) + break default: break } diff --git a/src/components/FileBrowserContextMenu.tsx b/src/components/FileBrowserContextMenu.tsx index 1356a23..573afdf 100644 --- a/src/components/FileBrowserContextMenu.tsx +++ b/src/components/FileBrowserContextMenu.tsx @@ -10,6 +10,7 @@ export enum Action { FileCopy, FilePaste, FileMove, + FileDownload, DirDelete } @@ -32,6 +33,7 @@ const FileBrowserContextMenu: React.FC = (props) => { Delete Copy Move + Download Paste diff --git a/src/functions/downloadFile.ts b/src/functions/downloadFile.ts new file mode 100644 index 0000000..bf2fee1 --- /dev/null +++ b/src/functions/downloadFile.ts @@ -0,0 +1,9 @@ +function downloadFile(uri:string): void { + const link = document.createElement("a") + link.download = "" + link.href = uri + link.click() + link.remove() +} + +export default downloadFile