AP event
This commit is contained in:
@@ -38,7 +38,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
Event.belongsTo(models.event, { as: 'parent' })
|
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 tags = this.tags && this.tags.map(t => t.tag.replace(/[ #]/g, '_'))
|
||||||
const tag_links = tags.map(t => {
|
const tag_links = tags.map(t => {
|
||||||
return `<a href='/tags/${t}' class='mention hashtag status-link' rel='tag'><span>#${t}</span></a>`
|
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/>
|
${this.description.length > 500 ? this.description.substr(0, 500) + '...' : this.description}<br/>
|
||||||
${tag_links} <br/>`
|
${tag_links} <br/>`
|
||||||
|
|
||||||
// const attachment = []
|
const attachment = []
|
||||||
// if (this.image_path) {
|
if (this.image_path) {
|
||||||
// attachment.push({
|
attachment.push({
|
||||||
// type: 'Document',
|
type: 'Document',
|
||||||
// mediaType: 'image/jpeg',
|
mediaType: 'image/jpeg',
|
||||||
// url: `${config.baseurl}/media/${this.image_path}`,
|
url: `${config.baseurl}/media/${this.image_path}`,
|
||||||
// name: null,
|
name: null,
|
||||||
// blurHash: null
|
blurHash: null
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: `${config.baseurl}/federation/m/${this.id}`,
|
id: `${config.baseurl}/federation/m/${this.id}`,
|
||||||
url: `${config.baseurl}/federation/m/${this.id}`,
|
url: `${config.baseurl}/federation/m/${this.id}`,
|
||||||
type: 'Note',
|
type: 'Event',
|
||||||
// do not send attachment, in mastodon a link preview is shown instead
|
attachment,
|
||||||
// attachment,
|
|
||||||
tag: tags.map(tag => ({
|
tag: tags.map(tag => ({
|
||||||
type: 'Hashtag',
|
type: 'Hashtag',
|
||||||
name: '#' + tag,
|
name: '#' + tag,
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ const Helpers = {
|
|||||||
to: recipients[sharedInbox],
|
to: recipients[sharedInbox],
|
||||||
cc: ['https://www.w3.org/ns/activitystreams#Public', `${config.baseurl}/federation/u/${settingsController.settings.instance_name}/followers`],
|
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}`,
|
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,
|
settingsController.settings.instance_locale,
|
||||||
recipients[sharedInbox])
|
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] })
|
const event = await Event.findByPk(req.params.event_id, { include: [User, Tag, Place] })
|
||||||
if (!event) { return res.status(404).send('Not found') }
|
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
|
// 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') {
|
if (b.object.type === 'Note') {
|
||||||
debug('Create a resource!')
|
debug('Create a resource!')
|
||||||
await Resources.create(req, res)
|
await Resources.create(req, res)
|
||||||
|
} else if (b.object.type === 'Event') {
|
||||||
|
debug('Event type is coming!!')
|
||||||
} else {
|
} else {
|
||||||
// await Resources.create(req, res)
|
// await Resources.create(req, res)
|
||||||
debug('Create with unsupported Object or not a reply => %s ', b.object.type)
|
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/outbox', Users.outbox)
|
||||||
router.get('/u/:name/followers', Users.followers)
|
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
|
// Handle 404
|
||||||
router.use((req, res) => {
|
router.use((req, res) => {
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ module.exports = {
|
|||||||
type: 'OrderedCollectionPage',
|
type: 'OrderedCollectionPage',
|
||||||
totalItems: events.length,
|
totalItems: events.length,
|
||||||
partOf: `${config.baseurl}/federation/u/${name}/outbox`,
|
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 => ({
|
// user.events.map(e => ({
|
||||||
// id: `${config.baseurl}/federation/m/${e.id}#create`,
|
// id: `${config.baseurl}/federation/m/${e.id}#create`,
|
||||||
// type: 'Create',
|
// type: 'Create',
|
||||||
|
|||||||
Reference in New Issue
Block a user