-
Notifications
You must be signed in to change notification settings - Fork 0
/
cobalt.ts
64 lines (63 loc) · 1.4 KB
/
cobalt.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
import { z } from "zod";
import { USER_AGENT } from "./consts";
export const CobaltResult = z.discriminatedUnion("status", [
z.object({
status: z.literal("error"),
error: z.object({
code: z.string(),
context: z
.object({
service: z.string().optional(),
limit: z.number().optional(),
})
.optional(),
}),
}),
z.object({
status: z.literal("picker"),
audio: z.string().optional(),
audioFilename: z.string().optional(),
picker: z.array(
z.object({
type: z.enum(["photo", "video", "gif"]),
url: z.string(),
thumb: z.string().optional(),
})
),
}),
z.object({
status: z.enum(["tunnel", "redirect"]),
url: z.string(),
filename: z.string(),
}),
]);
export type CobaltResult = z.infer<typeof CobaltResult>;
export type VideoQuality =
| "144"
| "240"
| "360"
| "480"
| "720"
| "1080"
| "1440"
| "2160"
| "4320"
| "max";
export async function askCobalt(
url: string,
options?: {
videoQuality?: VideoQuality;
}
) {
const response = await fetch(`https://dorsiblancoapicobalt.nulo.in/`, {
method: "POST",
body: JSON.stringify({ url, ...options }),
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"User-Agent": USER_AGENT,
},
});
const data = await response.json();
return CobaltResult.parse(data);
}