diff options
author | Johannes <johannes@cloudron.io> | 2016-11-15 16:56:03 +0100 |
---|---|---|
committer | Johannes <johannes@cloudron.io> | 2016-11-15 16:56:03 +0100 |
commit | ecfbca9fd86e73ab6ae949e49578906ceda12a5b (patch) | |
tree | 78475109ce3420d16d46db812a00572e5efb96ad | |
parent | 5be531a3b6df5ab59065ccc534b774261b3ad622 (diff) | |
download | Surfer-ecfbca9fd86e73ab6ae949e49578906ceda12a5b.tar.gz Surfer-ecfbca9fd86e73ab6ae949e49578906ceda12a5b.tar.zst Surfer-ecfbca9fd86e73ab6ae949e49578906ceda12a5b.zip |
Support multifile upload via the webinterface
-rw-r--r-- | app/index.html | 2 | ||||
-rw-r--r-- | app/js/app.js | 33 |
2 files changed, 23 insertions, 12 deletions
diff --git a/app/index.html b/app/index.html index b1c7da6..80f9bdd 100644 --- a/app/index.html +++ b/app/index.html | |||
@@ -108,7 +108,7 @@ | |||
108 | <div class="col-lg-12"> | 108 | <div class="col-lg-12"> |
109 | <center> | 109 | <center> |
110 | <form id="fileUploadForm"> | 110 | <form id="fileUploadForm"> |
111 | <input type="file" v-el:upload style="display: none" id="uploadInput"/> | 111 | <input type="file" v-el:upload style="display: none" id="uploadInput" multiple/> |
112 | <button class="btn btn-primary" v-on:click.stop.prevent="upload()" id="uploadButton">Upload</button> | 112 | <button class="btn btn-primary" v-on:click.stop.prevent="upload()" id="uploadButton">Upload</button> |
113 | </form> | 113 | </form> |
114 | </center> | 114 | </center> |
diff --git a/app/js/app.js b/app/js/app.js index 739e9b1..9a2e532 100644 --- a/app/js/app.js +++ b/app/js/app.js | |||
@@ -129,21 +129,32 @@ function upload() { | |||
129 | // detach event handler | 129 | // detach event handler |
130 | $(app.$els.upload).off('change'); | 130 | $(app.$els.upload).off('change'); |
131 | 131 | ||
132 | var file = app.$els.upload.files[0]; | 132 | var length = app.$els.upload.files.length; |
133 | var path = encode(sanitize(app.path + '/' + file.name)); | 133 | var done = 0; |
134 | 134 | ||
135 | var formData = new FormData(); | 135 | function uploadFile(file) { |
136 | formData.append('file', file); | 136 | var path = encode(sanitize(app.path + '/' + file.name)); |
137 | 137 | ||
138 | superagent.put('/api/files' + path).query({ username: app.session.username, password: app.session.password }).send(formData).end(function (error, result) { | 138 | var formData = new FormData(); |
139 | app.busy = false; | 139 | formData.append('file', file); |
140 | 140 | ||
141 | if (result && result.statusCode === 401) return logout(); | 141 | superagent.put('/api/files' + path).query({ username: app.session.username, password: app.session.password }).send(formData).end(function (error, result) { |
142 | if (result && result.statusCode !== 201) return console.error('Error uploading file: ', result.statusCode); | 142 | if (result && result.statusCode === 401) return logout(); |
143 | if (error) return console.error(error); | 143 | if (result && result.statusCode !== 201) console.error('Error uploading file: ', result.statusCode); |
144 | if (error) console.error(error); | ||
144 | 145 | ||
145 | refresh(); | 146 | ++done; |
146 | }); | 147 | |
148 | if (done >= length) { | ||
149 | app.busy = false; | ||
150 | refresh(); | ||
151 | } | ||
152 | }); | ||
153 | } | ||
154 | |||
155 | for(var i = 0; i < length; i++) { | ||
156 | uploadFile(app.$els.upload.files[i]); | ||
157 | } | ||
147 | }); | 158 | }); |
148 | 159 | ||
149 | // reset the form first to make the change handler retrigger even on the same file selected | 160 | // reset the form first to make the change handler retrigger even on the same file selected |