update scripts

This commit is contained in:
Nolan Lawson 2018-03-05 20:51:42 -08:00
parent 9872f6073e
commit 5c38554a38
6 changed files with 50 additions and 38 deletions

View file

@ -1,8 +1,8 @@
const times = require('lodash/times')
import times from 'lodash/times'
export const actions = times(30, i => ({
post: {
text: (i + 1)
text: '' + (i + 1)
},
user: 'admin'
})).concat([
@ -95,6 +95,14 @@ export const actions = times(30, i => ({
user: 'quux',
follow: 'foobar'
},
{
user: 'admin',
follow: 'quux'
},
{
user: 'foobar',
follow: 'quux'
},
{
user: 'admin',
post: {
@ -139,10 +147,6 @@ export const actions = times(30, i => ({
privacy: 'private'
}
},
{
user: 'admin',
boost: 2
},
{
user: 'admin',
favorite: 2
@ -180,10 +184,6 @@ export const actions = times(30, i => ({
user: 'quux',
pin: 6
},
{
user: 'admin',
boost: 5
},
{
user: 'admin',
favorite: 5

View file

@ -5,16 +5,20 @@ import { uploadMedia } from '../routes/_api/media'
import { followAccount } from '../routes/_api/follow'
import { favoriteStatus } from '../routes/_api/favorite'
import { reblogStatus } from '../routes/_api/reblog'
import fetch from 'node-fetch'
import FileApi from 'file-api'
import path from 'path'
global.File = require('file-api').File
global.FormData = require('file-api').FormData
global.fetch = require('node-fetch')
async function restoreMastodonData () {
global.File = FileApi.File
global.FormData = FileApi.FormData
global.fetch = fetch
export async function restoreMastodonData () {
debugger
console.log('Restoring mastodon data...')
let internalIdsToIds = {}
for (let action of actions) {
console.log(JSON.stringify(action))
let accessToken = users[action.user].accessToken
if (action.post) {
let { text, media, sensitive, spoiler, privacy, inReplyTo, internalId } = action.post
@ -32,13 +36,16 @@ async function restoreMastodonData () {
internalIdsToIds[internalId] = status.id
}
} else if (action.follow) {
await followAccount('localhost:3000', accessToken, action.follow)
await followAccount('localhost:3000', accessToken, users[action.follow].id)
} else if (action.favorite) {
await favoriteStatus('localhost:3000', accessToken, internalIdsToIds[action.favorite])
} else if (action.boost) {
await reblogStatus('localhost:3000', accessToken, internalIdsToIds[action.favorite])
await reblogStatus('localhost:3000', accessToken, internalIdsToIds[action.boost])
}
}
}
module.exports = restoreMastodonData
restoreMastodonData().catch(err => {
console.error(err)
process.exit(1)
})

View file

@ -1,14 +1,16 @@
const restoreMastodonData = require('./restore-mastodon-data')
const pify = require('pify')
const exec = require('child-process-promise').exec
const spawn = require('child-process-promise').spawn
const dir = __dirname
const path = require('path')
const fs = require('fs')
import { restoreMastodonData } from './restore-mastodon-data'
import pify from 'pify'
import childProcessPromise from 'child-process-promise'
import path from 'path'
import fs from 'fs'
import { waitForMastodonToStart } from './wait-for-mastodon-to-start'
const exec = childProcessPromise.exec
const spawn = childProcessPromise.spawn
const mkdirp = pify(mkdirpCB)
const stat = pify(fs.stat.bind(fs))
const writeFile = pify(fs.writeFile.bind(fs))
const mkdirp = pify(require('mkdirp'))
const waitForMastodonToStart = require('./wait-for-mastodon-to-start')
const dir = __dirname
const envFile = `
PAPERCLIP_SECRET=foo
@ -71,9 +73,9 @@ async function runMastodon () {
async function main () {
await cloneMastodon()
//await setupMastodonDatabase()
await setupMastodonDatabase()
await runMastodon()
//await restoreMastodonData()
await restoreMastodonData()
}
process.on('SIGINT', function () {

View file

@ -1,6 +1,6 @@
const fetch = require('node-fetch')
import fetch from 'node-fetch'
async function waitForMastodonToStart () {
export async function waitForMastodonToStart () {
while (true) {
try {
let json = await ((await fetch('http://127.0.0.1:3000/api/v1/instance')).json())
@ -16,8 +16,6 @@ async function waitForMastodonToStart () {
console.log('Mastodon started up')
}
module.exports = waitForMastodonToStart
if (require.main === module) {
waitForMastodonToStart().catch(err => {
console.error(err)

View file

@ -109,6 +109,7 @@
]
},
"@std/esm": {
"mode": "js"
"mode": "js",
"cjs": "vars"
}
}

View file

@ -2,21 +2,25 @@ export const users = {
admin: {
username: 'admin',
password: 'mastodonadmin',
accessToken: '1a62cc93aa6ccdad5a1048bd37b627c9df72f68c7f4b87d2daaeb83010ff44ab'
accessToken: '1a62cc93aa6ccdad5a1048bd37b627c9df72f68c7f4b87d2daaeb83010ff44ab',
id: 1
},
foobar: {
username: 'foobar',
password: 'foobarfoobar',
accessToken: '67868cd5b1f1279697ffffdb44c144b0ae427d74f4540717b67bf4a9c5c5c346'
accessToken: '67868cd5b1f1279697ffffdb44c144b0ae427d74f4540717b67bf4a9c5c5c346',
id: 2
},
quux: {
username: 'quux',
password: 'quuxquuxquux',
accessToken: 'd100083c1749392da7e1c12e63a6fba75f15ea1fbce93361d722889abf418464'
accessToken: 'd100083c1749392da7e1c12e63a6fba75f15ea1fbce93361d722889abf418464',
id: 3
},
ExternalLinks: {
username: 'ExternalLinks',
password: 'ExternalLinksExternalLink',
accessToken: 'e9a463ba1729ae0049a97a312af702cb3d08d84de1cc8d6da3fad90af068117b'
accessToken: 'e9a463ba1729ae0049a97a312af702cb3d08d84de1cc8d6da3fad90af068117b',
id: 4
}
}