refactor server
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
ale 2024-11-10 02:36:04 +01:00
parent 6c56252145
commit 5deb70a0b0
2 changed files with 47 additions and 41 deletions

View File

@ -238,5 +238,5 @@ module.exports = async (client, apex, app) => {
job = schedule.scheduleJob('0 ' + constant.schedule + ' * * *', async () => {
await util.sendFederatedMessage(constant.nick, null, 'Scanning ' + app.locals.server + ' instance with ' + app.locals.scantotal + ' peers\nScanned ' + app.locals.peers + ' peers from ' + app.locals.instances + ' instances, ' + app.locals.created + ' created, ' + app.locals.updated + ' updated\nhttps://' + constant.apexdomain)
})
await scanReturn()
return await scanReturn()
}

View File

@ -54,7 +54,48 @@ const apexinstance = require('./lib/apex'),
},
itemsPerPage: 200
}),
server = http.createServer(app).listen(4000, () => {
register = async () => {
const admin = await apex.store.getObject(apex.utils.usernameToIRI('admin'), true)
if (!admin) {
const adminaccount = await apex.createActor('admin', 'Fediblock Admin', 'Fediblock Admin - https://' + constant.apexdomain,
{ type: 'Image', mediaType: 'image/png', url: constant.icon }, 'Service'),
keys = generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
})
adminaccount.publicKey[0].publicKeyPem[0] = keys.publicKey
adminaccount._meta.privateKey = keys.privateKey
await apex.store.saveObject(adminaccount)
const bot = await apex.createActor(constant.nick, 'Fediblock Bot', 'Fediblock #Bot - https://' + constant.apexdomain,
{ type: 'Image', mediaType: 'image/png', url: constant.icon }, 'Person'),
keysbot = generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
})
bot.publicKey[0].publicKeyPem[0] = keysbot.publicKey
bot._meta.privateKey = keysbot.privateKey
await apex.store.saveObject(bot)
apex.systemUser = adminaccount
apex.store.setup(adminaccount)
} else {
apex.systemUser = admin
}
},
connect = () => {
mongoclient.connect()
.then(async () => {
const exists = await client.indices.exists({ index: constant.index })
@ -69,45 +110,7 @@ const apexinstance = require('./lib/apex'),
})
.then(async () => {
try {
const admin = await apex.store.getObject(apex.utils.usernameToIRI('admin'), true)
if (!admin) {
const adminaccount = await apex.createActor('admin', 'Fediblock Admin', 'Fediblock Admin - https://' + constant.apexdomain,
{ type: 'Image', mediaType: 'image/png', url: constant.icon }, 'Service'),
keys = generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
})
adminaccount.publicKey[0].publicKeyPem[0] = keys.publicKey
adminaccount._meta.privateKey = keys.privateKey
await apex.store.saveObject(adminaccount)
const bot = await apex.createActor(constant.nick, 'Fediblock Bot', 'Fediblock #Bot - https://' + constant.apexdomain,
{ type: 'Image', mediaType: 'image/png', url: constant.icon }, 'Person'),
keysbot = generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
})
bot.publicKey[0].publicKeyPem[0] = keysbot.publicKey
bot._meta.privateKey = keysbot.privateKey
await apex.store.saveObject(bot)
apex.systemUser = adminaccount
apex.store.setup(adminaccount)
} else {
apex.systemUser = admin
}
await register()
taskdeletedup(client)
await apex.startDelivery()
console.log('Server listening on ' + server.address().address + ':' + server.address().port)
@ -116,6 +119,9 @@ const apexinstance = require('./lib/apex'),
console.error(e)
}
})
},
server = http.createServer(app).listen(4000, () => {
connect()
})
app.locals.scan = new events.EventEmitter()