This commit is contained in:
parent
e13c5f6744
commit
d388fd4cd4
@ -1,4 +1,5 @@
|
||||
let servers
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0
|
||||
module.exports = async (client, apex, app) => {
|
||||
const util = require('./util')(apex),
|
||||
constant = require('./constant'),
|
||||
@ -18,9 +19,7 @@ module.exports = async (client, apex, app) => {
|
||||
}
|
||||
},
|
||||
requestPart = async uri => {
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0
|
||||
const ac = new AbortController()
|
||||
try {
|
||||
setTimeout(() => {
|
||||
ac.abort()
|
||||
}, 5000)
|
||||
@ -36,14 +35,9 @@ module.exports = async (client, apex, app) => {
|
||||
json = await response.json()
|
||||
// setImmediate(() => { ac.abort() })
|
||||
return json
|
||||
} catch (e) {
|
||||
// setImmediate(() => { ac.abort() })
|
||||
// console.error(e)
|
||||
throw e
|
||||
}
|
||||
s
|
||||
},
|
||||
scanInstance = async instance => {
|
||||
try {
|
||||
const json = await requestPart(`https://${instance}/api/v1/instance/domain_blocks`)
|
||||
if (Array.isArray(json) && json.length > 0) {
|
||||
const result = await client.search({
|
||||
@ -68,7 +62,6 @@ module.exports = async (client, apex, app) => {
|
||||
requestPart(`https://${instance}/api/v1/instance/peers`)
|
||||
])
|
||||
if (instancelocated.length === 0) {
|
||||
try {
|
||||
await client.index({
|
||||
index: constant.index,
|
||||
body: {
|
||||
@ -80,10 +73,6 @@ module.exports = async (client, apex, app) => {
|
||||
last: new Date()
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return
|
||||
}
|
||||
app.locals.created++
|
||||
return await util.sendFederatedMessage(constant.nick, 'New Fediblock Instance', `Fediblock Instance ${instance} with ${json.length} blocks - https://${constant.apexdomain}#${instance}`, getAccount(api))
|
||||
} else {
|
||||
@ -94,7 +83,6 @@ module.exports = async (client, apex, app) => {
|
||||
|| !instancelocated[0]._source.api
|
||||
|| !instancelocated[0]._source.nodeinfo
|
||||
|| !instancelocated[0]._source.peers) {
|
||||
try {
|
||||
await client.update({
|
||||
index: constant.index,
|
||||
id: instancelocated[0]._id,
|
||||
@ -107,33 +95,16 @@ module.exports = async (client, apex, app) => {
|
||||
},
|
||||
doc_as_upsert: true
|
||||
})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return
|
||||
}
|
||||
app.locals.updated++
|
||||
if (instancelocated[0]._source.api && instancelocated[0]._source.api.uri && instancelocated[0]._source.api.contact_account && instancelocated[0]._source.api.contact_account.acct) {
|
||||
const difference = blocks.filter(block => block.domain && block.domain.trim().length > 0 && !elasticinstance.some(instance => block.domain === instance.domain))
|
||||
if (difference.length > 0 && difference.length < 50) {
|
||||
return await util.sendFederatedMessage(constant.nick, 'Detected #Fediblock by Fediblock Instance', `You blocked new instances: ${difference.map(d => d.domain).join(', ')} - https://${constant.apexdomain}#${instance}`, getAccount(instancelocated[0]._source.api))
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scanPart = async function* (instancesall, index) {
|
||||
@ -154,7 +125,6 @@ module.exports = async (client, apex, app) => {
|
||||
}
|
||||
},
|
||||
scanIndex = async (server, instancesall) => {
|
||||
try {
|
||||
const [api, nodeinfo, blocks] = await Promise.all([
|
||||
requestPart(`https://${server}/api/v1/instance`),
|
||||
requestPart(`https://${server}/nodeinfo/2.0`),
|
||||
@ -201,19 +171,9 @@ module.exports = async (client, apex, app) => {
|
||||
doc_as_upsert: true
|
||||
})
|
||||
app.locals.updated++
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return
|
||||
}
|
||||
},
|
||||
scanReturn = async () => {
|
||||
@ -242,7 +202,7 @@ module.exports = async (client, apex, app) => {
|
||||
if (!servers || servers.length === 0) {
|
||||
servers = instancesall.sort(() => Math.random() - 0.5)
|
||||
}
|
||||
if (server && server === constant.initialscan) {
|
||||
if (server === constant.initialscan) {
|
||||
return await scan(servers.shift())
|
||||
}
|
||||
app.locals.scannum = instancessorted.length
|
||||
@ -263,7 +223,7 @@ module.exports = async (client, apex, app) => {
|
||||
return await scanReturn()
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
// console.error(e)
|
||||
return await scanReturn()
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user