]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/commitdiff
Add file preview
authorJohannes Zellner <johannes@nebulon.de>
Tue, 1 Mar 2016 17:16:31 +0000 (18:16 +0100)
committerJohannes Zellner <johannes@nebulon.de>
Tue, 1 Mar 2016 17:16:31 +0000 (18:16 +0100)
app/css/style.css
app/img/directory.png [new file with mode: 0644]
app/img/html.png [new file with mode: 0644]
app/img/image.png [new file with mode: 0644]
app/img/pdf.png [new file with mode: 0644]
app/img/text.png [new file with mode: 0644]
app/img/unknown.png [new file with mode: 0644]
app/img/video.png [new file with mode: 0644]
app/index.html
app/js/app.js

index b7e57423e86267d47c4a1c62753fa94f827474c4..13c65334ee3c23541de00e60b6f396e7791a7f85 100644 (file)
@@ -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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
index 0000000..6c01aea
Binary files /dev/null and b/app/img/video.png differ
index 4557fcbaed864d625d6931ac0c64f4b70fbcdb65..f6c91c9ff05d52df53c48a71bff0ac5fb94a4c4d 100644 (file)
                         </tr>
                         <tr v-for="entry in entries" v-on:click="open(entry)" class="hand">
                             <th>
-                                <i class="fa fa-folder-o" v-show="entry.isDirectory"></i>
-                                <i class="fa fa-file-o" v-show="entry.isFile"></i>
+                                <img v-bind:src="entry.previewUrl" height="48px" width="48px"/>
                             </th>
                             <th>{{ entry.filePath }}</th>
                             <th>{{ entry.size }}</th>
index 0d6144e37c53023e44f2a2171f1649de2948249b..c942e605b903734021e35a5252b4aba557b9334d 100644 (file)
@@ -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; });