-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
71 lines (58 loc) · 2.79 KB
/
Copy pathserver.js
File metadata and controls
71 lines (58 loc) · 2.79 KB
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
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { config } from './config.js';
import { loadAndFormat } from './data-formatters.js';
const app = new Hono();
app.use('*', cors());
app.get('/homepage', async ({ req }) => {
const offset = +req.query('offset') || 0;
return loadAndFormat(`${config.api.host}/v3/timelines/home?offset=${offset}`, req.header('authorization'));
});
app.get('/searchpage', async ({ req }) => {
const q = req.query('q');
const offset = +req.query('offset') || 0;
return loadAndFormat(`${config.api.host}/v3/search?qs=${encodeURIComponent(q)}&offset=${offset}`, req.header('authorization'), null, null, !q);
});
app.get('/discussionspage', async ({ req }) => {
const offset = +req.query('offset') || 0;
return loadAndFormat(`${config.api.host}/v3/timelines/filter/discussions?with-my-posts=yes&offset=${offset}`, req.header('authorization'));
});
app.get('/directspage', async ({ req }) => {
const offset = +req.query('offset') || 0;
return loadAndFormat(`${config.api.host}/v3/timelines/filter/directs?offset=${offset}`, req.header('authorization'));
});
app.get('/userpage/:username', async ({ req }) => {
const username = req.param('username');
const offset = +req.query('offset') || 0;
return loadAndFormat(`${config.api.host}/v3/timelines/${username}?offset=${offset}`, req.header('authorization'), username);
});
app.get('/usercommentspage/:username', async ({ req }) => {
const username = req.param('username');
const offset = +req.query('offset') || 0;
return loadAndFormat(`${config.api.host}/v3/timelines/${username}/comments?offset=${offset}`, req.header('authorization'), username);
});
app.get('/userlikespage/:username', async ({ req }) => {
const username = req.param('username');
const offset = +req.query('offset') || 0;
return loadAndFormat(`${config.api.host}/v3/timelines/${username}/likes?offset=${offset}`, req.header('authorization'), username);
});
app.get('/postpage/:postId', async ({ req }) => {
const postId = req.param('postId');
const comments = req.query('comments');
const likes = req.query('likes');
const params = new URLSearchParams();
if (comments === 'all') params.set('maxComments', 'all');
if (likes === 'all') params.set('maxLikes', 'all');
const query = params.toString();
const url = `${config.api.host}/v3/posts/${postId}${query ? `?${query}` : ''}`;
return loadAndFormat(url, req.header('authorization'), null, postId, false, {
withoutComments: comments === 'none',
withoutLikes: likes === 'none',
});
});
app.get('/postbacklinkspage/:postId', async ({ req }) => {
const postId = req.param('postId');
const offset = +req.query('offset') || 0;
return loadAndFormat(`${config.api.host}/v3/posts/${postId}/backlinks?offset=${offset}`, req.header('authorization'));
});
export default app;