Skip to content

Commit

Permalink
Merge branch 'clearlydefined:master' into yk/update-request-promise
Browse files Browse the repository at this point in the history
  • Loading branch information
yashkohli88 committed Sep 19, 2024
2 parents 731800d + c008d00 commit d9b7a1d
Show file tree
Hide file tree
Showing 3 changed files with 40,676 additions and 8 deletions.
19 changes: 13 additions & 6 deletions routes/originPyPi.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ router.get(
'/:name/revisions',
asyncMiddleware(async (request, response) => {
const { name } = request.params
const url = `https://pypi.python.org/pypi/${name}/json`
const answer = await requestPromise({ url, method: 'GET', json: true })
const answer = await getPypiData(name)
const result = answer && answer.releases ? Object.keys(answer.releases) : []
result.reverse()
return response.status(200).send(uniq(result))
Expand All @@ -23,14 +22,22 @@ router.get(
'/:name',
asyncMiddleware(async (request, response) => {
const { name } = request.params
const url = `https://pypi.python.org/pypi/${name}/json`
const answer = await requestPromise({ url, method: 'GET', json: true })
const answer = await getPypiData(name)
const result = answer && answer.info ? [{ id: answer.info.name }] : []
return response.status(200).send(result)
})
)

function setup() {
async function getPypiData(name) {
const url = `https://pypi.python.org/pypi/${encodeURIComponent(name)}/json`
try {
return await requestPromise({ url, method: 'GET', json: true })
} catch (error) {
if (error.statusCode === 404) return {}
throw error
}
}
function setup(testflag = false) {
if (testflag) router._getPypiData = getPypiData
return router
}

Expand Down
Loading

0 comments on commit d9b7a1d

Please sign in to comment.