Pinafore-Web-Client-Frontend/src/routes/_api/statuses.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

import { auth, basename } from './utils.js'
import { DEFAULT_TIMEOUT, get, post, WRITE_TIMEOUT } from '../_utils/ajax.js'
2018-03-05 01:27:15 +01:00
2018-03-05 02:16:33 +01:00
export async function postStatus (instanceName, accessToken, text, inReplyToId, mediaIds,
sensitive, spoilerText, visibility, poll) {
2019-08-03 22:49:37 +02:00
const url = `${basename(instanceName)}/api/v1/statuses`
2018-03-05 01:27:15 +01:00
2019-08-03 22:49:37 +02:00
const body = {
2018-03-05 01:27:15 +01:00
status: text,
in_reply_to_id: inReplyToId,
media_ids: mediaIds,
2022-11-18 18:32:31 +01:00
sensitive,
2018-03-05 01:27:15 +01:00
spoiler_text: spoilerText,
2022-11-18 18:32:31 +01:00
visibility,
poll
2018-03-05 01:27:15 +01:00
}
2019-08-03 22:49:37 +02:00
for (const key of Object.keys(body)) {
const value = body[key]
// remove any unnecessary fields, except 'status' which must at least be an empty string
if (key !== 'status' && (!value || (Array.isArray(value) && !value.length))) {
2018-03-05 01:27:15 +01:00
delete body[key]
}
}
return post(url, body, auth(accessToken), { timeout: WRITE_TIMEOUT })
2018-03-05 02:16:33 +01:00
}
export async function getStatusContext (instanceName, accessToken, statusId) {
2019-08-03 22:49:37 +02:00
const url = `${basename(instanceName)}/api/v1/statuses/${statusId}/context`
return get(url, auth(accessToken), { timeout: DEFAULT_TIMEOUT })
}
export async function getStatus (instanceName, accessToken, statusId) {
2019-08-03 22:49:37 +02:00
const url = `${basename(instanceName)}/api/v1/statuses/${statusId}`
return get(url, auth(accessToken), { timeout: DEFAULT_TIMEOUT })
}