Edit mapping types to use constants
This commit is contained in:
+7
-32
@@ -7,51 +7,26 @@ import { handle as handleUser } from './handlers/users'
|
||||
import log from './helpers/logger'
|
||||
import { initStorage } from './helpers/storage'
|
||||
import { whoami } from './helpers/synapse'
|
||||
import { Entity, entities } from './Entities'
|
||||
|
||||
log.info('rocketchat2matrix starts.')
|
||||
|
||||
const enum Entities {
|
||||
Users = 'users',
|
||||
Rooms = 'rooms',
|
||||
Messages = 'messages',
|
||||
}
|
||||
|
||||
type EntityConfig = {
|
||||
filename: string
|
||||
mappingType: number
|
||||
}
|
||||
|
||||
const entities: { [key in Entities]: EntityConfig } = {
|
||||
users: {
|
||||
filename: 'users.json',
|
||||
mappingType: 0,
|
||||
},
|
||||
rooms: {
|
||||
filename: 'rocketchat_room.json',
|
||||
mappingType: 1,
|
||||
},
|
||||
messages: {
|
||||
filename: 'rocketchat_message.json',
|
||||
mappingType: 2,
|
||||
},
|
||||
}
|
||||
|
||||
async function loadRcExport(entity: Entities) {
|
||||
async function loadRcExport(entity: Entity) {
|
||||
const rl = new lineByLine(`./inputs/${entities[entity].filename}`)
|
||||
|
||||
let line: false | Buffer
|
||||
while ((line = rl.next())) {
|
||||
const item = JSON.parse(line.toString())
|
||||
switch (entity) {
|
||||
case Entities.Users:
|
||||
case Entity.Users:
|
||||
await handleUser(item)
|
||||
break
|
||||
|
||||
case Entities.Rooms:
|
||||
case Entity.Rooms:
|
||||
await handleRoom(item)
|
||||
break
|
||||
|
||||
case Entities.Messages:
|
||||
case Entity.Messages:
|
||||
log.debug(`Message: ${item.name}`)
|
||||
break
|
||||
|
||||
@@ -66,9 +41,9 @@ async function main() {
|
||||
await whoami()
|
||||
await initStorage()
|
||||
log.info('Parsing users')
|
||||
await loadRcExport(Entities.Users)
|
||||
await loadRcExport(Entity.Users)
|
||||
log.info('Parsing rooms')
|
||||
await loadRcExport(Entities.Rooms)
|
||||
await loadRcExport(Entity.Rooms)
|
||||
log.info('Done.')
|
||||
} catch (error) {
|
||||
log.error(`Encountered an error while booting up: ${error}`, error)
|
||||
|
||||
Reference in New Issue
Block a user