|
1 | 1 | 'use strict'; |
2 | 2 |
|
| 3 | +import express from "express"; |
| 4 | + |
3 | 5 | const log4js = require('log4js'); |
4 | 6 | const clientLogger = log4js.getLogger('client'); |
5 | 7 | const {Formidable} = require('formidable'); |
6 | 8 | const apiHandler = require('../../handler/APIHandler'); |
7 | 9 | const util = require('util'); |
8 | 10 |
|
| 11 | + |
| 12 | +function objectAsString(obj) { |
| 13 | + var output = ''; |
| 14 | + for (var property in obj) { |
| 15 | + if(obj.hasOwnProperty(property) && typeof obj[property] !== 'function') { |
| 16 | + var value = obj[property]; |
| 17 | + if(typeof value === 'object' && !Array.isArray(value) && value !== null) { |
| 18 | + value = '{' + objectAsString(value) + '}'; |
| 19 | + } |
| 20 | + output += property + ': ' + value +'; '; |
| 21 | + } |
| 22 | + } |
| 23 | + return output; |
| 24 | +} |
| 25 | + |
9 | 26 | exports.expressPreSession = async (hookName:string, {app}:any) => { |
| 27 | + app.use(express.json()); |
10 | 28 | // The Etherpad client side sends information about how a disconnect happened |
11 | 29 | app.post('/ep/pad/connection-diagnostic-info', async (req:any, res:any) => { |
12 | | - const [fields, files] = await (new Formidable({})).parse(req); |
13 | | - clientLogger.info(`DIAGNOSTIC-INFO: ${fields.diagnosticInfo}`); |
| 30 | + if (!req.body ||!req.body.diagnosticInfo || typeof req.body.diagnosticInfo !== 'object') { |
| 31 | + clientLogger.warn('DIAGNOSTIC-INFO: No diagnostic info provided'); |
| 32 | + res.status(400).end('No diagnostic info provided'); |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + clientLogger.info(`DIAGNOSTIC-INFO: ${objectAsString(req.body.diagnosticInfo)}`); |
14 | 37 | res.end('OK'); |
15 | 38 | }); |
16 | 39 |
|
|
0 commit comments