Skip to content

Commit

Permalink
fix: fall back on default language for proxied labs
Browse files Browse the repository at this point in the history
If a proxied lab (Amrita, PhET, Physics Aviary) is not available in the
required language, fall back to the default (currently English). This
prevents labs like the Amrita ones from breaking.

closes #173
  • Loading branch information
juancarlosfarah committed Aug 20, 2019
1 parent eb5f864 commit a7007b2
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions public/app/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const download = require('download');
const providers = require('./config/providers');
const logger = require('./logger');
const mapping = require('./config/mapping');
const { DEFAULT_PROTOCOL } = require('./config/config');
const { DEFAULT_PROTOCOL, DEFAULT_LANG } = require('./config/config');
const {
getExtension,
isDownloadable,
Expand All @@ -25,11 +25,20 @@ const getDownloadUrl = async ({ url, lang }) => {
}
const res = await request(url);
const $ = cheerio.load(res);
const elem = $(`meta[name="download"][language="${lang}"]`);
if (elem) {
return elem.attr('value');

const proxyUrl = $(`meta[name="download"][language="${lang}"]`).attr('value');
if (proxyUrl) {
logger.debug(`proxying from ${proxyUrl}`);
return proxyUrl;
}
// fall back on default language if requested is not available
const defaultProxyUrl = $(
`meta[name="download"][language="${DEFAULT_LANG}"]`
).attr('value');
if (defaultProxyUrl) {
logger.debug(`defaulting to proxying from ${defaultProxyUrl}`);
return defaultProxyUrl;
}
// todo: fall back on another language if requested is not available?
return false;
};

Expand Down

0 comments on commit a7007b2

Please sign in to comment.