Standalone raw file redirects (#428)

This commit is contained in:
Spencer Woo
2022-02-14 19:33:19 +08:00
committed by GitHub
parent 0fda1c93db
commit 9493ce9f3d
30 changed files with 365 additions and 185 deletions
+11 -6
View File
@@ -11,6 +11,7 @@ import { humanFileSize, formatModifiedDateTime } from '../utils/fileDetails'
import { getReadablePath } from '../utils/getReadablePath'
import { Downloading, Checkbox, ChildIcon, ChildName } from './FileListing'
import { getStoredToken } from '../utils/protectedRouteHandler'
const FileListItem: FC<{ fileContent: OdFolderChildren }> = ({ fileContent: c }) => {
return (
@@ -45,9 +46,13 @@ const FolderListLayout = ({
toast,
}) => {
const clipboard = useClipboard()
const hashedToken = getStoredToken(path)
const { t } = useTranslation()
// Get item path from item name
const getItemPath = (name: string) => `${path === '/' ? '' : path}/${encodeURIComponent(name)}`
return (
<div className="rounded bg-white dark:bg-gray-900 dark:text-gray-100">
<div className="grid grid-cols-12 items-center space-x-2 border-b border-gray-900/10 px-3 dark:border-gray-500/30">
@@ -72,7 +77,7 @@ const FolderListLayout = ({
title={t('Select files')}
/>
{totalGenerating ? (
<Downloading title={t('Downloading selected files, refresh page to cancel')} />
<Downloading title={t('Downloading selected files, refresh page to cancel')} style="p-1.5" />
) : (
<button
title={t('Download selected files')}
@@ -113,7 +118,7 @@ const FolderListLayout = ({
<FontAwesomeIcon icon={['far', 'copy']} />
</span>
{folderGenerating[c.id] ? (
<Downloading title={t('Downloading folder, refresh page to cancel')} />
<Downloading title={t('Downloading folder, refresh page to cancel')} style="px-1.5 py-1" />
) : (
<span
title={t('Download folder')}
@@ -134,9 +139,9 @@ const FolderListLayout = ({
className="cursor-pointer rounded px-1.5 py-1 hover:bg-gray-300 dark:hover:bg-gray-600"
onClick={() => {
clipboard.copy(
`${getBaseUrl()}/api?path=${getReadablePath(
`${path === '/' ? '' : path}/${encodeURIComponent(c.name)}`
)}&raw=true`
`${getBaseUrl()}/api/raw/?path=${getReadablePath(getItemPath(c.name))}${
hashedToken ? `&odpt=${hashedToken}` : ''
}`
)
toast.success(t('Copied raw file permalink.'))
}}
@@ -146,7 +151,7 @@ const FolderListLayout = ({
<a
title={t('Download file')}
className="cursor-pointer rounded px-1.5 py-1 hover:bg-gray-300 dark:hover:bg-gray-600"
href={c['@microsoft.graph.downloadUrl']}
href={`/api/raw/?path=${getItemPath(c.name)}${hashedToken ? `&odpt=${hashedToken}` : ''}`}
>
<FontAwesomeIcon icon={['far', 'arrow-alt-circle-down']} />
</a>