-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhono.js
77 lines (66 loc) · 2.24 KB
/
hono.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Hono } from 'hono'
import { decode } from 'iconv-lite'
import { Dat, Subject, Setting } from './lib'
const app = new Hono()
const welcomeMessage = {
res: 1,
subject: '2ちゃんねるリーダー 2ch.js について',
comments: [{
id: 1,
body: [
'2ch.jsはウェブブラウザで動作する2ch互換掲示板ビューアです',
'',
'バグ報告は<a href="https://github.com/shinosaki/2ch.js/issues" target="_blank" rel="noopener noreferrer">GithubのIssue</a>から'
].join('<br>'),
uid: 'nullpo',
name: '2ch.js',
email: '',
date: '2024-01-25T08:11:06.085Z'
}]
}
app.get('/dat', async (c) => {
const { url } = c.req.query()
if (url === '/welcome.dat') {
return c.json(welcomeMessage)
}
const data = await fetch(url).then(r => r.arrayBuffer());
const decoded = decode(new Uint8Array(data), 'SJIS');
return c.json(Dat(decoded));
});
app.get('/subject', async (c) => {
const { url } = c.req.query()
const data = await fetch(url).then(r => r.arrayBuffer());
const decoded = decode(new Uint8Array(data), 'SJIS');
return c.json(Subject(decoded, url));
});
app.get('/setting', async (c) => {
const { url } = c.req.query()
const data = await fetch(url).then(r => r.arrayBuffer());
const decoded = decode(new Uint8Array(data), 'SJIS');
c.header('Cache-Control', 'max-age=86400')
return c.json(Setting(decoded));
});
app.get('/welcome.dat', async (c) => {
// const message = [
// '2ch.jsは、ウェブブラウザで動作する2ch互換掲示板ビューア'
// ].join('<br>')
})
// itest api
// app.get('/:board/subback', async (c) => {
// const { board } = c.req.param()
// const url = `https://itest.5ch.net/subbacks/${board}.json`
// const data = await fetch(url).then(r => r.json())
// return c.json(data)
// })
// app.get('/:board/:id', async (c) => {
// const serverList = {
// poverty: 'greta',
// livegalileo: 'nova'
// };
// const { board, id } = c.req.param()
// const server = c.req.query('server') || serverList[board]
// const url = `https://itest.5ch.net/cache/${server}/test/read.cgi/${board}/${id}`
// const data = await fetch(url).then(r => r.json())
// return c.json(data)
// })
export default app