1
0
mirror of https://github.com/nolanlawson/pinafore synced 2025-02-15 10:50:46 +01:00

54 lines
1.4 KiB
JavaScript
Raw Normal View History

import { get, paramsString, DEFAULT_TIMEOUT } from '../_utils/ajax'
2018-02-24 14:49:28 -08:00
import { auth, basename } from './utils'
2018-01-18 20:25:34 -08:00
2018-02-08 22:29:29 -08:00
function getTimelineUrlPath (timeline) {
2018-01-21 20:02:32 -08:00
switch (timeline) {
case 'local':
case 'federated':
2018-01-22 21:16:27 -08:00
return 'timelines/public'
2018-01-21 20:02:32 -08:00
case 'home':
2018-01-22 21:16:27 -08:00
return 'timelines/home'
case 'notifications':
return 'notifications'
case 'favorites':
return 'favourites'
2018-01-22 21:16:27 -08:00
}
if (timeline.startsWith('tag/')) {
return 'timelines/tag'
} else if (timeline.startsWith('account/')) {
return 'accounts'
2018-02-08 09:15:25 -08:00
} else if (timeline.startsWith('list/')) {
return 'timelines/list'
2018-01-21 20:02:32 -08:00
}
}
2018-02-08 22:29:29 -08:00
export function getTimeline (instanceName, accessToken, timeline, maxId, since) {
2018-01-22 21:16:27 -08:00
let timelineUrlName = getTimelineUrlPath(timeline)
let url = `${basename(instanceName)}/api/v1/${timelineUrlName}`
2018-01-18 20:25:34 -08:00
2018-01-21 20:02:32 -08:00
if (timeline.startsWith('tag/')) {
url += '/' + timeline.split('/').slice(-1)[0]
2018-01-22 21:16:27 -08:00
} else if (timeline.startsWith('account/')) {
2018-02-08 09:15:25 -08:00
url += '/' + timeline.split('/').slice(-1)[0] + '/statuses'
} else if (timeline.startsWith('list/')) {
url += '/' + timeline.split('/').slice(-1)[0]
2018-01-21 20:02:32 -08:00
}
2018-01-18 20:25:34 -08:00
let params = {}
if (since) {
params.since = since
}
if (maxId) {
params.max_id = maxId
}
2018-01-18 23:37:43 -08:00
if (timeline === 'local') {
params.local = true
}
2018-01-18 20:25:34 -08:00
url += '?' + paramsString(params)
return get(url, auth(accessToken), {timeout: DEFAULT_TIMEOUT})
2018-02-08 22:29:29 -08:00
}