From: Johannes Zellner Date: Tue, 1 Mar 2016 17:16:31 +0000 (+0100) Subject: Add file preview X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=a26d1f9bb76493767bceaecffcb6d39b4f5aac7a;p=perso%2FImmae%2FProjets%2FNodejs%2FSurfer.git Add file preview --- diff --git a/app/css/style.css b/app/css/style.css index b7e5742..13c6533 100644 --- a/app/css/style.css +++ b/app/css/style.css @@ -32,4 +32,8 @@ pre { .hand { cursor: hand; +} + +th { + vertical-align: middle !important; } \ No newline at end of file diff --git a/app/img/directory.png b/app/img/directory.png new file mode 100644 index 0000000..8630079 Binary files /dev/null and b/app/img/directory.png differ diff --git a/app/img/html.png b/app/img/html.png new file mode 100644 index 0000000..51153ea Binary files /dev/null and b/app/img/html.png differ diff --git a/app/img/image.png b/app/img/image.png new file mode 100644 index 0000000..22939ff Binary files /dev/null and b/app/img/image.png differ diff --git a/app/img/pdf.png b/app/img/pdf.png new file mode 100644 index 0000000..95e2308 Binary files /dev/null and b/app/img/pdf.png differ diff --git a/app/img/text.png b/app/img/text.png new file mode 100644 index 0000000..daf010d Binary files /dev/null and b/app/img/text.png differ diff --git a/app/img/unknown.png b/app/img/unknown.png new file mode 100644 index 0000000..c5dac42 Binary files /dev/null and b/app/img/unknown.png differ diff --git a/app/img/video.png b/app/img/video.png new file mode 100644 index 0000000..6c01aea Binary files /dev/null and b/app/img/video.png differ diff --git a/app/index.html b/app/index.html index 4557fcb..f6c91c9 100644 --- a/app/index.html +++ b/app/index.html @@ -138,8 +138,7 @@ - - + {{ entry.filePath }} {{ entry.size }} diff --git a/app/js/app.js b/app/js/app.js index 0d6144e..c942e60 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -43,6 +43,27 @@ function encode(filePath) { return filePath.split('/').map(encodeURIComponent).join('/'); } +var mimeTypes = { + images: [ '.png', '.jpg', '.jpeg', '.tiff', '.gif' ], + text: [ '.txt', '.md' ], + pdf: [ '.pdf' ], + html: [ '.html', '.htm', '.php' ], + video: [ '.mp4', '.mpg', '.mpeg', '.ogg', '.mkv' ] +}; + +function getPreviewUrl(entry, basePath) { + var path = '/_admin/img/'; + + if (entry.isDirectory) return path + 'directory.png'; + if (mimeTypes.images.some(function (e) { return entry.filePath.endsWith(e); })) return sanitize(basePath + '/' + entry.filePath); + if (mimeTypes.text.some(function (e) { return entry.filePath.endsWith(e); })) return path +'text.png'; + if (mimeTypes.pdf.some(function (e) { return entry.filePath.endsWith(e); })) return path + 'pdf.png'; + if (mimeTypes.html.some(function (e) { return entry.filePath.endsWith(e); })) return path + 'html.png'; + if (mimeTypes.video.some(function (e) { return entry.filePath.endsWith(e); })) return path + 'video.png'; + + return path + 'unknown.png'; +} + function refresh() { loadDirectory(app.path); } @@ -60,7 +81,10 @@ function loadDirectory(filePath) { if (error) return console.error(error); if (result.statusCode === 401) return logout(); - app.entries = result.body.entries; + app.entries = result.body.entries.map(function (entry) { + entry.previewUrl = getPreviewUrl(entry, filePath); + return entry; + }); app.path = filePath; app.pathParts = filePath.split('/').filter(function (e) { return !!e; });