mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
27 lines
815 B
JavaScript
27 lines
815 B
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import minimatch from 'minimatch'
|
|
|
|
let oEmbedProvidersFile = fs.readFileSync(path.join(__dirname, './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
|
|
}
|