Skip to content

Commit a193acf

Browse files
authored
fix: Merge pull request #6 from electron/get-method
Add get method, so can get info at electron website url
2 parents 25552ec + 7ef6f01 commit a193acf

File tree

4 files changed

+6007
-4
lines changed

4 files changed

+6007
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.env
22
.npmrc
3+
node_modules

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {post} = require('got')
1+
const got = require('got')
22
const assert = require('assert')
33
const path = require('path')
44

@@ -8,14 +8,18 @@ async function getCrowdinFileIds (project, crowdinKey) {
88

99
assert(project, '`project` must be the first argument')
1010

11+
let method = 'post'
12+
1113
if (project === 'electron') {
1214
url = 'https://electronjs.org/crowdin/info'
15+
method = 'get' // Fix: HTTPError: Response code 405 (Method Not Allowed)
16+
// https://github.com/electron/electronjs.org/blob/f67079064ea071bee1ad46052d7940591e229a2c/routes/languages/proxy.js#L17
1317
} else {
1418
assert(crowdinKey, '`crowdinKey` must be the second argument or process.env.CROWDIN_KEY')
1519
url = `https://api.crowdin.com/api/project/${project}/info?key=${crowdinKey}&json`
1620
}
1721

18-
const res = await post(url, {json: true})
22+
const res = await got[method](url, {json: true})
1923
return resolveFile({}, res.body.files)
2024
}
2125

@@ -25,7 +29,7 @@ function resolveFile (acc, files, pathPrefix = []) {
2529
files.forEach(file => {
2630
switch (file.node_type) {
2731
case 'file':
28-
const fullpath = pathPrefix.concat(file.name).join(path.sep)
32+
const fullpath = pathPrefix.concat(file.name).join(path.sep).replace(/\\/g, '/')
2933
acc[fullpath] = file.id
3034
break
3135
case 'directory':

0 commit comments

Comments
 (0)