Fix handling of filename extensions when there is no extension and incorrectly trying to display preview images for folders.
This commit is contained in:
parent
1b12ae86de
commit
e84c665e7c
@ -37,21 +37,24 @@ export class Doc {
|
|||||||
return this.url.replace(/^\/#/, '')
|
return this.url.replace(/^\/#/, '')
|
||||||
}
|
}
|
||||||
get img(): boolean {
|
get img(): boolean {
|
||||||
const ext = this.name.split('.').pop()?.toLowerCase() || ''
|
// Folders cannot be images
|
||||||
return ['jpg', 'jpeg', 'png', 'gif', 'webp', 'avif', 'heic', 'heif', 'svg'].includes(ext)
|
if (this.dir) return false
|
||||||
|
return ['jpg', 'jpeg', 'png', 'gif', 'webp', 'avif', 'heic', 'heif', 'svg'].includes(this.ext)
|
||||||
}
|
}
|
||||||
get previewable(): boolean {
|
get previewable(): boolean {
|
||||||
|
// Folders cannot be previewable
|
||||||
|
if (this.dir) return false
|
||||||
if (this.img) return true
|
if (this.img) return true
|
||||||
const ext = this.name.split('.').pop()?.toLowerCase() || ''
|
|
||||||
// Not a comprehensive list, but good enough for now
|
// Not a comprehensive list, but good enough for now
|
||||||
return ['mp4', 'mkv', 'webm', 'ogg', 'mp3', 'flac', 'aac', 'pdf'].includes(ext)
|
return ['mp4', 'mkv', 'webm', 'ogg', 'mp3', 'flac', 'aac', 'pdf'].includes(this.ext)
|
||||||
}
|
}
|
||||||
get previewurl(): string {
|
get previewurl(): string {
|
||||||
return this.url.replace(/^\/files/, '/preview')
|
return this.url.replace(/^\/files/, '/preview')
|
||||||
}
|
}
|
||||||
get ext(): string {
|
get ext(): string {
|
||||||
const ext = this.name.split('.').pop()
|
const dotIndex = this.name.lastIndexOf('.')
|
||||||
return ext ? ext.toLowerCase() : ''
|
if (dotIndex === -1 || dotIndex === this.name.length - 1) return ''
|
||||||
|
return this.name.slice(dotIndex + 1).toLowerCase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export type errorEvent = {
|
export type errorEvent = {
|
||||||
|
@ -50,12 +50,11 @@ export function formatUnixDate(t: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getFileExtension(filename: string) {
|
export function getFileExtension(filename: string) {
|
||||||
const parts = filename.split('.')
|
const dotIndex = filename.lastIndexOf('.')
|
||||||
if (parts.length > 1) {
|
if (dotIndex === -1 || dotIndex === filename.length - 1) {
|
||||||
return parts[parts.length - 1]
|
return '' // No extension
|
||||||
} else {
|
|
||||||
return '' // No hay extensión
|
|
||||||
}
|
}
|
||||||
|
return filename.slice(dotIndex + 1)
|
||||||
}
|
}
|
||||||
interface FileTypes {
|
interface FileTypes {
|
||||||
[key: string]: string[]
|
[key: string]: string[]
|
||||||
@ -68,8 +67,9 @@ const filetypes: FileTypes = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getFileType(name: string): string {
|
export function getFileType(name: string): string {
|
||||||
const ext = name.split('.').pop()?.toLowerCase()
|
const dotIndex = name.lastIndexOf('.')
|
||||||
if (!ext || ext.length === name.length) return 'unknown'
|
if (dotIndex === -1 || dotIndex === name.length - 1) return 'unknown'
|
||||||
|
const ext = name.slice(dotIndex + 1).toLowerCase()
|
||||||
return Object.keys(filetypes).find(type => filetypes[type].includes(ext)) || 'unknown'
|
return Object.keys(filetypes).find(type => filetypes[type].includes(ext)) || 'unknown'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user