2012-02-25 17:23:44 +01:00
|
|
|
var hasPadAccess = require("../../padaccess");
|
|
|
|
var settings = require('../../utils/Settings');
|
|
|
|
var exportHandler = require('../../handler/ExportHandler');
|
|
|
|
var importHandler = require('../../handler/ImportHandler');
|
2018-04-04 21:48:32 +01:00
|
|
|
var padManager = require("../../db/PadManager");
|
2012-02-25 16:06:08 +01:00
|
|
|
|
|
|
|
exports.expressCreateServer = function (hook_name, args, cb) {
|
2019-01-23 16:29:36 +00:00
|
|
|
args.app.get('/p/:pad/:rev?/export/:type', async function(req, res, next) {
|
2014-12-29 20:57:58 +01:00
|
|
|
var types = ["pdf", "doc", "txt", "html", "odt", "etherpad"];
|
2012-02-25 16:06:08 +01:00
|
|
|
//send a 404 if we don't support this filetype
|
|
|
|
if (types.indexOf(req.params.type) == -1) {
|
2019-01-23 16:29:36 +00:00
|
|
|
return next();
|
2012-02-25 16:06:08 +01:00
|
|
|
}
|
|
|
|
|
2019-02-08 23:20:57 +01:00
|
|
|
// if abiword is disabled, and this is a format we only support with abiword, output a message
|
2015-12-18 00:14:13 -06:00
|
|
|
if (settings.exportAvailable() == "no" &&
|
2012-02-25 16:06:08 +01:00
|
|
|
["odt", "pdf", "doc"].indexOf(req.params.type) !== -1) {
|
2015-12-18 00:14:13 -06:00
|
|
|
res.send("This export is not enabled at this Etherpad instance. Set the path to Abiword or SOffice in settings.json to enable this feature");
|
2012-02-25 16:06:08 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res.header("Access-Control-Allow-Origin", "*");
|
|
|
|
|
2019-01-23 16:29:36 +00:00
|
|
|
if (await hasPadAccess(req, res)) {
|
2018-04-04 21:48:32 +01:00
|
|
|
console.log('req.params.pad', req.params.pad);
|
2019-01-23 16:29:36 +00:00
|
|
|
let exists = await padManager.doesPadExists(req.params.pad);
|
|
|
|
if (!exists) {
|
|
|
|
return next();
|
|
|
|
}
|
2018-04-04 21:48:32 +01:00
|
|
|
|
2019-01-23 16:29:36 +00:00
|
|
|
exportHandler.doExport(req, res, req.params.pad, req.params.type);
|
|
|
|
}
|
2012-02-25 16:06:08 +01:00
|
|
|
});
|
|
|
|
|
2019-02-08 23:20:57 +01:00
|
|
|
// handle import requests
|
2019-01-23 16:29:36 +00:00
|
|
|
args.app.post('/p/:pad/import', async function(req, res, next) {
|
|
|
|
if (await hasPadAccess(req, res)) {
|
|
|
|
let exists = await padManager.doesPadExists(req.params.pad);
|
|
|
|
if (!exists) {
|
|
|
|
return next();
|
|
|
|
}
|
2018-04-04 21:48:32 +01:00
|
|
|
|
2019-01-23 16:29:36 +00:00
|
|
|
importHandler.doImport(req, res, req.params.pad);
|
|
|
|
}
|
2012-02-25 16:06:08 +01:00
|
|
|
});
|
|
|
|
}
|