Skip to content

Commit

Permalink
Merge pull request #22 from nareg23/twitter-support
Browse files Browse the repository at this point in the history
Update oEmbed service to support Twitter
  • Loading branch information
nicolashmln authored Dec 8, 2023
2 parents 21bf9d1 + f0ffef1 commit fdbe2b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion admin/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
10 changes: 9 additions & 1 deletion server/services/oembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit fdbe2b8

Please sign in to comment.