From 3ed3612047c4f115da9bafc7aaaefd0ab19ec430 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 18 Mar 2015 13:54:43 -0400 Subject: [PATCH] file upload with spaces / general file upload fix wrt ajaxiy --- public/src/ajaxify.js | 11 +++++++++++ src/file.js | 13 +++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 75e341643e..0c4e191532 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -25,6 +25,8 @@ $(document).ready(function() { ajaxify.go = function (url, callback, quiet) { if (ajaxify.handleACPRedirect(url)) { return true; + } else if (ajaxify.handleNonAPIRoutes(url)) { + return true; } app.enterRoom(''); @@ -71,6 +73,15 @@ $(document).ready(function() { return false; }; + ajaxify.handleNonAPIRoutes = function(url) { + url = ajaxify.removeRelativePath(url.replace(/\/$/, '')); + if (url.indexOf('uploads') === 0) { + window.open(RELATIVE_PATH + '/' + url, '_blank'); + return true; + } + return false; + }; + ajaxify.start = function(url, quiet, search) { url = ajaxify.removeRelativePath(url.replace(/\/$/, '')); var hash = window.location.hash; diff --git a/src/file.js b/src/file.js index c98da6c761..6be1cd37c8 100644 --- a/src/file.js +++ b/src/file.js @@ -8,11 +8,20 @@ var fs = require('fs'), Magic = mmmagic.Magic, mime = require('mime'), - meta= require('./meta'); + meta = require('./meta'), + utils = require('../public/src/utils'); var file = {}; file.saveFileToLocal = function(filename, folder, tempPath, callback) { + /* + * remarkable doesn't allow spaces in hyperlinks, once that's fixed, remove this. + */ + filename = filename.split('.'); + filename.forEach(function(name, idx) { + filename[idx] = utils.slugify(name); + }); + filename = filename.join('.'); var uploadPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), folder, filename); @@ -23,7 +32,7 @@ file.saveFileToLocal = function(filename, folder, tempPath, callback) { is.on('end', function () { callback(null, { - url: nconf.get('upload_url') + folder + '/' + encodeURIComponent(filename) + url: nconf.get('upload_url') + folder + '/' + filename }); });