From 9493ce9f3ddd7b9c9b2e899eec02e336664e9e33 Mon Sep 17 00:00:00 2001 From: Spencer Woo Date: Mon, 14 Feb 2022 19:33:19 +0800 Subject: [PATCH] Standalone raw file redirects (#428) --- components/CustomEmbedLinkMenu.tsx | 15 +- components/DownloadBtnGtoup.tsx | 23 +-- components/FileListing.tsx | 21 ++- components/FolderGridLayout.tsx | 20 ++- components/FolderListLayout.tsx | 17 ++- components/MultiFileDownloader.tsx | 2 +- components/SearchModal.tsx | 4 +- components/previews/AudioPreview.tsx | 8 +- components/previews/CodePreview.tsx | 8 +- components/previews/DefaultPreview.tsx | 10 +- components/previews/EPUBPreview.tsx | 9 +- components/previews/ImagePreview.tsx | 9 +- components/previews/MarkdownPreview.tsx | 14 +- components/previews/OfficePreview.tsx | 10 +- components/previews/PDFPreview.tsx | 17 ++- components/previews/TextPreview.tsx | 8 +- components/previews/URLPreview.tsx | 10 +- components/previews/VideoPreview.tsx | 28 ++-- config/api.config.js | 7 +- pages/api/index.ts | 148 ++++++++++--------- pages/api/item.ts | 2 +- pages/api/name/[name].ts | 4 +- pages/api/raw.ts | 81 ++++++++++ pages/api/search.ts | 2 +- pages/api/thumbnail.ts | 30 ++-- pages/onedrive-vercel-index-oauth/step-2.tsx | 2 +- types/index.d.ts | 12 +- utils/fetchOnMount.ts | 23 ++- utils/fetchWithSWR.ts | 4 +- utils/oAuthHandler.ts | 2 +- 30 files changed, 365 insertions(+), 185 deletions(-) create mode 100644 pages/api/raw.ts diff --git a/components/CustomEmbedLinkMenu.tsx b/components/CustomEmbedLinkMenu.tsx index f8e7742..850a8e2 100644 --- a/components/CustomEmbedLinkMenu.tsx +++ b/components/CustomEmbedLinkMenu.tsx @@ -6,6 +6,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { useClipboard } from 'use-clipboard-copy' import { getBaseUrl } from '../utils/getBaseUrl' +import { getStoredToken } from '../utils/protectedRouteHandler' +import { getReadablePath } from '../utils/getReadablePath' export default function CustomEmbedLinkMenu({ path, @@ -18,6 +20,9 @@ export default function CustomEmbedLinkMenu({ }) { const { t } = useTranslation() const clipboard = useClipboard() + + const hashedToken = getStoredToken(path) + const closeMenu = () => setMenuOpen(false) const filename = path.substring(path.lastIndexOf('/') + 1) @@ -77,13 +82,13 @@ export default function CustomEmbedLinkMenu({ />

{t('Default')}

- {`${getBaseUrl()}/api?path=${path}&raw=true`} + {`${getBaseUrl()}/api/raw/?path=${getReadablePath(path)}${hashedToken ? `&odpt=${hashedToken}` : ''}`}

{t('Customised')}

{`${getBaseUrl()}/api/name/`} {name} - {`?path=${path}&raw=true`} + {`/?path=${getReadablePath(path)}${hashedToken ? `&odpt=${hashedToken}` : ''}`}
@@ -91,7 +96,11 @@ export default function CustomEmbedLinkMenu({