@postfetch/core 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -1
- package/dist/tiktok.d.ts +1 -0
- package/dist/twitter.d.ts +1 -0
- package/package.json +1 -1
- package/src/tiktok.ts +5 -1
- package/src/twitter.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1267,9 +1267,12 @@ async function fetchVideoPage(net, id, userAgent) {
|
|
|
1267
1267
|
});
|
|
1268
1268
|
return { cookie: cookieHeader(page.headers), item: itemStruct(await page.text()) };
|
|
1269
1269
|
}
|
|
1270
|
+
function isShortlinkHost(hostname) {
|
|
1271
|
+
return hostname === "vm.tiktok.com" || hostname === "vt.tiktok.com";
|
|
1272
|
+
}
|
|
1270
1273
|
async function followShortlink(net, userAgent, input) {
|
|
1271
1274
|
const url = asUrl(input);
|
|
1272
|
-
if (!url.hostname
|
|
1275
|
+
if (!isShortlinkHost(url.hostname)) {
|
|
1273
1276
|
return input;
|
|
1274
1277
|
}
|
|
1275
1278
|
const response = await net(input, { headers: { "user-agent": userAgent }, redirect: "manual" }, 1);
|
package/dist/tiktok.d.ts
CHANGED
package/dist/twitter.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postfetch/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Zero-dependency typed core that turns Facebook, Instagram, Pinterest, Reddit, SoundCloud, TikTok, X and YouTube post URLs into media files.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/tiktok.ts
CHANGED
|
@@ -56,9 +56,13 @@ async function fetchVideoPage(
|
|
|
56
56
|
return { cookie: cookieHeader(page.headers), item: itemStruct(await page.text()) };
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
export function isShortlinkHost(hostname: string): boolean {
|
|
60
|
+
return hostname === "vm.tiktok.com" || hostname === "vt.tiktok.com";
|
|
61
|
+
}
|
|
62
|
+
|
|
59
63
|
async function followShortlink(net: Net, userAgent: string, input: string): Promise<string> {
|
|
60
64
|
const url = asUrl(input);
|
|
61
|
-
if (!url.hostname
|
|
65
|
+
if (!isShortlinkHost(url.hostname)) {
|
|
62
66
|
return input;
|
|
63
67
|
}
|
|
64
68
|
const response = await net(input, { headers: { "user-agent": userAgent }, redirect: "manual" }, 1);
|
package/src/twitter.ts
CHANGED
|
@@ -76,6 +76,6 @@ function bestVariant(entry: Json): string | null {
|
|
|
76
76
|
return best ? string(best.url) : null;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
function tweetId(input: string): string | null {
|
|
79
|
+
export function tweetId(input: string): string | null {
|
|
80
80
|
return asUrl(input).pathname.match(/\/status(?:es)?\/(\d+)/)?.[1] ?? null;
|
|
81
81
|
}
|