Preserve original ext and skip folders when extracting extensions (#448)

This commit is contained in:
myl7
2022-02-15 19:27:47 +08:00
committed by GitHub
parent e24a602d46
commit 81d0cad71c
4 changed files with 10 additions and 7 deletions
+4 -4
View File
@@ -12,7 +12,7 @@ import { useTranslation } from 'next-i18next'
import useLocalStorage from '../utils/useLocalStorage' import useLocalStorage from '../utils/useLocalStorage'
import { getPreviewType, preview } from '../utils/getPreviewType' import { getPreviewType, preview } from '../utils/getPreviewType'
import { useProtectedSWRInfinite } from '../utils/fetchWithSWR' import { useProtectedSWRInfinite } from '../utils/fetchWithSWR'
import { getExtension, getFileIcon } from '../utils/getFileIcon' import { getExtension, getRawExtension, getFileIcon } from '../utils/getFileIcon'
import { getStoredToken } from '../utils/protectedRouteHandler' import { getStoredToken } from '../utils/protectedRouteHandler'
import { import {
DownloadingToast, DownloadingToast,
@@ -70,10 +70,10 @@ const formatChildName = (name: string) => {
const { render, emoji } = renderEmoji(name) const { render, emoji } = renderEmoji(name)
return render ? name.replace(emoji ? emoji[0] : '', '').trim() : name return render ? name.replace(emoji ? emoji[0] : '', '').trim() : name
} }
export const ChildName: FC<{ name: string }> = ({ name }) => { export const ChildName: FC<{ name: string; folder?: boolean }> = ({ name, folder }) => {
const original = formatChildName(name) const original = formatChildName(name)
const extension = getExtension(original) const extension = folder ? '' : getRawExtension(original)
const prename = original.substring(0, original.length - extension.length) const prename = folder ? original : original.substring(0, original.length - extension.length)
return ( return (
<span className="truncate before:float-right before:content-[attr(data-tail)]" data-tail={extension}> <span className="truncate before:float-right before:content-[attr(data-tail)]" data-tail={extension}>
{prename} {prename}
+1 -1
View File
@@ -46,7 +46,7 @@ const GridItem = ({ c, path }: { c: OdFolderChildren; path: string }) => {
<span className="w-5 flex-shrink-0 text-center"> <span className="w-5 flex-shrink-0 text-center">
<ChildIcon child={c} /> <ChildIcon child={c} />
</span> </span>
<ChildName name={c.name} /> <ChildName name={c.name} folder={Boolean(c.folder)} />
</div> </div>
<div className="truncate text-center font-mono text-xs text-gray-700 dark:text-gray-500"> <div className="truncate text-center font-mono text-xs text-gray-700 dark:text-gray-500">
{formatModifiedDateTime(c.lastModifiedDateTime)} {formatModifiedDateTime(c.lastModifiedDateTime)}
+1 -1
View File
@@ -20,7 +20,7 @@ const FileListItem: FC<{ fileContent: OdFolderChildren }> = ({ fileContent: c })
<div className="w-5 flex-shrink-0 text-center"> <div className="w-5 flex-shrink-0 text-center">
<ChildIcon child={c} /> <ChildIcon child={c} />
</div> </div>
<ChildName name={c.name} /> <ChildName name={c.name} folder={Boolean(c.folder)} />
</div> </div>
<div className="col-span-3 hidden flex-shrink-0 font-mono text-sm text-gray-700 dark:text-gray-500 md:block"> <div className="col-span-3 hidden flex-shrink-0 font-mono text-sm text-gray-700 dark:text-gray-500 md:block">
{formatModifiedDateTime(c.lastModifiedDateTime)} {formatModifiedDateTime(c.lastModifiedDateTime)}
+4 -1
View File
@@ -105,8 +105,11 @@ export function hasKey<O>(obj: O, key: PropertyKey): key is keyof O {
return key in obj return key in obj
} }
export function getRawExtension(fileName: string): string {
return fileName.slice(((fileName.lastIndexOf('.') - 1) >>> 0) + 2)
}
export function getExtension(fileName: string): string { export function getExtension(fileName: string): string {
return fileName.slice(((fileName.lastIndexOf('.') - 1) >>> 0) + 2).toLowerCase() return getRawExtension(fileName).toLowerCase()
} }
export function getFileIcon(fileName: string, flags?: { video?: boolean }): [IconPrefix, IconName] { export function getFileIcon(fileName: string, flags?: { video?: boolean }): [IconPrefix, IconName] {