[misc] wordcount: restrict image to an allow list and add tests

This commit is contained in:
Jakob Ackermann
2020-06-26 13:17:45 +01:00
parent 5ed09d1a98
commit 6edb458910
4 changed files with 86 additions and 2 deletions

View File

@@ -189,6 +189,11 @@ module.exports = Client = {
},
wordcount(project_id, file, callback) {
const image = undefined
Client.wordcountWithImage(project_id, file, image, callback)
},
wordcountWithImage(project_id, file, image, callback) {
if (callback == null) {
callback = function(error, pdfPositions) {}
}
@@ -196,6 +201,7 @@ module.exports = Client = {
{
url: `${this.host}/project/${project_id}/wordcount`,
qs: {
image,
file
}
},
@@ -203,6 +209,9 @@ module.exports = Client = {
if (error != null) {
return callback(error)
}
if (response.statusCode !== 200) {
return callback(new Error(`statusCode=${response.statusCode}`))
}
return callback(null, JSON.parse(body))
}
)