Skip to content

Commit

Permalink
Remove mathoid PNG image support (#1324)
Browse files Browse the repository at this point in the history
Remove mathoid PNG image support from RESTBase endpoint.

* Stop storing PNG response from mathoid
* Redirect PNG endpoint to SVG endpoint

Bug: T334842
  • Loading branch information
physikerwelt committed Jul 6, 2023
1 parent a1edf24 commit 50152c4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
15 changes: 6 additions & 9 deletions sys/mathoid.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const URI = HyperSwitch.URI;
const HTTPError = HyperSwitch.HTTPError;
const mwUtil = require('../lib/mwUtil');

const FORMATS = ['mml', 'svg', 'png'];
const FORMATS = ['mml', 'svg'];

function prefixHeaders(headers, prefix = 'x-store-') {
const prefixedHeaders = {};
Expand Down Expand Up @@ -141,12 +141,6 @@ class MathoidService {
}, prefixHeaders(completeBody[format].headers)),
body: completeBody[format].body
};
if (format === 'png' && reqObj.body && reqObj.body.type === 'Buffer') {
// for png, we need to convert the encoded data manually
// because we are receiving it wrapped inside a JSON
reqObj.body = Buffer.from(reqObj.body.data);
completeBody[format].body = reqObj.body;
}
// store the emit Promise
reqs[idx] = hyper.put(reqObj);
}
Expand All @@ -162,7 +156,10 @@ class MathoidService {
requestAndStore(hyper, req) {
const rp = req.params;
const hash = req.headers['x-resource-location'];

// T334842 redirect png traffic to svg endpoint.
if (rp.format === 'png') {
rp.format = 'svg';
}
// first ask for all the renders from Mathoid
return hyper.post({
uri: `${this.options.host}/complete`,
Expand Down Expand Up @@ -297,7 +294,7 @@ module.exports = (options) => {
},
body: {
keyType: 'string',
valueType: 'blob'
valueType: 'string'
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions test/features/mathoid.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ describe('Mathoid', function() {
const server = new Server();
const f = 'c^2 = a^2 + b^2';
const nf = 'c^{2}=a^{2}+b^{2}';
const formats = ['mml', 'svg', 'png'];
const formats_regex = [/mathml/, /svg/, /png/];
const formats = ['mml', 'svg'];
const formatRegexp = [/mathml/, /svg/];
let hash;

before(() => server.start());
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('Mathoid', function() {

for (let i = 0; i < formats.length; i++) {
const format = formats[i];
const regex = formats_regex[i];
const regex = formatRegexp[i];
it(`gets the render in ${format}`, () => { // eslint-disable-line no-loop-func
return preq.get({
uri: `${server.config.baseURL('wikimedia.org')}/media/math/render/${format}/${hash}`
Expand Down
4 changes: 0 additions & 4 deletions v1/mathoid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ paths:
application/mathml+xml:
schema:
type: string
image/png:
schema:
type: string
format: binary
404:
description: Unknown format or hash ID
content:
Expand Down

0 comments on commit 50152c4

Please sign in to comment.