-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
51 lines (40 loc) · 1.13 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// deno-lint-ignore-file no-explicit-any
import express from 'npm:express'
import cors from 'npm:cors'
import yt from './yt/main.ts'
const app = express()
const port = 3666
app.use(cors())
app.use(express.static('public'))
app.get('/yt/0', async (req: any, res: any) => {
const page = parseInt(req.query.page) || 1
const limit = parseInt(req.query.limit) || 500
const iter = yt.db.list<any>({ prefix: ['videos'] })
const list = []
for await (const res of iter) list.push(res.value)
const videos = list
.sort((a: any, b: any) => b.meta.timestamp - a.meta.timestamp)
.slice((page - 1) * limit, page * limit)
res.json({
page,
limit,
videos
})
})
app.get('/yt/0/stats', async (_req: any, res: any) => {
const iter = yt.db.list<any>({ prefix: ['videos'] })
const list = []
for await (const res of iter) list.push(res.value)
const length = list.length
res.json({
length,
videos: list
})
})
app.listen(port, () => {
console.log(`𝒜𝓇𝓇𝒶𝓃𝑔𝒾𝓃𝑔 𝒟𝒶𝓉𝒶 𝐼𝓃𝓉𝑜 𝐿𝒾𝓈𝓉𝓈 http://localhost:${port}`)
})
function init() {
yt.init()
}
init()