Skip to content

Commit c62fe46

Browse files
authored
feat: use unauthenticated proxy for electron project
use unauthenticated proxy for electron project
2 parents 6e8d258 + 8eb3e0f commit c62fe46

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ const path = require('path')
44

55
async function getCrowdinFileIds (project, crowdinKey) {
66
crowdinKey = crowdinKey || process.env.CROWDIN_KEY
7+
let url
78

89
assert(project, '`project` must be the first argument')
9-
assert(crowdinKey, '`crowdinKey` must be the second argument or process.env.CROWDIN_KEY')
1010

11-
const url = `https://api.crowdin.com/api/project/${project}/info?key=${crowdinKey}&json`
11+
if (project === 'electron') {
12+
url = 'https://electronjs.org/crowdin/info'
13+
} else {
14+
assert(crowdinKey, '`crowdinKey` must be the second argument or process.env.CROWDIN_KEY')
15+
url = `https://api.crowdin.com/api/project/${project}/info?key=${crowdinKey}&json`
16+
}
17+
1218
const res = await post(url, {json: true})
1319
return resolveFile({}, res.body.files)
1420
}

test/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ describe('getCrowdinFileIds', () => {
1515
})
1616

1717
it('expects project name and Crowdin API key as arguments', async () => {
18-
crowdin.post('/project/electron/info?key=xyz&json')
18+
crowdin.post('/project/foo-project/info?key=xyz&json')
1919
.once()
2020
.reply(200, require('./fixture.json'))
2121

22-
const urls = await getCrowdinFileIds('electron', 'xyz')
22+
const urls = await getCrowdinFileIds('foo-project', 'xyz')
2323
const paths = Object.keys(urls)
2424

2525
urls.should.be.an('object')
@@ -30,7 +30,17 @@ describe('getCrowdinFileIds', () => {
3030
})
3131

3232
it('falls back to CROWDIN_KEY env var', async () => {
33-
crowdin.post('/project/electron/info?key=abc&json')
33+
crowdin.post('/project/bar-project/info?key=abc&json')
34+
.once()
35+
.reply(200, require('./fixture.json'))
36+
37+
const urls = await getCrowdinFileIds('bar-project')
38+
urls.should.be.an('object')
39+
})
40+
41+
it('uses the unauthenticated website proxy for the `electron` project', async () => {
42+
nock('https://electronjs.org/crowdin')
43+
.post('/info')
3444
.once()
3545
.reply(200, require('./fixture.json'))
3646

0 commit comments

Comments
 (0)