website now works
This commit is contained in:
1 parent
ce56fcb91c
commit
3daa9f82e7
15 files changed
+241
-137
No files matched your search
+14
-12
@@ -132,7 +132,6 @@ export class Database {
|
||||
[image],
|
||||
tag,
|
||||
category,
|
||||
excerptHtml excerpt,
|
||||
contentHtml content
|
||||
FROM files f
|
||||
JOIN q ON q.path = f.path
|
||||
@@ -155,7 +154,6 @@ export class Database {
|
||||
image?: string
|
||||
tag?: string[]
|
||||
category?: string
|
||||
excerpt: string
|
||||
content: string
|
||||
}
|
||||
}
|
||||
@@ -167,7 +165,10 @@ export class Database {
|
||||
limit: number
|
||||
}
|
||||
) {
|
||||
return this._search(q, opts, 'RANK')
|
||||
return this._search(q, {
|
||||
...opts,
|
||||
orderedBy: 'RANK',
|
||||
})
|
||||
}
|
||||
|
||||
public by(
|
||||
@@ -177,11 +178,11 @@ export class Database {
|
||||
limit: number
|
||||
}
|
||||
) {
|
||||
return this._search(
|
||||
q,
|
||||
opts,
|
||||
'priority DESC, [date] DESC, createdAt DESC, updatedAt DESC'
|
||||
)
|
||||
return this._search(q, {
|
||||
...opts,
|
||||
orderedBy: 'priority DESC, [date] DESC, createdAt DESC, updatedAt DESC',
|
||||
where: '[date] IS NOT NULL',
|
||||
})
|
||||
}
|
||||
|
||||
private _search(
|
||||
@@ -189,13 +190,14 @@ export class Database {
|
||||
opts: {
|
||||
offset: number
|
||||
limit: number
|
||||
},
|
||||
orderedBy: string
|
||||
orderedBy: string
|
||||
where?: string
|
||||
}
|
||||
) {
|
||||
const fromSegment = /* sql */ `
|
||||
FROM files f
|
||||
JOIN q ON q.path = f.path
|
||||
${q ? `WHERE q = @q` : ''}
|
||||
WHERE ${q ? `q = @q` : 'TRUE'} ${opts.where ? `AND ${opts.where}` : ''}
|
||||
`
|
||||
|
||||
const count =
|
||||
@@ -220,7 +222,7 @@ export class Database {
|
||||
category,
|
||||
excerptHtml excerpt
|
||||
${fromSegment}
|
||||
ORDER BY ${orderedBy}
|
||||
ORDER BY ${opts.orderedBy}
|
||||
LIMIT ${opts.limit} OFFSET ${opts.offset}
|
||||
`
|
||||
)
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
import express from 'express'
|
||||
import morgan from 'morgan'
|
||||
import * as z from 'zod'
|
||||
|
||||
import { Database } from './db'
|
||||
|
||||
const app = express()
|
||||
app.use(morgan('dev'))
|
||||
|
||||
const db = new Database({ readonly: true })
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
const { id } = z
|
||||
const { path } = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
path: z.string(),
|
||||
})
|
||||
.parse(req.query)
|
||||
|
||||
const r = db.get(id)
|
||||
const r = db.get(path)
|
||||
if (!r) {
|
||||
res.sendStatus(404)
|
||||
return
|
||||
@@ -55,4 +58,10 @@ app.get('/q', (req, res) => {
|
||||
)
|
||||
})
|
||||
|
||||
app.use((err: Error, _: express.Request, res: express.Response) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(err.stack)
|
||||
res.status(500).send(err)
|
||||
})
|
||||
|
||||
export default app
|
||||
Reference in new issue
Block a user