diff --git a/components/DownloadBtn.tsx b/components/DownloadBtn.tsx deleted file mode 100644 index 113c034..0000000 --- a/components/DownloadBtn.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { FunctionComponent } from 'react' -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import toast, { Toaster } from 'react-hot-toast' -import { useRouter } from 'next/router' -import { useClipboard } from 'use-clipboard-copy' - -import { getBaseUrl } from '../utils/getBaseUrl' - -const DownloadBtn: FunctionComponent<{ downloadUrl: string }> = ({ downloadUrl }) => { - const { asPath } = useRouter() - const clipboard = useClipboard() - - return ( -
- - - - Download - - - - Proxy download - - -
- ) -} - -export default DownloadBtn diff --git a/components/DownloadBtnGtoup.tsx b/components/DownloadBtnGtoup.tsx new file mode 100644 index 0000000..9c13c43 --- /dev/null +++ b/components/DownloadBtnGtoup.tsx @@ -0,0 +1,92 @@ +import { MouseEventHandler } from 'react' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { IconProp } from '@fortawesome/fontawesome-svg-core' +import toast, { Toaster } from 'react-hot-toast' +import { useClipboard } from 'use-clipboard-copy' + +import Image from 'next/image' +import { useRouter } from 'next/router' + +import { getBaseUrl } from '../utils/getBaseUrl' + +const btnStyleMap = (btnColor?: string) => { + const colorMap = { + gray: 'hover:text-gray-600 dark:hover:text-white focus:ring-gray-200 focus:text-gray-600 dark:focus:text-white border-gray-300 dark:border-gray-500 dark:focus:ring-gray-500', + blue: 'hover:text-blue-600 focus:ring-blue-200 focus:text-blue-600 border-blue-300 dark:border-blue-700 dark:focus:ring-blue-500', + teal: 'hover:text-teal-600 focus:ring-teal-200 focus:text-teal-600 border-teal-300 dark:border-teal-700 dark:focus:ring-teal-500', + red: 'hover:text-red-600 focus:ring-red-200 focus:text-red-600 border-red-300 dark:border-red-700 dark:focus:ring-red-500', + green: + 'hover:text-green-600 focus:ring-green-200 focus:text-green-600 border-green-300 dark:border-green-700 dark:focus:ring-green-500', + pink: 'hover:text-pink-600 focus:ring-pink-200 focus:text-pink-600 border-pink-300 dark:border-pink-700 dark:focus:ring-pink-500', + yellow: + 'hover:text-yellow-400 focus:ring-yellow-100 focus:text-yellow-400 border-yellow-300 dark:border-yellow-400 dark:focus:ring-yellow-300', + } + + if (btnColor) { + return colorMap[btnColor] + } + + return colorMap.gray +} + +export const DownloadButton = ({ + onClickCallback, + btnColor, + btnText, + btnIcon, + btnImage, +}: { + onClickCallback: MouseEventHandler + btnColor?: string + btnText: string + btnIcon?: IconProp + btnImage?: string +}) => { + return ( + + ) +} + +const DownloadButtonGroup: React.FC<{ downloadUrl: string }> = ({ downloadUrl }) => { + const { asPath } = useRouter() + const clipboard = useClipboard() + + return ( +
+ + + window.open(downloadUrl)} + btnColor="blue" + btnText="Download" + btnIcon="file-download" + /> + window.open(`/api/proxy?url=${encodeURIComponent(downloadUrl)}`)} + btnColor="teal" + btnText="Proxy download" + btnIcon="download" + /> + { + clipboard.copy(`${getBaseUrl()}/api?path=${asPath}&raw=true`) + toast.success('Copied direct link to clipboard.') + }} + btnColor="yellow" + btnText="Copy direct link" + btnIcon="copy" + /> +
+ ) +} + +export default DownloadButtonGroup diff --git a/components/FileListing.tsx b/components/FileListing.tsx index 064a44a..74a25d6 100644 --- a/components/FileListing.tsx +++ b/components/FileListing.tsx @@ -30,7 +30,7 @@ import CodePreview from './previews/CodePreview' import OfficePreview from './previews/OfficePreview' import AudioPreview from './previews/AudioPreview' import VideoPreview from './previews/VideoPreview' -import DownloadBtn from './DownloadBtn' +import DownloadButtonGroup from './DownloadBtnGtoup' import PDFPreview from './previews/PDFPreview' // Disabling SSR for some previews (image gallery view, and PDF view) @@ -592,7 +592,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = />
- +
) diff --git a/components/FourOhFour.tsx b/components/FourOhFour.tsx index e920fbc..4b192d9 100644 --- a/components/FourOhFour.tsx +++ b/components/FourOhFour.tsx @@ -3,20 +3,20 @@ import { FunctionComponent } from 'react' const FourOhFour: FunctionComponent<{ errorMsg: string }> = ({ errorMsg }) => { return ( -
-
+
+
404
-
+
Oops, that's a four-oh-four.
-
+
{errorMsg}
-
+
Press{' '} - F12{' '} + F12{' '} and open devtools for more details, or seek help at{' '} { className="flex items-center space-x-2 dark:text-white hover:opacity-80" > - {l.name} + {l.name} ))} - - - Email - + {siteConfig.email && ( + + + Email + + )} {tokenPresent && ( )} diff --git a/components/previews/AudioPreview.tsx b/components/previews/AudioPreview.tsx index 87549e7..07657bb 100644 --- a/components/previews/AudioPreview.tsx +++ b/components/previews/AudioPreview.tsx @@ -2,7 +2,7 @@ import { FunctionComponent, useState } from 'react' import ReactPlayer from 'react-player' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import DownloadBtn from '../DownloadBtn' +import DownloadButtonGroup from '../DownloadBtnGtoup' enum PlayerState { Loading, @@ -74,7 +74,7 @@ const AudioPreview: FunctionComponent<{ file: any }> = ({ file }) => {
- +
) diff --git a/components/previews/CodePreview.tsx b/components/previews/CodePreview.tsx index 1f1b873..a19605f 100644 --- a/components/previews/CodePreview.tsx +++ b/components/previews/CodePreview.tsx @@ -5,7 +5,7 @@ import { getExtension } from '../../utils/getFileIcon' import { useStaleSWR } from '../../utils/fetchWithSWR' import FourOhFour from '../FourOhFour' import Loading from '../Loading' -import DownloadBtn from '../DownloadBtn' +import DownloadButtonGroup from '../DownloadBtnGtoup' const CodePreview: FunctionComponent<{ file: any }> = ({ file }) => { const { data, error } = useStaleSWR({ url: file['@microsoft.graph.downloadUrl'] }) @@ -39,7 +39,7 @@ const CodePreview: FunctionComponent<{ file: any }> = ({ file }) => {
- +
) diff --git a/components/previews/EPUBPreview.tsx b/components/previews/EPUBPreview.tsx index 5c52ec8..f7ae28c 100644 --- a/components/previews/EPUBPreview.tsx +++ b/components/previews/EPUBPreview.tsx @@ -3,7 +3,7 @@ import { ReactReader } from 'react-reader' import type { Rendition } from 'epubjs' import Loading from '../Loading' -import DownloadBtn from '../DownloadBtn' +import DownloadButtonGroup from '../DownloadBtnGtoup' const EPUBPreview: FunctionComponent<{file: any}> = ({ file }) => { const [epubContainerWidth, setEpubContainerWidth] = useState(400) @@ -52,7 +52,7 @@ const EPUBPreview: FunctionComponent<{file: any}> = ({ file }) => {
- +
) diff --git a/components/previews/MarkdownPreview.tsx b/components/previews/MarkdownPreview.tsx index a8e4cfa..e513478 100644 --- a/components/previews/MarkdownPreview.tsx +++ b/components/previews/MarkdownPreview.tsx @@ -10,7 +10,7 @@ import 'katex/dist/katex.min.css' import FourOhFour from '../FourOhFour' import Loading from '../Loading' -import DownloadBtn from '../DownloadBtn' +import DownloadButtonGroup from '../DownloadBtnGtoup' import { useStaleSWR } from '../../utils/fetchWithSWR' const MarkdownPreview: FunctionComponent<{ file: any; path: string; standalone?: boolean }> = ({ @@ -100,7 +100,7 @@ const MarkdownPreview: FunctionComponent<{ file: any; path: string; standalone?:
{standalone && (
- +
)} diff --git a/components/previews/OfficePreview.tsx b/components/previews/OfficePreview.tsx index e94da77..607d17a 100644 --- a/components/previews/OfficePreview.tsx +++ b/components/previews/OfficePreview.tsx @@ -1,7 +1,7 @@ import { FunctionComponent, useEffect, useRef, useState } from 'react' import Preview from 'preview-office-docs' -import DownloadBtn from '../DownloadBtn' +import DownloadButtonGroup from '../DownloadBtnGtoup' const OfficePreview: FunctionComponent<{ file: any }> = ({ file }) => { const docContainer = useRef(null) @@ -17,7 +17,7 @@ const OfficePreview: FunctionComponent<{ file: any }> = ({ file }) => {
- +
) diff --git a/components/previews/PDFPreview.tsx b/components/previews/PDFPreview.tsx index 00ad232..bd0ce73 100644 --- a/components/previews/PDFPreview.tsx +++ b/components/previews/PDFPreview.tsx @@ -1,6 +1,6 @@ import { FunctionComponent } from 'react' -import DownloadBtn from '../DownloadBtn' +import DownloadButtonGroup from '../DownloadBtnGtoup' const PDFEmbedPreview: FunctionComponent<{ file: any }> = ({ file }) => { // const url = `/api/proxy?url=${encodeURIComponent(file['@microsoft.graph.downloadUrl'])}&inline=true` @@ -14,7 +14,7 @@ const PDFEmbedPreview: FunctionComponent<{ file: any }> = ({ file }) => {
- +
) diff --git a/components/previews/TextPreview.tsx b/components/previews/TextPreview.tsx index 06817e6..95022ce 100644 --- a/components/previews/TextPreview.tsx +++ b/components/previews/TextPreview.tsx @@ -2,7 +2,7 @@ import { FunctionComponent } from 'react' import FourOhFour from '../FourOhFour' import Loading from '../Loading' -import DownloadBtn from '../DownloadBtn' +import DownloadButtonGroup from '../DownloadBtnGtoup' import { useStaleSWR } from '../../utils/fetchWithSWR' const TextPreview: FunctionComponent<{ file: any }> = ({ file }) => { @@ -28,7 +28,7 @@ const TextPreview: FunctionComponent<{ file: any }> = ({ file }) => {
{data}
- +
) diff --git a/components/previews/VideoPreview.tsx b/components/previews/VideoPreview.tsx index ed5cd60..c826607 100644 --- a/components/previews/VideoPreview.tsx +++ b/components/previews/VideoPreview.tsx @@ -7,6 +7,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import toast, { Toaster } from 'react-hot-toast' import { getBaseUrl } from '../../utils/getBaseUrl' +import { DownloadButton } from '../DownloadBtnGtoup' const VideoPreview: FunctionComponent<{ file: any }> = ({ file }) => { const { asPath } = useRouter() @@ -25,56 +26,48 @@ const VideoPreview: FunctionComponent<{ file: any }> = ({ file }) => { /> -
+
- - - Download - - + btnColor="yellow" + btnText="Copy direct link" + btnIcon="copy" + /> - - iina - IINA - - - vlc - VLC - - - potplayer - PotPlayer - + window.open(`iina://weblink?url=${file['@microsoft.graph.downloadUrl']}`)} + btnText="IINA" + btnImage="/players/iina.png" + /> + window.open(`vlc://${file['@microsoft.graph.downloadUrl']}`)} + btnText="VLC" + btnImage="/players/vlc.png" + /> + window.open(`potplayer://${file['@microsoft.graph.downloadUrl']}`)} + btnText="PotPlayer" + btnImage="/players/potplayer.png" + />
) diff --git a/tailwind.config.js b/tailwind.config.js index c75526f..2123b73 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -18,7 +18,8 @@ module.exports = { blue: colors.sky, indigo: colors.indigo, purple: colors.purple, - pink: colors.pink + pink: colors.pink, + teal: colors.teal }, extend: { fontFamily: {