From 6dc2084bc7c58eb5507d984aa7f41603dd1dd160 Mon Sep 17 00:00:00 2001 From: HF Date: Thu, 10 Feb 2022 21:25:54 +0100 Subject: [PATCH] add odysee support and remove it cause no CORSE support --- src/components/embeds/Odysee.jsx | 66 ++++++++++++++++++++++++++++++++ src/components/embeds/TikTok.jsx | 2 +- src/components/embeds/index.js | 2 + src/styles/default.css | 2 +- 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/components/embeds/Odysee.jsx diff --git a/src/components/embeds/Odysee.jsx b/src/components/embeds/Odysee.jsx new file mode 100644 index 0000000..c79314c --- /dev/null +++ b/src/components/embeds/Odysee.jsx @@ -0,0 +1,66 @@ +/* + * Odysee oembed API does not allow CORS request, + * therefor we can't use it right now. + * Still keeping this here in case that the policy changes in the future + */ +import React, { useState, useEffect } from 'react'; + +function getUserFromUrl(url) { + let aPos = url.indexOf('/@'); + if (aPos === -1) { + return url; + } + aPos += 1; + let bPos = url.indexOf(':', aPos); + if (bPos === -1) { + bPos = url.length; + } + return url.substring(aPos, bPos); +} + +const Odysee = ({ url }) => { + const [embedUrl, setEmbedUrl] = useState(null); + + useEffect(async () => { + const prot = window.location.protocol.startsWith('http') + ? window.location.protocol : 'https'; + // eslint-disable-next-line max-len + const odurl = `${prot}//odysee.com/$/oembed?url=${encodeURIComponent(url)}&format=json`; + const resp = await fetch(odurl); + const embedData = await resp.json(); + if (embedData.html) { + const { html } = embedData; + let emUrl = html.substring(html.indexOf('src="') + 5); + emUrl = emUrl.substring(0, emUrl.indexOf('"')); + setEmbedUrl(emUrl); + } + }, []); + + if (!embedUrl) { + return
LOADING
; + } + + return ( +
+