pinafore/routes/_utils/mastodon/timelines.js

42 lines
859 B
JavaScript
Raw Normal View History

2018-01-19 05:25:34 +01:00
import { get, paramsString } from '../ajax'
import { basename } from './utils'
2018-01-19 05:25:34 +01:00
2018-01-22 05:02:32 +01:00
function getTimelineUrlName(timeline) {
switch (timeline) {
case 'local':
case 'federated':
return 'public'
case 'home':
return 'home'
default:
return 'tag'
}
}
2018-01-19 08:37:43 +01:00
export function getTimeline(instanceName, accessToken, timeline, maxId, since) {
2018-01-22 05:02:32 +01:00
let timelineUrlName = getTimelineUrlName(timeline)
2018-01-19 08:37:43 +01:00
let url = `${basename(instanceName)}/api/v1/timelines/${timelineUrlName}`
2018-01-19 05:25:34 +01:00
2018-01-22 05:02:32 +01:00
if (timeline.startsWith('tag/')) {
url += '/' + timeline.split('/').slice(-1)[0]
}
2018-01-19 05:25:34 +01:00
let params = {}
if (since) {
params.since = since
}
if (maxId) {
params.max_id = maxId
}
2018-01-19 08:37:43 +01:00
if (timeline === 'local') {
params.local = true
}
2018-01-19 05:25:34 +01:00
url += '?' + paramsString(params)
return get(url, {
'Authorization': `Bearer ${accessToken}`
})
}