encode url params, make issues/prs separate routes
This commit is contained in:
parent
d33abb559f
commit
3a7ecc70a3
1 changed files with 31 additions and 3 deletions
34
server.js
34
server.js
|
@ -17,7 +17,9 @@ app.get('/', function (req, res) {
|
|||
|
||||
app.get('/:owner/:repo', async function (req, res) {
|
||||
const repoResp = await fetch(
|
||||
`https://git.gay/api/v1/repos/${req.params.owner}/${req.params.repo}`
|
||||
`https://git.gay/api/v1/repos/${encodeURIComponent(
|
||||
req.params.owner
|
||||
)}/${encodeURIComponent(req.params.repo)}`
|
||||
)
|
||||
const repo = await repoResp.json()
|
||||
const html = await eta.renderAsync('repo', {
|
||||
|
@ -33,9 +35,35 @@ app.get('/:owner/:repo', async function (req, res) {
|
|||
res.send(await render(html))
|
||||
})
|
||||
|
||||
app.get('/:owner/:repo/:type/:num', async function (req, res) {
|
||||
app.get('/:owner/:repo/issue/:num', async function (req, res) {
|
||||
const issueResp = await fetch(
|
||||
`https://git.gay/api/v1/repos/${req.params.owner}/${req.params.repo}/${req.params.type}/${req.params.num}`
|
||||
`https://git.gay/api/v1/repos/${encodeURIComponent(
|
||||
req.params.owner
|
||||
)}/${encodeURIComponent(req.params.repo)}/issues/${encodeURIComponent(
|
||||
req.params.num
|
||||
)}`
|
||||
)
|
||||
const issue = await issueResp.json()
|
||||
const html = await eta.renderAsync('issue', {
|
||||
issue,
|
||||
debug
|
||||
})
|
||||
if (debug) {
|
||||
res.send(await renderHtml(html))
|
||||
return
|
||||
}
|
||||
res.type('png')
|
||||
res.set('Content-Disposition', 'inline')
|
||||
res.send(await render(html))
|
||||
})
|
||||
|
||||
app.get('/:owner/:repo/pull/:num', async function (req, res) {
|
||||
const issueResp = await fetch(
|
||||
`https://git.gay/api/v1/repos/${encodeURIComponent(
|
||||
req.params.owner
|
||||
)}/${encodeURIComponent(req.params.repo)}/pulls/${encodeURIComponent(
|
||||
req.params.num
|
||||
)}`
|
||||
)
|
||||
const issue = await issueResp.json()
|
||||
const html = await eta.renderAsync('issue', {
|
||||
|
|
Loading…
Reference in a new issue