From f0ffef11528e67c7bef65ffca56bcf74590da15d Mon Sep 17 00:00:00 2001 From: "Nareg.T" Date: Tue, 28 Nov 2023 11:20:22 -0500 Subject: [PATCH] Update oEmbed service to support Twitter --- admin/src/translations/en.json | 2 +- server/services/oembed.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/admin/src/translations/en.json b/admin/src/translations/en.json index eb2a365..f8a404c 100644 --- a/admin/src/translations/en.json +++ b/admin/src/translations/en.json @@ -4,6 +4,6 @@ "form.button.delete": "Delete", "modal.import.title": "Import oEmbed content", "modal.import.input.label": "URL", - "modal.import.input.description": "Youtube, Vimeo, Tiktok, Soundcloud or Spotify", + "modal.import.input.description": "Youtube, Vimeo, Tiktok, Twitter, Soundcloud or Spotify", "modal.import.button.import": "Import" } diff --git a/server/services/oembed.js b/server/services/oembed.js index 07f789d..f54a250 100644 --- a/server/services/oembed.js +++ b/server/services/oembed.js @@ -16,7 +16,8 @@ module.exports = ( async fetch(url) { let data; - const matches = url.match(/^(https?:\/\/)?(www\.)?(youtu\.be|youtube\.com|soundcloud\.com|vimeo\.com|tiktok\.com|open\.spotify\.com)/i); + + const matches = url.match(/^(https?:\/\/)?(www\.)?(youtu\.be|youtube\.com|soundcloud\.com|vimeo\.com|tiktok\.com|open\.spotify\.com|twitter\.com)/i); if (matches) { try { @@ -33,6 +34,13 @@ module.exports = ( mime = 'video/youtube'; thumbnail = fetchedData.thumbnail_url; break; + + case 'twitter.com': + fetchedData = await axios.get(`https://publish.twitter.com/oembed?url=${encodeURIComponent(url)}`).then(res => res.data); + title = fetchedData.author_name; + mime = 'text/twitter'; + thumbnail = null; // Twitter oEmbed may not provide a thumbnail + break; case 'soundcloud.com': fetchedData = await axios.get(`https://www.soundcloud.com/oembed?url=${encodeURIComponent(url)}&format=json`).then(res => res.data);