2022-04-28 17:18:50 +02:00
|
|
|
import { favoriteStatus } from '../src/routes/_api/favorite.js'
|
2018-02-25 06:27:32 +01:00
|
|
|
import fetch from 'node-fetch'
|
2018-03-10 19:54:16 +01:00
|
|
|
import FileApi from 'file-api'
|
2022-04-28 17:18:50 +02:00
|
|
|
import { users } from './users.js'
|
|
|
|
import { postStatus } from '../src/routes/_api/statuses.js'
|
|
|
|
import { deleteStatus } from '../src/routes/_api/delete.js'
|
|
|
|
import { authorizeFollowRequest, getFollowRequests } from '../src/routes/_api/followRequests.js'
|
|
|
|
import { followAccount, unfollowAccount } from '../src/routes/_api/follow.js'
|
|
|
|
import { updateCredentials } from '../src/routes/_api/updateCredentials.js'
|
|
|
|
import { reblogStatus } from '../src/routes/_api/reblog.js'
|
2021-07-05 05:19:04 +02:00
|
|
|
import { submitMedia } from './submitMedia.js'
|
2022-04-28 17:18:50 +02:00
|
|
|
import { voteOnPoll } from '../src/routes/_api/polls.js'
|
|
|
|
import { POLL_EXPIRY_DEFAULT } from '../src/routes/_static/polls.js'
|
|
|
|
import { createList, getLists } from '../src/routes/_api/lists.js'
|
|
|
|
import { createFilter, deleteFilter, getFilters } from '../src/routes/_api/filters.js'
|
2018-03-10 19:54:16 +01:00
|
|
|
|
2018-03-06 08:56:48 +01:00
|
|
|
global.fetch = fetch
|
2018-03-10 19:54:16 +01:00
|
|
|
global.File = FileApi.File
|
|
|
|
global.FormData = FileApi.FormData
|
2018-02-25 06:27:32 +01:00
|
|
|
|
2018-03-11 01:21:10 +01:00
|
|
|
const instanceName = 'localhost:3000'
|
|
|
|
|
2018-03-16 18:06:02 +01:00
|
|
|
export async function favoriteStatusAs (username, statusId) {
|
|
|
|
return favoriteStatus(instanceName, users[username].accessToken, statusId)
|
2018-02-25 06:27:32 +01:00
|
|
|
}
|
2018-03-10 19:54:16 +01:00
|
|
|
|
2018-08-28 15:45:15 +02:00
|
|
|
export async function reblogStatusAs (username, statusId) {
|
|
|
|
return reblogStatus(instanceName, users[username].accessToken, statusId)
|
|
|
|
}
|
|
|
|
|
2018-03-16 18:06:02 +01:00
|
|
|
export async function postAs (username, text) {
|
|
|
|
return postStatus(instanceName, users[username].accessToken, text,
|
2018-03-10 19:54:16 +01:00
|
|
|
null, null, false, null, 'public')
|
|
|
|
}
|
2018-03-11 01:21:10 +01:00
|
|
|
|
2018-12-04 08:23:29 +01:00
|
|
|
export async function postWithSpoilerAndPrivacyAs (username, text, spoiler, privacy) {
|
|
|
|
return postStatus(instanceName, users[username].accessToken, text,
|
|
|
|
null, null, true, spoiler, privacy)
|
|
|
|
}
|
|
|
|
|
2020-08-31 03:08:55 +02:00
|
|
|
export async function postStatusWithMediaAs (username, status, filename, alt, sensitive) {
|
|
|
|
const mediaResponse = await submitMedia(users[username].accessToken, filename, alt)
|
|
|
|
return postStatus(instanceName, users[username].accessToken, status,
|
|
|
|
null, [mediaResponse.id], !!sensitive, null, 'public')
|
|
|
|
}
|
|
|
|
|
2019-09-17 09:19:53 +02:00
|
|
|
export async function postEmptyStatusWithMediaAs (username, filename, alt, sensitive) {
|
2019-08-03 22:49:37 +02:00
|
|
|
const mediaResponse = await submitMedia(users[username].accessToken, filename, alt)
|
2018-12-01 09:10:30 +01:00
|
|
|
return postStatus(instanceName, users[username].accessToken, '',
|
2019-09-17 09:19:53 +02:00
|
|
|
null, [mediaResponse.id], !!sensitive, null, 'public')
|
2018-12-01 09:10:30 +01:00
|
|
|
}
|
|
|
|
|
2018-03-16 18:06:02 +01:00
|
|
|
export async function postReplyAs (username, text, inReplyTo) {
|
|
|
|
return postStatus(instanceName, users[username].accessToken, text,
|
2018-03-11 05:24:07 +01:00
|
|
|
inReplyTo, null, false, null, 'public')
|
|
|
|
}
|
|
|
|
|
2021-02-28 03:31:53 +01:00
|
|
|
export async function postReplyWithSpoilerAs (username, text, inReplyTo, spoilerText) {
|
|
|
|
return postStatus(instanceName, users[username].accessToken, text,
|
|
|
|
inReplyTo, null, false, spoilerText, 'public')
|
|
|
|
}
|
|
|
|
|
2018-03-16 18:06:02 +01:00
|
|
|
export async function deleteAs (username, statusId) {
|
|
|
|
return deleteStatus(instanceName, users[username].accessToken, statusId)
|
2018-03-11 01:21:10 +01:00
|
|
|
}
|
2018-03-15 06:14:06 +01:00
|
|
|
|
2018-03-16 18:06:02 +01:00
|
|
|
export async function getFollowRequestsAs (username) {
|
|
|
|
return getFollowRequests(instanceName, users[username].accessToken)
|
2018-03-15 06:14:06 +01:00
|
|
|
}
|
|
|
|
|
2018-03-16 18:06:02 +01:00
|
|
|
export async function authorizeFollowRequestAs (username, id) {
|
|
|
|
return authorizeFollowRequest(instanceName, users[username].accessToken, id)
|
2018-03-15 06:14:06 +01:00
|
|
|
}
|
2018-04-28 23:19:39 +02:00
|
|
|
|
|
|
|
export async function followAs (username, userToFollow) {
|
|
|
|
return followAccount(instanceName, users[username].accessToken, users[userToFollow].id)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function unfollowAs (username, userToFollow) {
|
|
|
|
return unfollowAccount(instanceName, users[username].accessToken, users[userToFollow].id)
|
|
|
|
}
|
2018-08-20 00:23:40 +02:00
|
|
|
|
|
|
|
export async function updateUserDisplayNameAs (username, displayName) {
|
2018-08-30 06:42:57 +02:00
|
|
|
return updateCredentials(instanceName, users[username].accessToken, { display_name: displayName })
|
2018-08-20 00:23:40 +02:00
|
|
|
}
|
2019-05-27 21:31:35 +02:00
|
|
|
|
2020-05-11 04:41:55 +02:00
|
|
|
export async function createPollAs (username, content, options, multiple, spoilerText) {
|
|
|
|
return postStatus(instanceName, users[username].accessToken, content, null, null, false, spoilerText, 'public', {
|
2019-05-27 21:31:35 +02:00
|
|
|
options,
|
|
|
|
multiple,
|
|
|
|
expires_in: POLL_EXPIRY_DEFAULT
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function voteOnPollAs (username, pollId, choices) {
|
|
|
|
return voteOnPoll(instanceName, users[username].accessToken, pollId, choices.map(_ => _.toString()))
|
|
|
|
}
|
2020-08-26 07:16:14 +02:00
|
|
|
|
|
|
|
export async function createListAs (username, title) {
|
|
|
|
return createList(instanceName, users[username].accessToken, title)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getListsAs (username) {
|
|
|
|
return getLists(instanceName, users[username].accessToken)
|
|
|
|
}
|
2021-03-14 02:31:17 +01:00
|
|
|
|
|
|
|
export async function deleteAllWordFiltersAs (username) {
|
|
|
|
const accessToken = users[username].accessToken
|
|
|
|
const filters = await getFilters(instanceName, accessToken)
|
|
|
|
await Promise.all(filters.map(({ id }) => deleteFilter(instanceName, accessToken, id)))
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function createWordFilterAs (username, filter) {
|
|
|
|
const accessToken = users[username].accessToken
|
|
|
|
await createFilter(instanceName, accessToken, filter)
|
|
|
|
}
|