mirror of
https://framagit.org/les/gancio.git
synced 2025-02-01 00:52:01 +01:00
fix fediverse fetch/axios
This commit is contained in:
parent
5b5474e61c
commit
f820c70a25
7 changed files with 35 additions and 33 deletions
|
@ -5,7 +5,14 @@ const config = require('config')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const { Op } = require('sequelize')
|
const { Op } = require('sequelize')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
const { event: Event, resource: Resource, tag: Tag, place: Place, notification: Notification } = require('../models')
|
const {
|
||||||
|
event: Event,
|
||||||
|
resource: Resource,
|
||||||
|
tag: Tag,
|
||||||
|
place: Place,
|
||||||
|
notification: Notification,
|
||||||
|
ap_user: APUser
|
||||||
|
} = require('../models')
|
||||||
const Sequelize = require('sequelize')
|
const Sequelize = require('sequelize')
|
||||||
const exportController = require('./export')
|
const exportController = require('./export')
|
||||||
const sanitizeHtml = require('sanitize-html')
|
const sanitizeHtml = require('sanitize-html')
|
||||||
|
@ -85,12 +92,18 @@ const eventController = {
|
||||||
try {
|
try {
|
||||||
event = await Event.findByPk(id, {
|
event = await Event.findByPk(id, {
|
||||||
attributes: {
|
attributes: {
|
||||||
exclude: ['createdAt', 'updatedAt']
|
exclude: ['createdAt', 'updatedAt', 'placeId']
|
||||||
},
|
},
|
||||||
include: [
|
include: [
|
||||||
{ model: Tag, attributes: ['tag', 'weigth'], through: { attributes: [] } },
|
{ model: Tag, required: false, attributes: ['tag', 'weigth'], through: { attributes: [] } },
|
||||||
{ model: Place, attributes: ['name', 'address'] },
|
{ model: Place, attributes: ['name', 'address'] },
|
||||||
{ model: Resource, where: !is_admin && { hidden: false }, required: false },
|
{
|
||||||
|
model: Resource,
|
||||||
|
where: !is_admin && { hidden: false },
|
||||||
|
include: [{ model: APUser, required: false, attributes: ['object', 'ap_id'] }],
|
||||||
|
required: false,
|
||||||
|
attributes: ['id', 'activitypub_id', 'data', 'hidden']
|
||||||
|
},
|
||||||
{ model: Event, required: false, as: 'parent' }
|
{ model: Event, required: false, as: 'parent' }
|
||||||
],
|
],
|
||||||
order: [[Resource, 'id', 'DESC']]
|
order: [[Resource, 'id', 'DESC']]
|
||||||
|
@ -98,7 +111,6 @@ const eventController = {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return res.sendStatus(400)
|
return res.sendStatus(400)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event && (event.is_visible || is_admin)) {
|
if (event && (event.is_visible || is_admin)) {
|
||||||
event = event.toJSON()
|
event = event.toJSON()
|
||||||
event.tags = event.tags.map(t => t.tag)
|
event.tags = event.tags.map(t => t.tag)
|
||||||
|
|
|
@ -1,15 +1,9 @@
|
||||||
const Sequelize = require('sequelize')
|
|
||||||
const { ap_user: APUser, instance: Instance, resource: Resource } = require('../models')
|
const { ap_user: APUser, instance: Instance, resource: Resource } = require('../models')
|
||||||
|
|
||||||
const instancesController = {
|
const instancesController = {
|
||||||
async getAll (req, res) {
|
async getAll (req, res) {
|
||||||
const instances = await Instance.findAll({
|
const instances = await Instance.findAll()
|
||||||
attributes: {
|
|
||||||
include: [[Sequelize.fn('count', Sequelize.col('domain')), 'users']]
|
|
||||||
},
|
|
||||||
group: ['domain'],
|
|
||||||
include: [{ model: APUser, attributes: [] }]
|
|
||||||
})
|
|
||||||
return res.json(instances)
|
return res.json(instances)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
const moment = require('moment-timezone')
|
const moment = require('moment-timezone')
|
||||||
|
// const debug = require('debug')('event:modals')
|
||||||
|
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
const Event = sequelize.define('event', {
|
const Event = sequelize.define('event', {
|
||||||
|
@ -24,7 +25,6 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
image_path: DataTypes.STRING,
|
image_path: DataTypes.STRING,
|
||||||
is_visible: DataTypes.BOOLEAN,
|
is_visible: DataTypes.BOOLEAN,
|
||||||
recurrent: DataTypes.JSON,
|
recurrent: DataTypes.JSON,
|
||||||
// parent: DataTypes.INTEGER,
|
|
||||||
likes: { type: DataTypes.JSON, defaultValue: [] },
|
likes: { type: DataTypes.JSON, defaultValue: [] },
|
||||||
boost: { type: DataTypes.JSON, defaultValue: [] }
|
boost: { type: DataTypes.JSON, defaultValue: [] }
|
||||||
}, {})
|
}, {})
|
||||||
|
@ -76,8 +76,8 @@ module.exports = (sequelize, DataTypes) => {
|
||||||
})),
|
})),
|
||||||
published: this.createdAt,
|
published: this.createdAt,
|
||||||
attributedTo: `${config.baseurl}/federation/u/${username}`,
|
attributedTo: `${config.baseurl}/federation/u/${username}`,
|
||||||
to: ['https://www.w3.org/ns/activitystreams#Public'],
|
to: follower || [],
|
||||||
cc: follower || [],
|
cc: ['https://www.w3.org/ns/activitystreams#Public', `${config.baseurl}/federation/u/${username}/followers`],
|
||||||
content,
|
content,
|
||||||
summary: null,
|
summary: null,
|
||||||
sensitive: false
|
sensitive: false
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
|
||||||
const Resource = sequelize.define('resource', {
|
const Resource = sequelize.define('resource', {
|
||||||
activitypub_id: {
|
activitypub_id: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const fetch = require('axios')
|
const axios = require('axios')
|
||||||
// const request = require('request')
|
// const request = require('request')
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
|
@ -41,7 +41,7 @@ const Helpers = {
|
||||||
const signature_b64 = signature.toString('base64')
|
const signature_b64 = signature.toString('base64')
|
||||||
const header = `keyId="${config.baseurl}/federation/u/${settingsController.settings.instance_name}",headers="(request-target) host date",signature="${signature_b64}"`
|
const header = `keyId="${config.baseurl}/federation/u/${settingsController.settings.instance_name}",headers="(request-target) host date",signature="${signature_b64}"`
|
||||||
try {
|
try {
|
||||||
const ret = await fetch(inbox, {
|
const ret = await axios(inbox, {
|
||||||
headers: {
|
headers: {
|
||||||
Host: inboxUrl.hostname,
|
Host: inboxUrl.hostname,
|
||||||
Date: d.toUTCString(),
|
Date: d.toUTCString(),
|
||||||
|
@ -49,10 +49,10 @@ const Helpers = {
|
||||||
'Content-Type': 'application/activity+json; charset=utf-8',
|
'Content-Type': 'application/activity+json; charset=utf-8',
|
||||||
Accept: 'application/activity+json, application/json; chartset=utf-8'
|
Accept: 'application/activity+json, application/json; chartset=utf-8'
|
||||||
},
|
},
|
||||||
method: 'POST',
|
method: 'post',
|
||||||
body: JSON.stringify(message)
|
data: JSON.stringify(message)
|
||||||
})
|
})
|
||||||
debug('sign %s => %s', ret.status, await ret.text())
|
debug('sign %s => %s', ret.status, ret.data)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debug('ERROR ', e.toString())
|
debug('ERROR ', e.toString())
|
||||||
}
|
}
|
||||||
|
@ -77,11 +77,9 @@ const Helpers = {
|
||||||
const body = {
|
const body = {
|
||||||
id: `${config.baseurl}/federation/m/${event.id}#create`,
|
id: `${config.baseurl}/federation/m/${event.id}#create`,
|
||||||
type,
|
type,
|
||||||
to: ['https://www.w3.org/ns/activitystreams#Public'],
|
to: recipients[sharedInbox],
|
||||||
cc: [`${config.baseurl}/federation/u/${settingsController.settings.instance_name}/followers`, ...recipients[sharedInbox]],
|
cc: ['https://www.w3.org/ns/activitystreams#Public', `${config.baseurl}/federation/u/${settingsController.settings.instance_name}/followers`],
|
||||||
// cc: recipients[sharedInbox],
|
|
||||||
actor: `${config.baseurl}/federation/u/${settingsController.settings.instance_name}`,
|
actor: `${config.baseurl}/federation/u/${settingsController.settings.instance_name}`,
|
||||||
// object: event.toNoteAP(instanceAdmin.username, [`${config.baseurl}/federation/u/${instanceAdmin.username}/followers`, ...recipients[sharedInbox]])
|
|
||||||
object: event.toNoteAP(settingsController.settings.instance_name, recipients[sharedInbox])
|
object: event.toNoteAP(settingsController.settings.instance_name, recipients[sharedInbox])
|
||||||
}
|
}
|
||||||
body['@context'] = [
|
body['@context'] = [
|
||||||
|
@ -106,13 +104,13 @@ const Helpers = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fedi_user = await fetch(URL, { headers: { Accept: 'application/jrd+json, application/json' } })
|
fedi_user = await axios.get(URL, { headers: { Accept: 'application/jrd+json, application/json' } })
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (!res.ok) {
|
if (res.status !== 200) {
|
||||||
debug('[ERR] Actor %s => %s', URL, res.statusText)
|
debug('[ERR] Actor %s => %s', URL, res.statusText)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return res.json()
|
return res.data
|
||||||
})
|
})
|
||||||
|
|
||||||
if (fedi_user) {
|
if (fedi_user) {
|
||||||
|
@ -132,8 +130,8 @@ const Helpers = {
|
||||||
if (instance) { return instance }
|
if (instance) { return instance }
|
||||||
}
|
}
|
||||||
|
|
||||||
instance = await fetch(`${instance_url}/api/v1/instance`, { headers: { Accept: 'application/json' } })
|
instance = await axios.$get(`${instance_url}/api/v1/instance`, { headers: { Accept: 'application/json' } })
|
||||||
.then(res => res.json())
|
// .then(res => { console.error(res.data); return res.data })
|
||||||
.then(instance => {
|
.then(instance => {
|
||||||
const data = {
|
const data = {
|
||||||
stats: instance.stats,
|
stats: instance.stats,
|
||||||
|
|
|
@ -21,7 +21,7 @@ const app = express()
|
||||||
app.use(spamFilter)
|
app.use(spamFilter)
|
||||||
|
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
debug(req.path)
|
debug(req.method, req.path)
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ class Task {
|
||||||
}
|
}
|
||||||
|
|
||||||
process () {
|
process () {
|
||||||
debug('PROCESS ', this.name)
|
|
||||||
this.processInNTick--
|
this.processInNTick--
|
||||||
if (this.processInNTick > 0) {
|
if (this.processInNTick > 0) {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue