mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
31 lines
843 B
JavaScript
31 lines
843 B
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import minimatch from 'minimatch'
|
|
|
|
let oEmbedProvidersFile = fs.readFileSync(
|
|
path.join(__dirname, '../../../../public/providers.json'),
|
|
'utf8',
|
|
)
|
|
|
|
// some providers allow a format parameter
|
|
// we need JSON
|
|
oEmbedProvidersFile = oEmbedProvidersFile.replace(/\{format\}/g, 'json')
|
|
const oEmbedProviders = JSON.parse(oEmbedProvidersFile)
|
|
|
|
export default function (embedUrl) {
|
|
for (const provider of oEmbedProviders) {
|
|
for (const endpoint of provider.endpoints) {
|
|
const { schemes = [], url } = endpoint
|
|
if (schemes.some((scheme) => minimatch(embedUrl, scheme))) return url
|
|
}
|
|
const { hostname } = new URL(embedUrl)
|
|
if (provider.provider_url.includes(hostname)) {
|
|
const {
|
|
endpoints: [{ url }],
|
|
} = provider
|
|
return url
|
|
}
|
|
}
|
|
return null
|
|
}
|