remove pug
This commit is contained in:
1 parent
e397c9ae1e
commit
68840c9c60
49 files changed
+1421
-806
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import express from 'express'
|
||||
import * as z from 'zod'
|
||||
|
||||
import { Database } from './db'
|
||||
|
||||
const app = express()
|
||||
const db = new Database({ readonly: true })
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
const { id } = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
})
|
||||
.parse(req.query)
|
||||
|
||||
const r = db.get(id)
|
||||
if (!r) {
|
||||
res.sendStatus(404)
|
||||
return
|
||||
}
|
||||
|
||||
res.json(r)
|
||||
})
|
||||
|
||||
app.get('/q', (req, res) => {
|
||||
const { q, tag, page: _page = '1' } = z
|
||||
.object({
|
||||
q: z.string().optional(),
|
||||
tag: z.string().optional(),
|
||||
page: z
|
||||
.string()
|
||||
.refine((s) => /^\d+$/.test(s))
|
||||
.optional(),
|
||||
})
|
||||
.parse(req.query)
|
||||
|
||||
const perPage = 5
|
||||
const offset = (parseInt(_page) - 1) * perPage
|
||||
|
||||
if (q) {
|
||||
res.json(
|
||||
db.q(`${q} ${tag ? `tag:${tag}` : ''}`, {
|
||||
offset,
|
||||
limit: perPage,
|
||||
})
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
res.json(
|
||||
db.by(tag ? `tag:${tag}` : '', {
|
||||
offset,
|
||||
limit: perPage,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
export default app
|
||||
Reference in new issue
Block a user