2023-08-02 18:09:44 -04:00
|
|
|
import express from 'express'
|
2023-08-02 18:37:47 -04:00
|
|
|
import { Eta } from 'eta'
|
2023-08-02 19:54:54 -04:00
|
|
|
import render, { renderHtml } from './lib/render.js'
|
2023-08-02 18:51:06 -04:00
|
|
|
|
|
|
|
const debug = process.env.DEBUG ? true : false
|
|
|
|
|
2023-08-02 18:37:47 -04:00
|
|
|
const eta = new Eta({
|
|
|
|
views: 'views',
|
2023-08-02 18:51:06 -04:00
|
|
|
cache: !debug
|
2023-08-02 18:37:47 -04:00
|
|
|
})
|
2023-08-02 18:09:44 -04:00
|
|
|
|
2023-08-02 18:17:21 -04:00
|
|
|
const app = express()
|
2023-08-02 18:09:44 -04:00
|
|
|
|
2023-08-02 18:17:21 -04:00
|
|
|
app.get('/', function (req, res) {
|
|
|
|
res.redirect('https://git.gay/gitgay/og.git')
|
|
|
|
})
|
2023-08-02 18:09:44 -04:00
|
|
|
|
2023-08-02 18:17:21 -04:00
|
|
|
app.get('/:owner/:repo', async function (req, res) {
|
2023-08-02 18:19:26 -04:00
|
|
|
const repoResp = await fetch(
|
|
|
|
`https://git.gay/api/v1/repos/${req.params.owner}/${req.params.repo}`
|
|
|
|
)
|
|
|
|
const repo = await repoResp.json()
|
2023-08-02 18:51:06 -04:00
|
|
|
const html = await eta.renderAsync('repo', {
|
|
|
|
repo,
|
|
|
|
debug
|
|
|
|
})
|
|
|
|
if (debug) {
|
2023-08-02 19:54:54 -04:00
|
|
|
res.send(renderHtml(html))
|
2023-08-02 18:51:06 -04:00
|
|
|
return
|
|
|
|
}
|
2023-08-02 18:37:47 -04:00
|
|
|
res.type('png')
|
|
|
|
res.set('Content-Disposition', 'inline')
|
2023-08-02 18:51:06 -04:00
|
|
|
res.send(await render(html))
|
2023-08-02 18:09:44 -04:00
|
|
|
})
|
|
|
|
|
2023-08-02 19:14:37 -04:00
|
|
|
app.get('/:owner/:repo/:type/:num', async function (req, res) {
|
2023-08-02 19:10:20 -04:00
|
|
|
const issueResp = await fetch(
|
2023-08-02 19:14:37 -04:00
|
|
|
`https://git.gay/api/v1/repos/${req.params.owner}/${req.params.repo}/${req.params.type}/${req.params.num}`
|
2023-08-02 19:10:20 -04:00
|
|
|
)
|
|
|
|
const issue = await issueResp.json()
|
|
|
|
const html = await eta.renderAsync('issue', {
|
|
|
|
issue,
|
|
|
|
debug
|
|
|
|
})
|
|
|
|
if (debug) {
|
2023-08-02 19:54:54 -04:00
|
|
|
res.send(renderHtml(html))
|
2023-08-02 19:10:20 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
res.type('png')
|
|
|
|
res.set('Content-Disposition', 'inline')
|
|
|
|
res.send(await render(html))
|
|
|
|
})
|
|
|
|
|
2023-08-02 18:17:21 -04:00
|
|
|
app.listen(8085)
|