Compare commits

...

2 Commits

Author SHA1 Message Date
ale
d4d34e14ee events Infinity
Some checks reported errors
continuous-integration/drone/push Build was killed
2024-09-26 02:25:51 +02:00
ale
ffce342aa1 some sonar changes 2024-09-26 02:23:49 +02:00
5 changed files with 82 additions and 84 deletions

View File

@ -24,7 +24,7 @@ module.exports = (app, apex, client) => {
&& msg.activity.type) {
const type = msg.activity.type.toLowerCase()
if (type === 'follow' && msg.recipient.type.toLowerCase() === 'person') {
const follow = await apex.acceptFollow(msg.recipient, msg.activity)
// const follow = await apex.acceptFollow(msg.recipient, msg.activity)
const act = await apex.buildActivity('Accept', apex.utils.usernameToIRI(constant.nick), ['https://www.w3.org/ns/activitystreams#Public'].concat([msg.actor.id]), {
actor: msg.recipient,
object: msg.activity
@ -36,35 +36,31 @@ module.exports = (app, apex, client) => {
content = ('' + msg.object.content).replace(/<[^>]*>?/gm, '').split(' ').filter(token => !token.startsWith('@'))
if (msg.recipient.id === apex.utils.usernameToIRI(constant.nick)) {
if (content.length === 1) {
const instance = content.join('').trim(),
ac = new AbortController()
try {
setTimeout(() => {
const instance = content.join('').trim(),
ac = new AbortController(),
timeout = setTimeout(() => {
ac.abort()
}, 5000)
const response = await fetch('https://' + constant.apexdomain + '/api/detail/' + instance, {
}, 5000),
response = await fetch('https://' + constant.apexdomain + '/api/detail/' + instance, {
headers: { 'User-Agent': constant.agent },
agent: new https.Agent({
rejectUnauthorized: false,
keepAlive: false
}),
signal: ac.signal
}),
json = await response.json()
signal: ac.signal,
keepalive: false
})
clearTimeout(timeout)
const json = await response.json()
if (json && json.blocks && Array.isArray(json.blocks) && json.blocks.length > 0) {
const ac2 = new AbortController()
setTimeout(() => {
ac2.abort()
}, 5000)
const result = await fetch('https://' + constant.apexdomain + '/api/list/' + instance, {
const ac = new AbortController(),
timeout = setTimeout(() => {
ac.abort()
}, 5000),
result = await fetch('https://' + constant.apexdomain + '/api/list/' + instance, {
headers: { 'User-Agent': constant.agent },
agent: new https.Agent({
rejectUnauthorized: false,
keepAlive: false
}),
signal: ac2.signal
}),
res = await result.json()
signal: ac.signal,
keepalive: false
})
clearTimeout(timeout)
const res = await result.json()
if (res && res.instances && Array.isArray(res.instances)) {
res.instances.map(async r => {
if (r.domain === instance) {

View File

@ -4,7 +4,7 @@ module.exports = (app, client) => {
const constant = require('./constant'),
zlib = require('zlib'),
clean = str => {
return str.replace(/[\/\\^$+?()`'¡¿¨!"·%&=;,\|\[\]{}]+/gmi, '')
return str.replace(/[/\\^$+?()`'¡¿¨!"·%&=;,\|\[\]{}]+/gmi, '')
}
/**
* @swagger
@ -185,7 +185,7 @@ module.exports = (app, client) => {
}
}
})
const ranking = result.aggregations.blocks.ranking.buckets
const ranking = result.aggregations?.blocks?.ranking?.buckets
res.json(ranking.map(r => ({ domain: r.key, count: r.doc_count })))
})
/**
@ -253,7 +253,7 @@ module.exports = (app, client) => {
}
}
})
const instances = result.hits && result.hits.hits && result.hits.hits.length > 0 ? result.hits.hits : [],
const instances = result.hits?.hits?.length > 0 ? result.hits.hits : [],
suggests = result.suggest.suggests && result.suggest.suggests.length > 0 && result.suggest.suggests[0].options.length > 0 ? result.suggest.suggests[0].options : []
res.json({
instances: instances.map(instance => ({
@ -319,7 +319,7 @@ module.exports = (app, client) => {
}
}
})
const instances = result.hits && result.hits.hits && result.hits.hits.length > 0 ? result.hits.hits : []
const instances = result.hits?.hits?.length > 0 ? result.hits.hits : []
res.json(instances.length > 0 && instances[0]._source.blocks && instances[0]._source.blocks.length > 0 ?
{
blocks: instances[0]._source.blocks.map(instance => ({ domain: instance.domain, comment: instance.comment, severity: instance.severity })),
@ -368,7 +368,7 @@ module.exports = (app, client) => {
}
}
})
const instances = result.hits && result.hits.hits && result.hits.hits.length > 0 ? result.hits.hits : []
const instances = result.hits?.hits?.length > 0 ? result.hits.hits : []
res.json(instances.length > 0 ? instances[0]._source.api : {})
} else {
res.status(404).end()
@ -409,7 +409,7 @@ module.exports = (app, client) => {
}
}
})
const instances = result.hits && result.hits.hits && result.hits.hits.length > 0 ? result.hits.hits : []
const instances = result.hits?.hits?.length > 0 ? result.hits.hits : []
res.json(instances.length > 0 ? instances[0]._source.nodeinfo : {})
} else {
res.status(404).end()
@ -473,7 +473,7 @@ module.exports = (app, client) => {
}
}
})
const instances = result.hits && result.hits.hits && result.hits.hits.length > 0 ? result.hits.hits : [],
const instances = result.hits?.hits?.length > 0 ? result.hits.hits : [],
instancescomment = instances.map(i => ({
instance: i._source.instance, comment: i._source.blocks.find(block => block.domain === clean(req.params.instance)).comment
}))

View File

@ -1,5 +1,4 @@
let servers
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0
module.exports = async (client, apex, app) => {
const util = require('./util')(apex),
constant = require('./constant'),
@ -21,8 +20,8 @@ module.exports = async (client, apex, app) => {
const ac = new AbortController(),
timeout = setTimeout(() => {
ac.abort()
}, constant.abort_timeout)
const response = await fetch(uri, {
}, constant.abort_timeout),
response = await fetch(uri, {
headers: { 'User-Agent': constant.agent },
signal: ac.signal,
keepalive: false,

View File

@ -1,5 +1,6 @@
module.exports = apex => {
const urlToId = url => {
const constant = require("./constant"),
urlToId = url => {
try {
if (typeof new URL(url) === 'object' && url.split('/').length === 5 && url.split('/')[3].length > 0) {
return '@' + url.split('/')[4] + '@' + url.split('/')[2]
@ -16,7 +17,7 @@ const urlToId = url => {
mentions = message.split(' ').filter(token => token.startsWith('@') && token.split('@').length === 3)
.map(token => { return { type: 'Mention', href: `https://${token.split('@')[2]}/users/${token.split('@')[1]}`, name: `@${token.split('@')[1]}` } }),
hashtags = message.split(' ').filter(token => token.startsWith('#'))
.map(token => { return { id: `https://mastodon.social/tags/${token.split('#')[1]}`, name: token } }),
.map(token => { return { id: `https://${constant.apexdomain}/tags/${token.split('#')[1]}`, name: token } }),
images = message.split(' ').filter(token => token.match(/^https?:\/\//i) && token.match(/\.(jpg|png|gif|jpeg|ppm)$/i))
.map(token => { return { type: 'Image', url: token } }),
audio = message.split(' ').filter(token => token.match(/^https?:\/\//i) && token.match(/\.(mp3|wav|flac)$/i))
@ -25,17 +26,17 @@ const urlToId = url => {
.map(token => { return { type: 'Video', url: token } }),
links = message.split(' ').filter(token => token.match(/^https?:\/\//i) && !images.concat(audio).concat(video)
.some(link => link.url === token)).map(token => { return { type: 'Link', href: token } }),
allusers = users.concat([recipient ? recipient : (await apex.store.getObject(apex.utils.usernameToIRI(id), true)).followers[0]]),
allusers = users.concat([recipient || (await apex.store.getObject(apex.utils.usernameToIRI(id), true)).followers[0]]),
act = await apex.buildActivity('Create', apex.utils.usernameToIRI(id), ['https://www.w3.org/ns/activitystreams#Public'].concat(allusers), {
object: {
type: 'Note',
name: `Fediblock Instance`,
summary: summary ? summary : null,
content: `<p>${message.replace(/(\b(https?|ftp|file):\/\/([-A-Z0-9+&@#%?=~_|!:,.;]*)([-A-Z0-9+&@#%?\/=~_|!:,.;]*))/ig,
'<a href="$1" target="_blank">$3</a>').replace(/\s#(\S+)/g, '<a href="https://mastodon.social/tags/$1">#$1</a>').replace(new RegExp('\r?\n', 'g'), '<br />')}</p>`,
summary: summary || null,
content: `<p>${message.replace(/(\b(https?|ftp|file):\/\/([-A-Z0-9+&@#%?=~_|!:,.;]*)([-A-Z0-9+&@#%?/=~_|!:,.;]*))/ig,
'<a href="$1" target="_blank">$3</a>').replace(/\s#(\S+)/g, '<a href="https://mastodon.social/tags/$1">#$1</a>').replace(/\r?\n/g, '<br />')}</p>`,
tag: hashtags.concat(mentions),
attachment: images.concat(links).concat(audio).concat(video),
inReplyTo: reply ? reply : null
inReplyTo: reply || null
}
})
act.object[0].id = act.id

View File

@ -1,3 +1,5 @@
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0
require('events').EventEmitter.defaultMaxListeners = Infinity
const apexinstance = require('./lib/apex'),
apexcustom = require('./lib/apexcustom'),
apiswagger = require('./lib/apiswagger'),