From 701cf9dc95aca5c05a13c72d9988007e9c9f9704 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 17 Dec 2021 12:57:25 -0700 Subject: [PATCH] improve icon/ext support --- json/extensions.json | 32 +++++++++++++++++++++++++++++--- json/icons.json | 6 +++++- scripts/fileview/fileicon.js | 6 +++--- scripts/fileview/load/load.js | 2 +- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/json/extensions.json b/json/extensions.json index 233fa28..380003e 100755 --- a/json/extensions.json +++ b/json/extensions.json @@ -1,7 +1,33 @@ { "zip": "Compressed Folder", "js": "JavaScript File", - "lnk": "Shortcut", - "url": "Shortcut", - "ini": ".ini Config File" + "lnk": "Shortcut (.lnk)", + "url": "Shortcut (.url)", + "ini": ".ini Config File", + "html": "HTML Web Document", + "css": "CSS Stylesheet", + "json": "JS Obj. Notation File", + "gitignore": "SCM Config File", + "bat": "Win. CMD Executable", + "md": "Markdown File", + "jshintrc": "JS Linter Config File", + "py": "Python Source File", + "txt": "Text File", + "docx": "Word Document", + "mp4": ".mp4 Video File", + "mp3": ".mp3 Audio File", + "ogg": "OGG Audio File", + "wav": ".wav Audio File", + "mov": ".mov Video File", + "png": "Portable Network Graphic", + "jpg": "JPG Image", + "gif": "Animated Image (.gif)", + "svg": ".svg Image", + "jar": "Java Executable", + "msi": "Windows Installer", + "exe": "Windows Application", + "pdf": "Portable Document File", + "der": "Certificate", + "7z": "Compressed Folder (7zip)", + "7zip": "Compressed Folder (7zip)" } \ No newline at end of file diff --git a/json/icons.json b/json/icons.json index c149967..6b77b35 100755 --- a/json/icons.json +++ b/json/icons.json @@ -17,7 +17,11 @@ "js": "javascript", "xlsx": "excel", "xls": "excel", - "gitignore": "git" + "gitignore": "git", + "7z": "zip", + "jar": "java", + "der": "certificate", + "py": "python" }, "folder": { diff --git a/scripts/fileview/fileicon.js b/scripts/fileview/fileicon.js index 5d19d1b..2ef385f 100755 --- a/scripts/fileview/fileicon.js +++ b/scripts/fileview/fileicon.js @@ -17,9 +17,9 @@ module.exports = (fpath, name) => { } }*/ else { - //console.log(path.extname(name)); - if (name.includes('.') && fs.existsSync(`./assets/icons/extension/${(path.extname(name).toLowerCase()).slice(1)}.svg`)) {icon = `./assets/icons/extension/${(path.extname(name).toLowerCase()).slice(1)}.svg`;} - else if (name.includes('.') && Object.keys(icons.file).includes((path.extname(name).toLowerCase()).slice(1))) {icon = `./assets/icons/extension/${icons.file[(path.extname(name).toLowerCase()).slice(1)]}.svg`;} + let ext = name.startsWith('.') ? name : path.extname(name); + if (name.includes('.') && fs.existsSync(`./assets/icons/extension/${(ext.toLowerCase()).slice(1)}.svg`)) {icon = `./assets/icons/extension/${(ext.toLowerCase()).slice(1)}.svg`;} + else if (name.includes('.') && Object.keys(icons.file).includes((ext.toLowerCase()).slice(1))) {icon = `./assets/icons/extension/${icons.file[(ext.toLowerCase()).slice(1)]}.svg`;} else {icon = './assets/icons/base/file.svg';} } } catch {icon = './assets/icons/base/file.svg';} diff --git a/scripts/fileview/load/load.js b/scripts/fileview/load/load.js index ab3ac2f..944f913 100755 --- a/scripts/fileview/load/load.js +++ b/scripts/fileview/load/load.js @@ -17,7 +17,7 @@ module.exports = (check=false) => { let ofile = {}; ofile.icon = fileIcon(`${dir}/${file}`, file); ofile.name = trimext.includes(path.extname(file)) ? file.slice(0, file.length - path.extname(file).length) : file; - try {ofile.type = fs.lstatSync(`${dir}/${file}`).isDirectory() ? "File Folder" : (extensions[path.extname(file).slice(1)] || "File");} + try {ofile.type = fs.lstatSync(`${dir}/${file}`).isDirectory() ? "File Folder" : (extensions[(file.startsWith('.') ? file : path.extname(file)).slice(1)] || "File");} catch {ofile.type = `${path.extname(file)} File`.trim();} try {ofile.lastModified = new Date(fs.lstatSync(`${dir}/${file}`).mtimeMs);} catch {ofile.lastModified = 0;}