Integrated stackedit-download-proxy service
This commit is contained in:
parent
4b875e798a
commit
7726b46be2
20
app/download.js
Normal file
20
app/download.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
var request = require('request');
|
||||||
|
|
||||||
|
exports.importPublic = function(req, res) {
|
||||||
|
var url = req.param('url');
|
||||||
|
if(!url) {
|
||||||
|
res.send(400, 'No URL parameter');
|
||||||
|
}
|
||||||
|
else if(url.indexOf("http://") === 0 || url.indexOf("https://") === 0) {
|
||||||
|
var stream = request.get(url);
|
||||||
|
stream.on('error', function(err) {
|
||||||
|
res.send(400, err);
|
||||||
|
});
|
||||||
|
stream.on('response', function() {
|
||||||
|
stream.pipe(res);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.send(400, 'Unknown protocol');
|
||||||
|
}
|
||||||
|
};
|
@ -25,7 +25,10 @@ app.get('/viewer', function (req, res) {
|
|||||||
res.render('viewer.html');
|
res.render('viewer.html');
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/pdf', require('./pdf'));
|
app.post('/pdfExport', require('./pdf').export);
|
||||||
|
app.post('/sshPublish', require('./ssh').publish);
|
||||||
|
app.post('/picasaImportImg', require('./picasa').importImg);
|
||||||
|
app.get('/downloadImport', require('./download').importPublic);
|
||||||
|
|
||||||
// Error 404
|
// Error 404
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
|
@ -1,67 +1,68 @@
|
|||||||
define([
|
define([
|
||||||
"jquery",
|
"jquery",
|
||||||
"constants",
|
"constants",
|
||||||
"eventMgr",
|
"eventMgr",
|
||||||
"utils",
|
"utils",
|
||||||
"fileMgr",
|
"fileMgr",
|
||||||
"classes/Provider",
|
"classes/Provider",
|
||||||
"classes/AsyncTask"
|
"classes/AsyncTask"
|
||||||
], function($, constants, eventMgr, utils, fileMgr, Provider, AsyncTask) {
|
], function($, constants, eventMgr, utils, fileMgr, Provider, AsyncTask) {
|
||||||
|
|
||||||
var downloadProvider = new Provider("download");
|
var downloadProvider = new Provider("download");
|
||||||
downloadProvider.sharingAttributes = [
|
downloadProvider.sharingAttributes = [
|
||||||
"url"
|
"url"
|
||||||
];
|
];
|
||||||
|
|
||||||
downloadProvider.importPublic = function(importParameters, callback) {
|
downloadProvider.importPublic = function(importParameters, callback) {
|
||||||
var title;
|
var title;
|
||||||
var content;
|
var content;
|
||||||
var task = new AsyncTask(true);
|
var task = new AsyncTask(true);
|
||||||
task.onRun(function() {
|
task.onRun(function() {
|
||||||
var url = importParameters.url;
|
var url = importParameters.url;
|
||||||
var slashUrl = url.lastIndexOf("/");
|
var slashUrl = url.lastIndexOf("/");
|
||||||
if(slashUrl === -1) {
|
if(slashUrl === -1) {
|
||||||
task.error(new Error("Invalid URL parameter."));
|
task.error(new Error("Invalid URL parameter."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
title = url.substring(slashUrl + 1);
|
title = url.substring(slashUrl + 1);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: constants.DOWNLOAD_PROXY_URL + "download?url=" + url,
|
url: constants.DOWNLOAD_IMPORT_URL + '?' + $.param({
|
||||||
type: "GET",
|
url: url
|
||||||
dataType: "text",
|
}),
|
||||||
timeout: constants.AJAX_TIMEOUT
|
dataType: 'text',
|
||||||
}).done(function(result) {
|
timeout: constants.AJAX_TIMEOUT
|
||||||
content = result;
|
}).done(function(result) {
|
||||||
task.chain();
|
content = result;
|
||||||
}).fail(function() {
|
task.chain();
|
||||||
task.error(new Error("Unable to access URL " + url));
|
}).fail(function() {
|
||||||
});
|
task.error(new Error("Unable to access URL " + url));
|
||||||
});
|
});
|
||||||
task.onSuccess(function() {
|
});
|
||||||
callback(undefined, title, content);
|
task.onSuccess(function() {
|
||||||
});
|
callback(undefined, title, content);
|
||||||
task.onError(function(error) {
|
});
|
||||||
callback(error);
|
task.onError(function(error) {
|
||||||
});
|
callback(error);
|
||||||
task.enqueue();
|
});
|
||||||
};
|
task.enqueue();
|
||||||
|
};
|
||||||
|
|
||||||
eventMgr.addListener("onReady", function() {
|
eventMgr.addListener("onReady", function() {
|
||||||
$('.action-import-url').click(function(e) {
|
$('.action-import-url').click(function(e) {
|
||||||
var url = utils.getInputTextValue('#input-import-url', e);
|
var url = utils.getInputTextValue('#input-import-url', e);
|
||||||
if(url) {
|
if(url) {
|
||||||
downloadProvider.importPublic({
|
downloadProvider.importPublic({
|
||||||
url: url
|
url: url
|
||||||
}, function(error, title, content) {
|
}, function(error, title, content) {
|
||||||
if(error) {
|
if(error) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var fileDesc = fileMgr.createFile(title, content);
|
var fileDesc = fileMgr.createFile(title, content);
|
||||||
fileMgr.selectFile(fileDesc);
|
fileMgr.selectFile(fileDesc);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return downloadProvider;
|
return downloadProvider;
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user