-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae2fe4c
commit 149a84a
Showing
4 changed files
with
228 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const USER_AGENT = "dlbot/1.0 (+https://nulo.lol/dlbot)"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters