mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
import/export: On export error return 500 instead of crashing
This commit is contained in:
parent
3a11e97758
commit
83f39289aa
3 changed files with 31 additions and 6 deletions
|
@ -33,11 +33,6 @@ const util = require('util');
|
||||||
const fsp_writeFile = util.promisify(fs.writeFile);
|
const fsp_writeFile = util.promisify(fs.writeFile);
|
||||||
const fsp_unlink = util.promisify(fs.unlink);
|
const fsp_unlink = util.promisify(fs.unlink);
|
||||||
|
|
||||||
const converter =
|
|
||||||
settings.soffice != null ? require('../utils/LibreOffice')
|
|
||||||
: settings.abiword != null ? require('../utils/Abiword')
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const tempDirectory = os.tmpdir();
|
const tempDirectory = os.tmpdir();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,6 +94,10 @@ exports.doExport = async (req, res, padId, readOnlyId, type) => {
|
||||||
if (result.length > 0) {
|
if (result.length > 0) {
|
||||||
// console.log("export handled by plugin", destFile);
|
// console.log("export handled by plugin", destFile);
|
||||||
} else {
|
} else {
|
||||||
|
const converter =
|
||||||
|
settings.soffice != null ? require('../utils/LibreOffice')
|
||||||
|
: settings.abiword != null ? require('../utils/Abiword')
|
||||||
|
: null;
|
||||||
// @TODO no Promise interface for converters (yet)
|
// @TODO no Promise interface for converters (yet)
|
||||||
await util.promisify(converter.convertFile)(srcFile, destFile, type);
|
await util.promisify(converter.convertFile)(srcFile, destFile, type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ exports.expressCreateServer = (hookName, args, cb) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Exporting pad "${req.params.pad}" in ${req.params.type} format`);
|
console.log(`Exporting pad "${req.params.pad}" in ${req.params.type} format`);
|
||||||
exportHandler.doExport(req, res, padId, readOnlyId, req.params.type);
|
await exportHandler.doExport(req, res, padId, readOnlyId, req.params.type);
|
||||||
}
|
}
|
||||||
})().catch((err) => next(err || new Error(err)));
|
})().catch((err) => next(err || new Error(err)));
|
||||||
});
|
});
|
||||||
|
|
26
src/tests/backend/specs/export.js
Normal file
26
src/tests/backend/specs/export.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const common = require('../common');
|
||||||
|
const padManager = require('../../../node/db/PadManager');
|
||||||
|
const settings = require('../../../node/utils/Settings');
|
||||||
|
|
||||||
|
describe(__filename, function () {
|
||||||
|
let agent;
|
||||||
|
const settingsBackup = {};
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
agent = await common.init();
|
||||||
|
settingsBackup.soffice = settings.soffice;
|
||||||
|
await padManager.getPad('testExportPad', 'test content');
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async function () {
|
||||||
|
Object.assign(settings, settingsBackup);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns 500 on export error', async function () {
|
||||||
|
settings.soffice = 'false'; // '/bin/false' doesn't work on Windows
|
||||||
|
await agent.get('/p/testExportPad/export/doc')
|
||||||
|
.expect(500);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue