1
0
Fork 0
peertube/server/initializers/migrations/0605-actor-missing-keys.ts
Chocobozzz 8795d6f254
Fix broken local actors
Some channels can't federate because they don't have public/private
keys, maybe because the generation failed for various reasons
2021-02-26 14:22:25 +01:00

34 lines
1,020 B
TypeScript

import * as Sequelize from 'sequelize'
import { createPrivateKey, getPublicKey } from '../../helpers/core-utils'
import { PRIVATE_RSA_KEY_SIZE } from '../constants'
async function up (utils: {
transaction: Sequelize.Transaction
queryInterface: Sequelize.QueryInterface
sequelize: Sequelize.Sequelize
db: any
}): Promise<void> {
{
const query = 'SELECT * FROM "actor" WHERE "serverId" IS NULL AND "publicKey" IS NULL'
const options = { type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT }
const actors = await utils.sequelize.query<any>(query, options)
for (const actor of actors) {
const { key } = await createPrivateKey(PRIVATE_RSA_KEY_SIZE)
const { publicKey } = await getPublicKey(key)
const queryUpdate = `UPDATE "actor" SET "publicKey" = '${publicKey}', "privateKey" = '${key}' WHERE id = ${actor.id}`
await utils.sequelize.query(queryUpdate)
}
}
}
function down (options) {
throw new Error('Not implemented.')
}
export {
up,
down
}