Improve sftp visual effects

This commit is contained in:
cfs4819
2024-01-23 12:27:49 +08:00
parent 266dfe15a3
commit cf09d95602

View File

@@ -81,43 +81,42 @@ export class SFTPPanelComponent {
a.name.localeCompare(b.name)) a.name.localeCompare(b.name))
} }
getFileType(fileExtension: string): string { getFileType (fileExtension: string): string {
const codeExtensions = ["js", "ts", "py", "java", "cpp", "h", "cs", "html", "css", "rb", "php", "swift", "go", "kt", "sh", "json", "cc", const codeExtensions = ['js', 'ts', 'py', 'java', 'cpp', 'h', 'cs', 'html', 'css', 'rb', 'php', 'swift', 'go', 'kt', 'sh', 'json', 'cc', 'c', 'xml']
"c", "xml"]; const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp']
const imageExtensions = ["jpg", "jpeg", "png", "gif", "bmp"]; const pdfExtensions = ['pdf']
const pdfExtensions = ["pdf"]; const archiveExtensions = ['zip', 'rar', 'tar', 'gz']
const archiveExtensions = ["zip", "rar", "tar", "gz"]; const wordExtensions = ['doc', 'docx']
const wordExtensions = ["doc", "docx"]; const videoExtensions = ['mp4', 'avi', 'mkv', 'mov']
const videoExtensions = ["mp4", "avi", "mkv", "mov"]; const powerpointExtensions = ['ppt', 'pptx']
const powerpointExtensions = ["ppt", "pptx"]; const textExtensions = ['txt', 'log']
const textExtensions = ["txt", "log"]; const audioExtensions = ['mp3', 'wav', 'flac']
const audioExtensions = ["mp3", "wav", "flac"]; const excelExtensions = ['xls', 'xlsx']
const excelExtensions = ["xls", "xlsx"];
const lowerCaseExtension = fileExtension.toLowerCase(); const lowerCaseExtension = fileExtension.toLowerCase()
if (codeExtensions.includes(lowerCaseExtension)) { if (codeExtensions.includes(lowerCaseExtension)) {
return "code"; return 'code'
} else if (imageExtensions.includes(lowerCaseExtension)) { } else if (imageExtensions.includes(lowerCaseExtension)) {
return "image"; return 'image'
} else if (pdfExtensions.includes(lowerCaseExtension)) { } else if (pdfExtensions.includes(lowerCaseExtension)) {
return "pdf"; return 'pdf'
} else if (archiveExtensions.includes(lowerCaseExtension)) { } else if (archiveExtensions.includes(lowerCaseExtension)) {
return "archive"; return 'archive'
} else if (wordExtensions.includes(lowerCaseExtension)) { } else if (wordExtensions.includes(lowerCaseExtension)) {
return "word"; return 'word'
} else if (videoExtensions.includes(lowerCaseExtension)) { } else if (videoExtensions.includes(lowerCaseExtension)) {
return "video"; return 'video'
} else if (powerpointExtensions.includes(lowerCaseExtension)) { } else if (powerpointExtensions.includes(lowerCaseExtension)) {
return "powerpoint"; return 'powerpoint'
} else if (textExtensions.includes(lowerCaseExtension)) { } else if (textExtensions.includes(lowerCaseExtension)) {
return "text"; return 'text'
} else if (audioExtensions.includes(lowerCaseExtension)) { } else if (audioExtensions.includes(lowerCaseExtension)) {
return "audio"; return 'audio'
} else if (excelExtensions.includes(lowerCaseExtension)) { } else if (excelExtensions.includes(lowerCaseExtension)) {
return "excel"; return 'excel'
} else { } else {
return "unknown"; return 'unknown'
} }
} }
@@ -128,16 +127,16 @@ export class SFTPPanelComponent {
if (item.isSymlink) { if (item.isSymlink) {
return 'fas fa-link text-warning' return 'fas fa-link text-warning'
} }
const fileMatch = /\.([^.]+)$/.exec(item.name); const fileMatch = /\.([^.]+)$/.exec(item.name)
const extension = fileMatch?fileMatch[1]:null; const extension = fileMatch ? fileMatch[1] : null
if (extension !== null) { if (extension !== null) {
const fileType = this.getFileType(extension); const fileType = this.getFileType(extension)
switch (fileType) { switch (fileType) {
case "unknown": case 'unknown':
return 'fas fa-file'; return 'fas fa-file'
default: default:
return `fa-solid fa-file-${fileType} `; return `fa-solid fa-file-${fileType} `
} }
} }
return 'fas fa-file' return 'fas fa-file'