Fix link previews for YouTube Music

This commit is contained in:
Evan Hahn 2021-01-11 15:43:44 -06:00 committed by GitHub
parent 0a35489696
commit 172598b354
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View file

@ -1,4 +1,4 @@
// Copyright 2020 Signal Messenger, LLC
// Copyright 2020-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { RequestInit, Response } from 'node-fetch';
@ -13,6 +13,8 @@ import {
MIMEType,
} from '../types/MIME';
const USER_AGENT = 'WhatsApp/2';
const MAX_REQUEST_COUNT_WITH_REDIRECTS = 20;
// Lifted from the `fetch` spec [here][0].
@ -408,7 +410,7 @@ export async function fetchLinkPreviewMetadata(
response = await fetchWithRedirects(fetchFn, href, {
headers: {
Accept: 'text/html,application/xhtml+xml',
'User-Agent': 'WhatsApp',
'User-Agent': USER_AGENT,
},
signal: abortSignal,
});
@ -504,7 +506,7 @@ export async function fetchLinkPreviewImage(
try {
response = await fetchWithRedirects(fetchFn, href, {
headers: {
'User-Agent': 'WhatsApp',
'User-Agent': USER_AGENT,
},
size: MAX_IMAGE_CONTENT_LENGTH,
signal: abortSignal,