Skip to content

Commit 05ae982

Browse files
committed
fix to use images with whitespaces
1 parent 4bd38ff commit 05ae982

4 files changed

Lines changed: 23 additions & 19 deletions

File tree

app.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,16 @@ app.post('/upload', function(req, res){
280280
}
281281

282282
fs.readFile(req.files.savefile.path, function (err, data) {
283-
var newPath = __dirname + '/public/uploads/' + req.files.savefile.name;
283+
284+
// needs to remove whitespaces (replace with _), since the
285+
// file name is going to be used as an URL by the mobile
286+
var filename = req.files.savefile.name.replace(/ /g,'_');
287+
288+
var newPath = __dirname + '/public/uploads/' + filename;
284289
console.log(newPath);
285290
fs.writeFile(newPath, data, function (err) {
286291
console.log(err);
287-
res.send(req.files.savefile.name);
292+
res.send(filename);
288293
});
289294
});
290295

@@ -383,8 +388,8 @@ io.sockets.on('connection', function(socket) {
383388
io.sockets.in('mobile').emit('downloadResourceFromWeb', data);
384389
});
385390

386-
socket.on('resourceSaved', function(message) {
387-
io.sockets.in('webapp').emit('resourceSaved', message);
391+
socket.on('resourceSaved', function(message, filename) {
392+
io.sockets.in('webapp').emit('resourceSaved', message, filename);
388393
});
389394

390395
socket.on('getListResources', function() {

public/js/libs/main.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208
//
209209
$('#resourceModalSave').click(function() {
210210
socket.emit('downloadResourceFromWeb', {url : $('#inputUrlResource').val(), filename : $('#inputFilenameResource').val() });
211-
CodeMirror.resourceImages().push('resources/' + response);
211+
LiveUtils.showFlashMessage('Downloading resource...', 10000);
212212
});
213213

214214
//-------------------------------------------------------
@@ -235,18 +235,16 @@
235235
//
236236
$('#upload').submit(function(e) {
237237
e.preventDefault();
238+
LiveUtils.showFlashMessage('Downloading resource...');
238239

239240
$(this).ajaxSubmit({
240241
success: function(response) {
241242
if(response.error) {
242243
status('Opps, something bad happened');
243244
return;
244245
}
245-
// alert('file uploaded!');
246246
$('#downloadResourceModal').modal('hide');
247247
socket.emit('downloadResourceFromServer', response);
248-
249-
CodeMirror.resourceImages().push('resources/' + response);
250248
}
251249
});
252250

@@ -258,7 +256,8 @@
258256
// Alert the user with the result of an attempt to save
259257
// a new file resurce on the device
260258
//
261-
socket.on('resourceSaved', function(message) {
259+
socket.on('resourceSaved', function(message, filename) {
260+
CodeMirror.resourceImages().push('resources/' + filename);
262261
LiveUtils.showFlashMessage(message);
263262
});
264263

@@ -359,12 +358,16 @@ var LiveUtils = (function() {
359358
var LiveUtils = {};
360359

361360
// When a gist file is saved, give feedback to the user
362-
LiveUtils.showFlashMessage = function(message) {
361+
LiveUtils.showFlashMessage = function(message, duration) {
363362
LiveUtils.hideLoadIndicator();
364363
$('#flashMessage').html(message);
365-
$('#flashMessage').fadeIn(1000, function() {
366-
$('#flashMessage').fadeOut(3000);
367-
});
364+
if(duration) {
365+
$('#flashMessage').fadeIn(1000);
366+
} else {
367+
$('#flashMessage').fadeIn(1000, function() {
368+
$('#flashMessage').fadeOut(3000);
369+
});
370+
}
368371
};
369372

370373
// helper functions to show and hide a load indicator

public/js/libs/mobilejs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
'http://' + _serverip + ':5678/uploads/' + filename,
9494
filename
9595
], function(message) {
96-
socket.emit('resourceSaved', message);
96+
socket.emit('resourceSaved', message, filename);
9797
});
9898
});
9999

@@ -104,7 +104,7 @@
104104
data.url,
105105
data.filename
106106
], function(message) {
107-
socket.emit('resourceSaved', message);
107+
socket.emit('resourceSaved', message, data.filename);
108108
});
109109
});
110110

public/js/vendors/Color.Picker.Classic.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,11 @@ Color.Picker = function (props) {
230230
/// helper functions
231231

232232
this.update = function(color) { // accepts HEX, RGB, and HSV
233-
console.log('color in update:', color);
234233
if (typeof(color) === "string") {
235-
console.log('string');
236234
that.color = Color.Space(color, "STRING>HEX>RGB>HSV");
237235
} else if (typeof(color.R) !== "undefined") {
238-
console.log('color.R undefined');
239236
that.color = Color.Space(color, "RGB>HSV");
240237
} else if (typeof(color.H) !== "undefined") {
241-
console.log('color.H undefined');
242238
that.color = color;
243239
}
244240
///

0 commit comments

Comments
 (0)