mirror of
https://framagit.org/les/gancio.git
synced 2025-02-01 00:52:01 +01:00
AP event
This commit is contained in:
parent
bef2560215
commit
7cf49fb320
4 changed files with 26 additions and 18 deletions
|
@ -38,7 +38,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||
Event.belongsTo(models.event, { as: 'parent' })
|
||||
}
|
||||
|
||||
Event.prototype.toNoteAP = function (username, locale, follower = []) {
|
||||
Event.prototype.toAP = function (username, locale, follower = []) {
|
||||
const tags = this.tags && this.tags.map(t => t.tag.replace(/[ #]/g, '_'))
|
||||
const tag_links = tags.map(t => {
|
||||
return `<a href='/tags/${t}' class='mention hashtag status-link' rel='tag'><span>#${t}</span></a>`
|
||||
|
@ -50,23 +50,22 @@ module.exports = (sequelize, DataTypes) => {
|
|||
${this.description.length > 500 ? this.description.substr(0, 500) + '...' : this.description}<br/>
|
||||
${tag_links} <br/>`
|
||||
|
||||
// const attachment = []
|
||||
// if (this.image_path) {
|
||||
// attachment.push({
|
||||
// type: 'Document',
|
||||
// mediaType: 'image/jpeg',
|
||||
// url: `${config.baseurl}/media/${this.image_path}`,
|
||||
// name: null,
|
||||
// blurHash: null
|
||||
// })
|
||||
// }
|
||||
const attachment = []
|
||||
if (this.image_path) {
|
||||
attachment.push({
|
||||
type: 'Document',
|
||||
mediaType: 'image/jpeg',
|
||||
url: `${config.baseurl}/media/${this.image_path}`,
|
||||
name: null,
|
||||
blurHash: null
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
id: `${config.baseurl}/federation/m/${this.id}`,
|
||||
url: `${config.baseurl}/federation/m/${this.id}`,
|
||||
type: 'Note',
|
||||
// do not send attachment, in mastodon a link preview is shown instead
|
||||
// attachment,
|
||||
type: 'Event',
|
||||
attachment,
|
||||
tag: tags.map(tag => ({
|
||||
type: 'Hashtag',
|
||||
name: '#' + tag,
|
||||
|
|
|
@ -80,7 +80,7 @@ const Helpers = {
|
|||
to: recipients[sharedInbox],
|
||||
cc: ['https://www.w3.org/ns/activitystreams#Public', `${config.baseurl}/federation/u/${settingsController.settings.instance_name}/followers`],
|
||||
actor: `${config.baseurl}/federation/u/${settingsController.settings.instance_name}`,
|
||||
object: event.toNoteAP(settingsController.settings.instance_name,
|
||||
object: event.toAP(settingsController.settings.instance_name,
|
||||
settingsController.settings.instance_locale,
|
||||
recipients[sharedInbox])
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ router.get('/m/:event_id', async (req, res) => {
|
|||
|
||||
const event = await Event.findByPk(req.params.event_id, { include: [User, Tag, Place] })
|
||||
if (!event) { return res.status(404).send('Not found') }
|
||||
return res.json(event.toNoteAP(event.user.username, req.settings.locale))
|
||||
return res.json(event.toAP(event.user.username, req.settings.locale))
|
||||
})
|
||||
|
||||
// get any message coming from federation
|
||||
|
@ -72,6 +72,8 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
|
|||
if (b.object.type === 'Note') {
|
||||
debug('Create a resource!')
|
||||
await Resources.create(req, res)
|
||||
} else if (b.object.type === 'Event') {
|
||||
debug('Event type is coming!!')
|
||||
} else {
|
||||
// await Resources.create(req, res)
|
||||
debug('Create with unsupported Object or not a reply => %s ', b.object.type)
|
||||
|
@ -80,9 +82,16 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
|
|||
}
|
||||
})
|
||||
|
||||
function redirect_on_html_accepted (req, res, next) {
|
||||
if (req.accepts('html')) {
|
||||
return res.redirect(settingsController.settings.baseurl)
|
||||
}
|
||||
return next()
|
||||
}
|
||||
|
||||
router.get('/u/:name/outbox', Users.outbox)
|
||||
router.get('/u/:name/followers', Users.followers)
|
||||
router.get('/u/:name', Users.get)
|
||||
router.get('/u/:name', redirect_on_html_accepted, Users.get)
|
||||
|
||||
// Handle 404
|
||||
router.use((req, res) => {
|
||||
|
|
|
@ -115,7 +115,7 @@ module.exports = {
|
|||
type: 'OrderedCollectionPage',
|
||||
totalItems: events.length,
|
||||
partOf: `${config.baseurl}/federation/u/${name}/outbox`,
|
||||
orderedItems: events.map(e => ({ ...e.toNoteAP(name, req.settings.locale), actor: `${config.baseurl}/federation/u/${name}` }))
|
||||
orderedItems: events.map(e => ({ ...e.toAP(name, req.settings.locale), actor: `${config.baseurl}/federation/u/${name}` }))
|
||||
// user.events.map(e => ({
|
||||
// id: `${config.baseurl}/federation/m/${e.id}#create`,
|
||||
// type: 'Create',
|
||||
|
|
Loading…
Reference in a new issue