Commit a26d1f9b by Johannes Zellner

Add file preview

1 parent 4e56a318
...@@ -33,3 +33,7 @@ pre { ...@@ -33,3 +33,7 @@ pre {
.hand { .hand {
cursor: hand; cursor: hand;
} }
th {
vertical-align: middle !important;
}
\ No newline at end of file
...@@ -138,8 +138,7 @@ ...@@ -138,8 +138,7 @@
</tr> </tr>
<tr v-for="entry in entries" v-on:click="open(entry)" class="hand"> <tr v-for="entry in entries" v-on:click="open(entry)" class="hand">
<th> <th>
<i class="fa fa-folder-o" v-show="entry.isDirectory"></i> <img v-bind:src="entry.previewUrl" height="48px" width="48px"/>
<i class="fa fa-file-o" v-show="entry.isFile"></i>
</th> </th>
<th>{{ entry.filePath }}</th> <th>{{ entry.filePath }}</th>
<th>{{ entry.size }}</th> <th>{{ entry.size }}</th>
......
...@@ -43,6 +43,27 @@ function encode(filePath) { ...@@ -43,6 +43,27 @@ function encode(filePath) {
return filePath.split('/').map(encodeURIComponent).join('/'); 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() { function refresh() {
loadDirectory(app.path); loadDirectory(app.path);
} }
...@@ -60,7 +81,10 @@ function loadDirectory(filePath) { ...@@ -60,7 +81,10 @@ function loadDirectory(filePath) {
if (error) return console.error(error); if (error) return console.error(error);
if (result.statusCode === 401) return logout(); 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.path = filePath;
app.pathParts = filePath.split('/').filter(function (e) { return !!e; }); app.pathParts = filePath.split('/').filter(function (e) { return !!e; });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!