Update migrate.ts

This commit is contained in:
syuilo 2019-04-09 19:02:09 +09:00
parent 9b594880c8
commit db4378415e
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
1 changed files with 23 additions and 2 deletions

View File

@ -21,6 +21,9 @@ import { Poll } from './models/entities/poll';
import { PollVote } from './models/entities/poll-vote'; import { PollVote } from './models/entities/poll-vote';
import { NoteFavorite } from './models/entities/note-favorite'; import { NoteFavorite } from './models/entities/note-favorite';
import { NoteReaction } from './models/entities/note-reaction'; import { NoteReaction } from './models/entities/note-reaction';
import { UserPublickey } from './models/entities/user-publickey';
import { UserKeypair } from './models/entities/user-keypair';
import { extractPublic } from './crypto_key';
const u = (config as any).mongodb.user ? encodeURIComponent((config as any).mongodb.user) : null; const u = (config as any).mongodb.user ? encodeURIComponent((config as any).mongodb.user) : null;
const p = (config as any).mongodb.pass ? encodeURIComponent((config as any).mongodb.pass) : null; const p = (config as any).mongodb.pass ? encodeURIComponent((config as any).mongodb.pass) : null;
@ -72,9 +75,11 @@ async function main() {
const PollVotes = getRepository(PollVote); const PollVotes = getRepository(PollVote);
const NoteFavorites = getRepository(NoteFavorite); const NoteFavorites = getRepository(NoteFavorite);
const NoteReactions = getRepository(NoteReaction); const NoteReactions = getRepository(NoteReaction);
const UserPublickeys = getRepository(UserPublickey);
const UserKeypairs = getRepository(UserKeypair);
async function migrateUser(user: any) { async function migrateUser(user: any) {
await Users.insert({ await Users.save({
id: user._id.toHexString(), id: user._id.toHexString(),
createdAt: user.createdAt || new Date(), createdAt: user.createdAt || new Date(),
username: user.username, username: user.username,
@ -99,6 +104,22 @@ async function main() {
sharedInbox: user.sharedInbox, sharedInbox: user.sharedInbox,
uri: user.uri, uri: user.uri,
}); });
if (user.publicKey) {
await UserPublickeys.save({
id: genId(),
userId: user._id.toHexString(),
keyId: user.publicKey.id,
keyPem: user.publicKey.publicKeyPem
});
}
if (user.keypair) {
await UserKeypairs.save({
id: genId(),
userId: user._id.toHexString(),
publicKey: extractPublic(user.keypair),
privateKey: user.keypair,
});
}
} }
async function migrateFollowing(following: any) { async function migrateFollowing(following: any) {
@ -204,7 +225,7 @@ async function main() {
} }
async function migrateNote(note: any) { async function migrateNote(note: any) {
await Notes.insert({ await Notes.save({
id: note._id.toHexString(), id: note._id.toHexString(),
createdAt: note.createdAt || new Date(), createdAt: note.createdAt || new Date(),
text: note.text, text: note.text,