Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace hardcoded domains in Mathoid APIs #1275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions sys/mathoid.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ class MathoidService {
body: checkRes.body
}),
indirectionP,
this._invalidateCache.bind(this, hyper, hash),
this._invalidateCache.bind(this, hyper, req, hash),
() => checkRes
);
}));

}

_storeRenders(hyper, domain, hash, completeBody) {
_storeRenders(hyper, req, domain, hash, completeBody) {
let idx;
const len = FORMATS.length;
const reqs = new Array(len);
Expand Down Expand Up @@ -152,7 +152,7 @@ class MathoidService {
}

// invalidate the cache
reqs.push(this._invalidateCache(hyper, hash));
reqs.push(this._invalidateCache(hyper, req, hash));

// now do them all
return P.all(reqs).then(() => completeBody);
Expand All @@ -169,7 +169,7 @@ class MathoidService {
headers: { 'content-type': 'application/json' },
body: req.body
}).then((res) => // now store all of the renders
this._storeRenders(hyper, rp.domain, hash, res.body)).then((res) => {
this._storeRenders(hyper, req, rp.domain, hash, res.body)).then((res) => {
// and return a proper response
const ret = res[rp.format];
ret.status = 200;
Expand All @@ -179,26 +179,30 @@ class MathoidService {

}

_invalidateCache(hyper, hash) {
_invalidateCache(hyper, req, hash) {

const routes = [];
const uri = '//wikimedia.org/api/rest_v1/media/math/';

routes.push(`${uri}formula/${hash}`);
return mwUtil.getSiteInfo(hyper, req)
.then((siteInfo) => {
const baseUri = siteInfo.baseUri.replace(/^https?:/, '');
const uri = `${baseUri}/api/rest_v1/media/math/`;

FORMATS.forEach((fmt) => {
routes.push(`${uri}render/${fmt}/${hash}`);
});
routes.push(`${uri}formula/${hash}`);

return hyper.post({
uri: new URI(['wikimedia.org', 'sys', 'events', '']),
body: routes.map((route) => ({
meta: { uri: route }
}))
}).catch((e) => {
hyper.logger.log('warn/bg-updates', e);
});
FORMATS.forEach((fmt) => {
routes.push(`${uri}render/${fmt}/${hash}`);
});

return hyper.post({
uri: new URI([this.options.host, 'sys', 'events', '']),
body: routes.map((route) => ({
meta: { uri: route }
}))
}).catch((e) => {
hyper.logger.log('warn/bg-updates', e);
});
});
}

getFormula(hyper, req) {
Expand Down
10 changes: 5 additions & 5 deletions v1/mathoid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ paths:
- get_from_sys:
request:
method: post
uri: /wikimedia.org/sys/mathoid/check/{type}
uri: /{domain}/sys/mathoid/check/{type}
headers: '{{ request.headers }}'
body: '{{ request.body }}'

Expand Down Expand Up @@ -127,7 +127,7 @@ paths:
- get_from_sys:
request:
method: get
uri: /wikimedia.org/sys/mathoid/formula/{hash}
uri: /{domain}/sys/mathoid/formula/{hash}
headers: '{{ request.headers }}'

/math/render/{format}/{hash}:
Expand Down Expand Up @@ -192,7 +192,7 @@ paths:
- check_storage:
request:
method: get
uri: /wikimedia.org/sys/key_value/mathoid_ng.{format}/{hash}
uri: /{domain}/sys/key_value/mathoid_ng.{format}/{hash}
headers:
cache-control: '{{ cache-control }}'
catch:
Expand All @@ -205,11 +205,11 @@ paths:
body: '{{ check_storage.body }}'
- postdata:
request:
uri: /wikimedia.org/sys/mathoid/formula/{request.params.hash}
uri: /{domain}/sys/mathoid/formula/{request.params.hash}
- mathoid:
request:
method: post
uri: /wikimedia.org/sys/mathoid/render/{request.params.format}
uri: /{domain}/sys/mathoid/render/{request.params.format}
headers:
content-type: application/json
x-resource-location: '{{ request.params.hash }}'
Expand Down