83 lines
1.8 KiB
JavaScript
83 lines
1.8 KiB
JavaScript
import express from 'express'
|
|
import { Eta } from 'eta'
|
|
import render, { renderHtml } from './lib/render.js'
|
|
|
|
const debug = process.env.DEBUG ? true : false
|
|
|
|
const eta = new Eta({
|
|
views: 'views',
|
|
cache: !debug
|
|
})
|
|
|
|
const app = express()
|
|
|
|
app.get('/', function (req, res) {
|
|
res.redirect('https://git.gay/gitgay/og.git')
|
|
})
|
|
|
|
app.get('/:owner/:repo', async function (req, res) {
|
|
const repoResp = await fetch(
|
|
`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', {
|
|
repo,
|
|
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/issue/:num', async function (req, res) {
|
|
const issueResp = await fetch(
|
|
`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', {
|
|
issue,
|
|
debug
|
|
})
|
|
if (debug) {
|
|
res.send(await renderHtml(html))
|
|
return
|
|
}
|
|
res.type('png')
|
|
res.set('Content-Disposition', 'inline')
|
|
res.send(await render(html))
|
|
})
|
|
|
|
app.listen(8085)
|