-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: download phet labs in requested language
closes #78
- Loading branch information
1 parent
a4c3adf
commit 3f2c432
Showing
7 changed files
with
73 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
module.exports = { | ||
'https://gateway.golabz.eu/os/pub/phet/http%25253A%25252F%25252Fphet.colorado.edu%25252Fen%25252Fsimulation%25252Fwave-on-a-string/w_default.html': | ||
'https://apps.graasp.eu/5acb589d0d5d9464081c2d46/5ccae1f6203454853b0aabcb/latest/index.html', | ||
}; | ||
module.exports = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = ['gateway.golabz.eu']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const request = require('request-promise'); | ||
const cheerio = require('cheerio'); | ||
const providers = require('./config/providers'); | ||
|
||
const getDownloadUrl = async ({ url, lang }) => { | ||
let proxied = false; | ||
providers.forEach(provider => { | ||
if (url.includes(provider)) { | ||
proxied = true; | ||
} | ||
}); | ||
if (!proxied) { | ||
return false; | ||
} | ||
const res = await request(url); | ||
const $ = cheerio.load(res); | ||
const elem = $(`meta[name="download"][language="${lang}"]`); | ||
if (elem) { | ||
return elem.attr('value'); | ||
} | ||
// todo: fall back on another language if requested is not available? | ||
return false; | ||
}; | ||
|
||
module.exports = { | ||
getDownloadUrl, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters