forked from Mastodon/mastoradio-la-radio-di-mastodon
~ d e s i g n ~
This commit is contained in:
25
src/util.js
Normal file
25
src/util.js
Normal file
@ -0,0 +1,25 @@
|
||||
import getUrls from 'get-urls'
|
||||
|
||||
export async function fetchEntries(domain, hashtags) {
|
||||
const response = await fetch(`https://${domain}/api/v1/timelines/tag/${hashtags[0]}`)
|
||||
const statuses = await response.json()
|
||||
|
||||
const entries = statuses
|
||||
.map(status => {
|
||||
const [url] = Array.from(getUrls(status.content)).filter(isSupportedUrl)
|
||||
const tags = intersection(status.tags.map(tag => tag.name), hashtags)
|
||||
|
||||
return { status, url, tags }
|
||||
})
|
||||
.filter(entry => entry.url != null)
|
||||
|
||||
return entries
|
||||
}
|
||||
|
||||
function isSupportedUrl(url) {
|
||||
return (new URL(url)).hostname === 'youtube.com'
|
||||
}
|
||||
|
||||
function intersection(xs, ys) {
|
||||
return xs.filter(x => ys.includes(x));
|
||||
}
|
Reference in New Issue
Block a user