Read rc entities from filesystem

This commit is contained in:
Henrik Hüttemann
2023-05-20 10:05:56 +02:00
parent cf3e26de8d
commit b138df0dac
4 changed files with 511 additions and 16 deletions
+45 -2
View File
@@ -1,10 +1,53 @@
import { access_token } from './config/synapse_access_token.json'
// import rcUsers from '../inputs/users.json'
import fs from 'node:fs'
import readline from 'node:readline'
import axios from 'axios'
import winston from 'winston'
const log = (module.exports = winston.createLogger({
level: 'debug',
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.colorize({ all: true }),
winston.format.simple()
),
}))
log.info('rocketchat2matrix starts.')
axios.defaults.baseURL = 'http://localhost:8008'
axios.defaults.headers.common['Authorization'] = ` Bearer ${access_token}`
axios.defaults.headers.post['Content-Type'] = 'application/json'
const whoami = axios.get('/_matrix/client/v3/account/whoami')
interface RcUser {
username: string
name: string
roles: string[]
_id: string
__rooms: string[]
}
whoami.then((response) => console.log(response.data))
function loadRcExport(filename: string) {
const rl = readline.createInterface({
input: fs.createReadStream(`./inputs/${filename}`, {
encoding: 'utf-8',
}),
crlfDelay: Infinity,
})
rl.on('line', (line) => {
const entity: RcUser = JSON.parse(line)
log.debug(`User: ${entity.name}`)
})
}
async function main() {
const whoami = axios.get('/_matrix/client/v3/account/whoami')
whoami
.then((response) => log.info('Logged into synapse as', response.data))
.catch((reason) => log.error(`Login to synapse failed: ${reason}`))
loadRcExport('users.json')
}
main()