Initial commit
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { FileEntry } from '#base_modules/FileManager/types/entries'
|
||||
|
||||
const PREVIEWABLE_TEXT_EXTENSIONS = ['txt', 'md', 'log', 'json', 'csv']
|
||||
|
||||
export default class FilePreviewService {
|
||||
public async withPreview(
|
||||
entry: FileEntry,
|
||||
getContent: () => Promise<string>
|
||||
): Promise<FileEntry & { content?: string }> {
|
||||
if (!this.isPreviewableTextFile(entry.name)) return entry
|
||||
|
||||
const content = await getContent()
|
||||
|
||||
return { ...entry, content }
|
||||
}
|
||||
|
||||
private isPreviewableTextFile(name: string): boolean {
|
||||
const fileExt = name.split('.').pop()?.toLowerCase()
|
||||
|
||||
return PREVIEWABLE_TEXT_EXTENSIONS.includes(fileExt as string)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user