api/facebook: add dispatcher support

This commit is contained in:
jj 2025-02-17 19:15:24 +00:00
parent b540e48ffb
commit 293164bac7
No known key found for this signature in database
2 changed files with 7 additions and 6 deletions

View File

@ -227,7 +227,8 @@ export default async function({ host, patternMatch, params }) {
case "facebook": case "facebook":
r = await facebook({ r = await facebook({
...patternMatch ...patternMatch,
dispatcher
}); });
break; break;

View File

@ -8,8 +8,8 @@ const headers = {
'Sec-Fetch-Site': 'none', 'Sec-Fetch-Site': 'none',
} }
const resolveUrl = (url) => { const resolveUrl = (url, dispatcher) => {
return fetch(url, { headers }) return fetch(url, { headers, dispatcher })
.then(r => { .then(r => {
if (r.headers.get('location')) { if (r.headers.get('location')) {
return decodeURIComponent(r.headers.get('location')); return decodeURIComponent(r.headers.get('location'));
@ -23,13 +23,13 @@ const resolveUrl = (url) => {
.catch(() => false); .catch(() => false);
} }
export default async function({ id, shareType, shortLink }) { export default async function({ id, shareType, shortLink, dispatcher }) {
let url = `https://web.facebook.com/i/videos/${id}`; let url = `https://web.facebook.com/i/videos/${id}`;
if (shareType) url = `https://web.facebook.com/share/${shareType}/${id}`; if (shareType) url = `https://web.facebook.com/share/${shareType}/${id}`;
if (shortLink) url = await resolveUrl(`https://fb.watch/${shortLink}`); if (shortLink) url = await resolveUrl(`https://fb.watch/${shortLink}`, dispatcher);
const html = await fetch(url, { headers }) const html = await fetch(url, { headers, dispatcher })
.then(r => r.text()) .then(r => r.text())
.catch(() => false); .catch(() => false);