diff options
Diffstat (limited to 'app/js')
-rw-r--r-- | app/js/app.js | 26 |
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 | ||
46 | var 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 | |||
54 | function 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 | |||
46 | function refresh() { | 67 | function 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 | ||