aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/js/app.js
diff options
context:
space:
mode:
authorJohannes Zellner <johannes@nebulon.de>2016-03-01 18:16:31 +0100
committerJohannes Zellner <johannes@nebulon.de>2016-03-01 18:16:31 +0100
commita26d1f9bb76493767bceaecffcb6d39b4f5aac7a (patch)
treedf815b9c31d0e9b67da43731764603f2ad86160c /app/js/app.js
parent4e56a31834d75e0acd9440e39e1b39b3f94f1e54 (diff)
downloadSurfer-a26d1f9bb76493767bceaecffcb6d39b4f5aac7a.tar.gz
Surfer-a26d1f9bb76493767bceaecffcb6d39b4f5aac7a.tar.zst
Surfer-a26d1f9bb76493767bceaecffcb6d39b4f5aac7a.zip
Add file preview
Diffstat (limited to 'app/js/app.js')
-rw-r--r--app/js/app.js26
1 files changed, 25 insertions, 1 deletions
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) {
43 return filePath.split('/').map(encodeURIComponent).join('/'); 43 return filePath.split('/').map(encodeURIComponent).join('/');
44} 44}
45 45
46var mimeTypes = {
47 images: [ '.png', '.jpg', '.jpeg', '.tiff', '.gif' ],
48 text: [ '.txt', '.md' ],
49 pdf: [ '.pdf' ],
50 html: [ '.html', '.htm', '.php' ],
51 video: [ '.mp4', '.mpg', '.mpeg', '.ogg', '.mkv' ]
52};
53
54function getPreviewUrl(entry, basePath) {
55 var path = '/_admin/img/';
56
57 if (entry.isDirectory) return path + 'directory.png';
58 if (mimeTypes.images.some(function (e) { return entry.filePath.endsWith(e); })) return sanitize(basePath + '/' + entry.filePath);
59 if (mimeTypes.text.some(function (e) { return entry.filePath.endsWith(e); })) return path +'text.png';
60 if (mimeTypes.pdf.some(function (e) { return entry.filePath.endsWith(e); })) return path + 'pdf.png';
61 if (mimeTypes.html.some(function (e) { return entry.filePath.endsWith(e); })) return path + 'html.png';
62 if (mimeTypes.video.some(function (e) { return entry.filePath.endsWith(e); })) return path + 'video.png';
63
64 return path + 'unknown.png';
65}
66
46function refresh() { 67function refresh() {
47 loadDirectory(app.path); 68 loadDirectory(app.path);
48} 69}
@@ -60,7 +81,10 @@ function loadDirectory(filePath) {
60 if (error) return console.error(error); 81 if (error) return console.error(error);
61 if (result.statusCode === 401) return logout(); 82 if (result.statusCode === 401) return logout();
62 83
63 app.entries = result.body.entries; 84 app.entries = result.body.entries.map(function (entry) {
85 entry.previewUrl = getPreviewUrl(entry, filePath);
86 return entry;
87 });
64 app.path = filePath; 88 app.path = filePath;
65 app.pathParts = filePath.split('/').filter(function (e) { return !!e; }); 89 app.pathParts = filePath.split('/').filter(function (e) { return !!e; });
66 90