2022-02-10 14:32:50 +00:00
|
|
|
import { getExtension } from './getFileIcon'
|
|
|
|
|
2022-01-26 07:40:21 +00:00
|
|
|
export const preview = {
|
2021-06-23 22:51:23 +00:00
|
|
|
markdown: 'markdown',
|
|
|
|
image: 'image',
|
|
|
|
text: 'text',
|
|
|
|
pdf: 'pdf',
|
|
|
|
code: 'code',
|
|
|
|
video: 'video',
|
|
|
|
audio: 'audio',
|
2021-06-29 15:20:35 +00:00
|
|
|
office: 'ms-office',
|
2021-10-05 21:28:40 +00:00
|
|
|
epub: 'epub',
|
2022-01-08 07:27:39 +00:00
|
|
|
url: 'url',
|
2021-06-23 22:51:23 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 07:40:21 +00:00
|
|
|
export const extensions = {
|
2021-06-23 22:51:23 +00:00
|
|
|
gif: preview.image,
|
|
|
|
jpeg: preview.image,
|
|
|
|
jpg: preview.image,
|
|
|
|
png: preview.image,
|
|
|
|
webp: preview.image,
|
|
|
|
|
|
|
|
md: preview.markdown,
|
|
|
|
markdown: preview.markdown,
|
|
|
|
mdown: preview.markdown,
|
|
|
|
|
|
|
|
pdf: preview.pdf,
|
|
|
|
|
2021-06-29 15:20:35 +00:00
|
|
|
doc: preview.office,
|
|
|
|
docx: preview.office,
|
|
|
|
ppt: preview.office,
|
|
|
|
pptx: preview.office,
|
|
|
|
xls: preview.office,
|
|
|
|
xlsx: preview.office,
|
|
|
|
|
2021-06-23 22:51:23 +00:00
|
|
|
c: preview.code,
|
|
|
|
cpp: preview.code,
|
|
|
|
js: preview.code,
|
2022-01-26 07:40:21 +00:00
|
|
|
jsx: preview.code,
|
2021-06-23 22:51:23 +00:00
|
|
|
java: preview.code,
|
|
|
|
sh: preview.code,
|
|
|
|
cs: preview.code,
|
|
|
|
py: preview.code,
|
|
|
|
css: preview.code,
|
|
|
|
html: preview.code,
|
2022-01-26 07:40:21 +00:00
|
|
|
// typescript or video file, determined below
|
2021-06-23 22:51:23 +00:00
|
|
|
ts: preview.code,
|
2022-01-26 07:40:21 +00:00
|
|
|
tsx: preview.code,
|
|
|
|
rs: preview.code,
|
2021-06-23 22:51:23 +00:00
|
|
|
vue: preview.code,
|
|
|
|
json: preview.code,
|
2022-02-10 14:32:50 +00:00
|
|
|
yml: preview.code,
|
2021-06-23 22:51:23 +00:00
|
|
|
yaml: preview.code,
|
|
|
|
toml: preview.code,
|
|
|
|
|
|
|
|
txt: preview.text,
|
2022-02-04 11:53:36 +00:00
|
|
|
vtt: preview.text,
|
|
|
|
srt: preview.text,
|
|
|
|
log: preview.text,
|
|
|
|
diff: preview.text,
|
2021-06-23 22:51:23 +00:00
|
|
|
|
|
|
|
mp4: preview.video,
|
|
|
|
flv: preview.video,
|
|
|
|
webm: preview.video,
|
|
|
|
m3u8: preview.video,
|
|
|
|
mkv: preview.video,
|
2022-01-10 10:52:45 +00:00
|
|
|
mov: preview.video,
|
2021-09-04 14:15:09 +00:00
|
|
|
avi: preview.video, // won't work!
|
2021-06-23 22:51:23 +00:00
|
|
|
|
|
|
|
mp3: preview.audio,
|
|
|
|
m4a: preview.audio,
|
|
|
|
aac: preview.audio,
|
|
|
|
wav: preview.audio,
|
|
|
|
ogg: preview.audio,
|
|
|
|
oga: preview.audio,
|
|
|
|
opus: preview.audio,
|
|
|
|
flac: preview.audio,
|
2021-10-05 21:28:40 +00:00
|
|
|
|
|
|
|
epub: preview.epub,
|
2022-01-08 07:27:39 +00:00
|
|
|
|
|
|
|
url: preview.url,
|
2021-06-23 22:51:23 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 07:32:36 +00:00
|
|
|
export function getPreviewType(extension: string, flags?: { video?: boolean }): string | undefined {
|
|
|
|
let previewType = extensions[extension]
|
|
|
|
if (!previewType) {
|
|
|
|
return previewType
|
|
|
|
}
|
|
|
|
|
2022-01-26 07:40:21 +00:00
|
|
|
// Files with '.ts' extensions may be TypeScript files or TS Video files, we check for the flag 'video'
|
|
|
|
// to determine what preview renderer to use for '.ts' files.
|
2022-01-24 07:32:36 +00:00
|
|
|
if (extension === 'ts') {
|
|
|
|
if (flags?.video) {
|
|
|
|
previewType = preview.video
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return previewType
|
|
|
|
}
|
2022-02-10 14:32:50 +00:00
|
|
|
|
|
|
|
export function getLanguageByFileName(filename: string): string {
|
|
|
|
const extension = getExtension(filename)
|
|
|
|
switch (extension) {
|
|
|
|
case 'ts':
|
|
|
|
case 'tsx':
|
|
|
|
return 'typescript'
|
|
|
|
case 'rs':
|
|
|
|
return 'rust'
|
|
|
|
case 'js':
|
|
|
|
case 'jsx':
|
|
|
|
return 'javascript'
|
|
|
|
case 'sh':
|
|
|
|
return 'shell'
|
|
|
|
case 'cs':
|
|
|
|
return 'csharp'
|
|
|
|
case 'py':
|
|
|
|
return 'python'
|
|
|
|
case 'yml':
|
|
|
|
return 'yaml'
|
|
|
|
default:
|
|
|
|
return extension
|
|
|
|
}
|
|
|
|
}
|