2018-03-06 05:29:49 +01:00
|
|
|
import { actions } from './mastodon-data'
|
|
|
|
import { users } from '../tests/users'
|
2018-04-29 21:28:44 +02:00
|
|
|
import { postStatus } from '../routes/_api/statuses'
|
2018-03-06 05:29:49 +01:00
|
|
|
import { followAccount } from '../routes/_api/follow'
|
|
|
|
import { favoriteStatus } from '../routes/_api/favorite'
|
|
|
|
import { reblogStatus } from '../routes/_api/reblog'
|
2018-03-06 05:51:42 +01:00
|
|
|
import fetch from 'node-fetch'
|
|
|
|
import FileApi from 'file-api'
|
2018-04-29 21:28:44 +02:00
|
|
|
import { pinStatus } from '../routes/_api/pin'
|
2018-12-01 09:10:30 +01:00
|
|
|
import { submitMedia } from '../tests/submitMedia'
|
2018-03-05 19:10:50 +01:00
|
|
|
|
2018-03-06 05:51:42 +01:00
|
|
|
global.File = FileApi.File
|
|
|
|
global.FormData = FileApi.FormData
|
|
|
|
global.fetch = fetch
|
|
|
|
|
|
|
|
export async function restoreMastodonData () {
|
2018-03-05 19:10:50 +01:00
|
|
|
console.log('Restoring mastodon data...')
|
2018-03-06 05:29:49 +01:00
|
|
|
let internalIdsToIds = {}
|
|
|
|
for (let action of actions) {
|
2018-11-11 20:12:41 +01:00
|
|
|
if (!action.post) {
|
|
|
|
// If the action is a boost, favorite, etc., then it needs to
|
|
|
|
// be delayed, otherwise it may appear in an unpredictable order and break the tests.
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
|
|
}
|
2018-03-06 05:51:42 +01:00
|
|
|
console.log(JSON.stringify(action))
|
2018-03-06 05:29:49 +01:00
|
|
|
let accessToken = users[action.user].accessToken
|
2018-03-06 18:03:59 +01:00
|
|
|
|
2018-03-06 05:29:49 +01:00
|
|
|
if (action.post) {
|
|
|
|
let { text, media, sensitive, spoiler, privacy, inReplyTo, internalId } = action.post
|
|
|
|
let mediaIds = media && await Promise.all(media.map(async mediaItem => {
|
2018-03-06 08:46:50 +01:00
|
|
|
let mediaResponse = await submitMedia(accessToken, mediaItem, 'kitten')
|
2018-03-06 05:29:49 +01:00
|
|
|
return mediaResponse.id
|
|
|
|
}))
|
2018-11-12 17:42:08 +01:00
|
|
|
let inReplyToId = inReplyTo && internalIdsToIds[inReplyTo]
|
|
|
|
let status = await postStatus('localhost:3000', accessToken, text, inReplyToId, mediaIds,
|
2018-03-06 05:29:49 +01:00
|
|
|
sensitive, spoiler, privacy || 'public')
|
|
|
|
if (typeof internalId !== 'undefined') {
|
|
|
|
internalIdsToIds[internalId] = status.id
|
|
|
|
}
|
|
|
|
} else if (action.follow) {
|
2018-03-06 05:51:42 +01:00
|
|
|
await followAccount('localhost:3000', accessToken, users[action.follow].id)
|
2018-03-06 05:29:49 +01:00
|
|
|
} else if (action.favorite) {
|
|
|
|
await favoriteStatus('localhost:3000', accessToken, internalIdsToIds[action.favorite])
|
|
|
|
} else if (action.boost) {
|
2018-03-06 05:51:42 +01:00
|
|
|
await reblogStatus('localhost:3000', accessToken, internalIdsToIds[action.boost])
|
2018-03-06 07:36:54 +01:00
|
|
|
} else if (action.pin) {
|
|
|
|
await pinStatus('localhost:3000', accessToken, internalIdsToIds[action.pin])
|
2018-03-06 05:29:49 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-06 06:21:28 +01:00
|
|
|
console.log('Restored mastodon data')
|
2018-03-06 08:56:48 +01:00
|
|
|
}
|