-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.ts
44 lines (39 loc) · 924 Bytes
/
handlers.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
import { rest } from 'msw';
import { AjaxIllustErrorResponse, AjaxIllustResponse } from '../types';
import { db } from './db';
export const handlers = [
rest.get<
any,
{ illustId: string },
AjaxIllustResponse | AjaxIllustErrorResponse
>(
'https://www.pixiv.net/ajax/illust/:illustId',
({ params: { illustId } }, res, ctx) => {
const illust = db.illust.findFirst({
where: {
id: {
equals: illustId,
},
},
});
if (!illust) {
return res(
ctx.status(404),
ctx.json({
error: true,
message: '該当作品は削除されたか、存在しない作品IDです。',
body: [],
})
);
}
return res(
ctx.status(200),
ctx.json({
error: false,
message: '',
body: illust,
})
);
}
),
];