Add switch for rc entity type
This commit is contained in:
parent
d32a2c76bb
commit
3edc835deb
35
src/app.ts
35
src/app.ts
@ -4,32 +4,45 @@ import log from './logger'
|
|||||||
import { whoami } from './synapse'
|
import { whoami } from './synapse'
|
||||||
log.info('rocketchat2matrix starts.')
|
log.info('rocketchat2matrix starts.')
|
||||||
|
|
||||||
interface RcUser {
|
const enum Entities {
|
||||||
username: string
|
Users = 'users.json',
|
||||||
name: string
|
Rooms = 'rocketchat_room.json',
|
||||||
roles: string[]
|
Messages = 'rocketchat_message.json',
|
||||||
_id: string
|
|
||||||
__rooms: string[]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadRcExport(filename: string) {
|
function loadRcExport(entity: Entities) {
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: fs.createReadStream(`./inputs/${filename}`, {
|
input: fs.createReadStream(`./inputs/${entity}`, {
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
}),
|
}),
|
||||||
crlfDelay: Infinity,
|
crlfDelay: Infinity,
|
||||||
})
|
})
|
||||||
|
|
||||||
rl.on('line', (line) => {
|
rl.on('line', (line) => {
|
||||||
const entity: RcUser = JSON.parse(line)
|
const item = JSON.parse(line)
|
||||||
log.debug(`User: ${entity.name}`)
|
switch (entity) {
|
||||||
|
case Entities.Users:
|
||||||
|
log.debug(`User: ${item.name}`)
|
||||||
|
break
|
||||||
|
|
||||||
|
case Entities.Rooms:
|
||||||
|
log.debug(`Room: ${item.name}`)
|
||||||
|
break
|
||||||
|
|
||||||
|
case Entities.Messages:
|
||||||
|
log.debug(`Message: ${item.name}`)
|
||||||
|
break
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error(`Unhandled Entity: ${entity}`)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
await whoami()
|
await whoami()
|
||||||
await loadRcExport('users.json')
|
await loadRcExport(Entities.Users)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Encountered an error booting up`)
|
log.error(`Encountered an error booting up`)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user