diff --git a/components/Breadcrumb.tsx b/components/Breadcrumb.tsx index 02d2e38..1a7563c 100644 --- a/components/Breadcrumb.tsx +++ b/components/Breadcrumb.tsx @@ -16,7 +16,14 @@ const Breadcrumb: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) =>
/
- {q} + encodeURIComponent(p)) + .join('/')}`} + > + {q} +
))} diff --git a/components/FileListing.tsx b/components/FileListing.tsx index 60ae97b..b942506 100644 --- a/components/FileListing.tsx +++ b/components/FileListing.tsx @@ -53,13 +53,16 @@ const queryToPath = (query?: ParsedUrlQuery) => { if (query) { const { path } = query if (!path) return '/' - if (typeof path === 'string') return `/${path}` - return `/${path.join('/')}` + if (typeof path === 'string') return `/${encodeURIComponent(path)}` + return `/${path.map(p => encodeURIComponent(p)).join('/')}` } return '/' } -const fetcher = (url: string) => axios.get(url).then(res => res.data) +const fetcher = (url: string) => { + console.log(url) + return axios.get(url).then(res => res.data) +} const FileListItem: FunctionComponent<{ fileContent: { id: string; name: string; size: number; file: Object; lastModifiedDateTime: string } @@ -71,7 +74,7 @@ const FileListItem: FunctionComponent<{
{/*
{c.file ? c.file.mimeType : 'folder'}
*/} -
+
{renderEmoji ? ( {emojiIcon ? emojiIcon[0] : '📁'} ) : ( @@ -82,7 +85,7 @@ const FileListItem: FunctionComponent<{ {renderEmoji ? c.name.replace(emojiIcon ? emojiIcon[0] : '', '').trim() : c.name}
-
+
{new Date(c.lastModifiedDateTime).toLocaleString('en-US', { year: 'numeric', month: '2-digit', @@ -92,7 +95,7 @@ const FileListItem: FunctionComponent<{ hour12: false, })}
-
{humanFileSize(c.size)}
+
{humanFileSize(c.size)}
) } @@ -105,7 +108,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = const path = queryToPath(query) - const { data, error } = useSWR(`/api?path=${encodeURIComponent(path)}`, fetcher, { + const { data, error } = useSWR(`/api?path=${path}`, fetcher, { revalidateOnFocus: false, }) @@ -216,12 +219,14 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) =
{ + e.preventDefault() + if (!c.folder && fileIsImage(c.name)) { setActiveImageIdx(imageIndexDict[c.id]) setImageViewerVisibility(true) } else { - e.preventDefault() - router.push(`${path === '/' ? '' : path}/${c.name}`) + console.log(path) + router.push(`${path === '/' ? '' : path}/${encodeURIComponent(c.name)}`) } }} >