pinafore/src/routes/_api/timelines.js
Nolan Lawson 4bd181d3cc
fix: update Sapper to latest (#775)
* fix: update to latest sapper

fixes #416

* fix error and debug pages

* requestIdleCallback makes column switching feel way nicer than double rAF

* add export feature

* add better csp info

* workaround for sapper sub-page issue

* clarify in readme about exporting

* fix now config

* switch from rIC to triple raf

* style-loader is no longer used

* update theming guide
2018-12-11 07:31:48 -08:00

57 lines
1.4 KiB
JavaScript

import { get, paramsString, DEFAULT_TIMEOUT } from '../_utils/ajax'
import { auth, basename } from './utils'
function getTimelineUrlPath (timeline) {
switch (timeline) {
case 'local':
case 'federated':
return 'timelines/public'
case 'home':
return 'timelines/home'
case 'notifications':
return 'notifications'
case 'favorites':
return 'favourites'
}
if (timeline.startsWith('tag/')) {
return 'timelines/tag'
} else if (timeline.startsWith('account/')) {
return 'accounts'
} else if (timeline.startsWith('list/')) {
return 'timelines/list'
}
}
export function getTimeline (instanceName, accessToken, timeline, maxId, since, limit) {
let timelineUrlName = getTimelineUrlPath(timeline)
let url = `${basename(instanceName)}/api/v1/${timelineUrlName}`
if (timeline.startsWith('tag/')) {
url += '/' + timeline.split('/').slice(-1)[0]
} else if (timeline.startsWith('account/')) {
url += '/' + timeline.split('/').slice(-1)[0] + '/statuses'
} else if (timeline.startsWith('list/')) {
url += '/' + timeline.split('/').slice(-1)[0]
}
let params = {}
if (since) {
params.since = since
}
if (maxId) {
params.max_id = maxId
}
if (limit) {
params.limit = limit
}
if (timeline === 'local') {
params.local = true
}
url += '?' + paramsString(params)
return get(url, auth(accessToken), { timeout: DEFAULT_TIMEOUT })
}