-
Notifications
You must be signed in to change notification settings - Fork 0
/
fxtwitter.ts
118 lines (116 loc) · 3.01 KB
/
fxtwitter.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { z } from "zod";
import { USER_AGENT } from "./consts";
export const FxtwitterResult = z.object({
code: z.number(),
message: z.string(),
tweet: z.object({
url: z.string(),
text: z.string(),
created_at: z.string(),
created_timestamp: z.number(),
author: z.object({
name: z.string(),
screen_name: z.string(),
avatar_url: z.string(),
avatar_color: z.string().nullable(),
banner_url: z.string(),
}),
replies: z.number(),
retweets: z.number(),
likes: z.number(),
views: z.number(),
color: z.string().nullable(),
twitter_card: z.string().optional(),
lang: z.string(),
source: z.string(),
replying_to: z.any(),
replying_to_status: z.any(),
quote: z
.object({
text: z.string(),
author: z.object({
name: z.string(),
screen_name: z.string(),
}),
})
.optional(),
media: z
.object({
all: z
.array(
z.object({
type: z.enum(["video", "gif", "photo"]),
url: z.string(),
thumbnail_url: z.string().optional(),
width: z.number(),
height: z.number(),
duration: z.number().optional(),
format: z.string().optional(),
})
)
.optional(),
external: z
.object({
type: z.literal("video"),
url: z.string(),
height: z.number(),
width: z.number(),
duration: z.number(),
})
.optional(),
photos: z
.array(
z.object({
type: z.literal("photo"),
url: z.string(),
width: z.number(),
height: z.number(),
})
)
.optional(),
videos: z
.array(
z.object({
type: z.enum(["video", "gif"]),
url: z.string(),
thumbnail_url: z.string(),
width: z.number(),
height: z.number(),
duration: z.number(),
format: z.string(),
})
)
.optional(),
mosaic: z
.object({
type: z.literal("mosaic_photo"),
width: z.number().optional(),
height: z.number().optional(),
formats: z.object({
webp: z.string(),
jpeg: z.string(),
}),
})
.optional(),
})
.optional(),
}),
});
export async function askFxtwitter(
screenName: string,
id: string,
translateTo?: string
) {
const url = `https://api.fxtwitter.com/${screenName}/status/${id}/${translateTo}`;
const response = await fetch(url, {
headers: {
"User-Agent": USER_AGENT,
},
});
const json = await response.json();
console.debug("fxtwitter res", JSON.stringify(json));
if (response.status !== 200) {
throw new Error(`Fxtwitter returned status ${response.status}`);
}
return FxtwitterResult.parse(json);
}