Commit 32b0d1ce authored by Nelson GONCALVES's avatar Nelson GONCALVES
Browse files

Fix pad export with apikey

parent 4fca244c
const settings = require('ep_etherpad-lite/node/utils/Settings');
const padManager = require("ep_etherpad-lite/node/db/PadManager");
const readOnlyManager = require('ep_etherpad-lite/node/db/ReadOnlyManager');
const rateLimit = require("express-rate-limit");
const exportHandler = require('ep_etherpad-lite/node/handler/ExportHandler');
const importHandler = require('ep_etherpad-lite/node/handler/ImportHandler');
......@@ -31,7 +32,7 @@ exports.expressCreateServer = function (hook_name, args, cb) {
// handle export requests'/api/laclasse/:pad/:rev?/export/:type', limiter);'/api/laclasse/:pad/:rev?/export/:type', async function(req, res, next) {
var types = ["pdf", "doc", "txt", "html", "odt", "etherpad"];
const types = ["pdf", "doc", "txt", "html", "odt", "etherpad"];
//send a 404 if we don't support this filetype
if (types.indexOf(req.params.type) == -1) {
return next();
......@@ -55,14 +56,21 @@ exports.expressCreateServer = function (hook_name, args, cb) {
return res.send({ code: 4, message: 'no or wrong API Key', data: null });
let exists = await padManager.doesPadExists(req.params.pad);
let padId = req.params.pad;
let readOnlyId = null;
if (readOnlyManager.isReadOnlyId(padId)) {
readOnlyId = padId;
padId = await readOnlyManager.getPadId(readOnlyId);
let exists = await padManager.doesPadExists(padId);
if (!exists) {
laclasseLogger.warn(`Laclasse tried to export a pad that doesn't exist (${req.params.pad})`);
laclasseLogger.warn(`Laclasse tried to export a pad that doesn't exist (${padId})`);
return next();
}`Exporting pad "${req.params.pad}" in ${req.params.type} format`);
exportHandler.doExport(req, res, req.params.pad, req.params.type);`Exporting pad "${padId}" in ${req.params.type} format`);
exportHandler.doExport(req, res, padId, readOnlyId, req.params.type);
// handle import requests
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment