[lint] linting
This commit is contained in:
@@ -2,8 +2,8 @@ const crypto = require('crypto')
|
||||
const moment = require('moment-timezone')
|
||||
const { Op } = require('sequelize')
|
||||
const lodash = require('lodash')
|
||||
const { event: Event, comment: Comment, tag: Tag, place: Place,
|
||||
user: User, notification: Notification, event_notification: EventNotification } = require('../models')
|
||||
const { event: Event, comment: Comment, tag: Tag, place: Place,
|
||||
user: User, notification: Notification } = require('../models')
|
||||
const Sequelize = require('sequelize')
|
||||
const exportController = require('./export')
|
||||
const debug = require('debug')('controller:event')
|
||||
@@ -142,7 +142,7 @@ const eventController = {
|
||||
async unconfirm (req, res) {
|
||||
const id = Number(req.params.event_id)
|
||||
const event = await Event.findByPk(id)
|
||||
if (!event) { return sendStatus(404) }
|
||||
if (!event) { return req.sendStatus(404) }
|
||||
|
||||
try {
|
||||
event.is_visible = false
|
||||
@@ -219,7 +219,7 @@ const eventController = {
|
||||
{ start_datetime: { [Op.between]: [start.unix(), end.unix()] } }
|
||||
]
|
||||
},
|
||||
attributes: { exclude: ['createdAt', 'updatedAt', 'placeId' ] },
|
||||
attributes: { exclude: [ 'createdAt', 'updatedAt', 'placeId' ] },
|
||||
order: [[Tag, 'weigth', 'DESC']],
|
||||
include: [
|
||||
{ model: Comment, required: false, attributes: ['id'] },
|
||||
|
||||
@@ -65,7 +65,7 @@ const exportController = {
|
||||
url: `${req.settings.baseurl}/event/${e.id}`,
|
||||
alarms: [{
|
||||
action: 'display',
|
||||
trigger: {hours: 1, before: true}
|
||||
trigger: { hours: 1, before: true }
|
||||
}]
|
||||
}
|
||||
})
|
||||
|
||||
@@ -200,7 +200,7 @@ const userController = {
|
||||
},
|
||||
|
||||
async current (req, res) {
|
||||
if (!req.user) return res.status(400).send('Not logged')
|
||||
if (!req.user) { return res.status(400).send('Not logged') }
|
||||
const user = await User.findByPk(req.user.id, { include: { model: FedUsers, as: 'followers' } })
|
||||
res.json(user)
|
||||
},
|
||||
@@ -214,7 +214,7 @@ const userController = {
|
||||
|
||||
async update (req, res) {
|
||||
// user to modify
|
||||
user = await User.findByPk(req.body.id)
|
||||
const user = await User.findByPk(req.body.id)
|
||||
|
||||
if (!user) { return res.status(404).json({ success: false, message: 'User not found!' }) }
|
||||
|
||||
|
||||
@@ -21,16 +21,16 @@ api.use(cookieParser())
|
||||
api.use(bodyParser.urlencoded({ extended: false }))
|
||||
api.use(bodyParser.json())
|
||||
|
||||
const jwt = expressJwt({
|
||||
secret: config.secret,
|
||||
credentialsRequired: false,
|
||||
})
|
||||
// const jwt = expressJwt({
|
||||
// secret: config.secret,
|
||||
// credentialsRequired: false
|
||||
// })
|
||||
|
||||
// api.use(jwt)
|
||||
|
||||
// AUTH
|
||||
api.post('/auth/login', userController.login)
|
||||
api.get('/auth/user', fillUser, userController.current)
|
||||
api.get('/auth/user', fillUser, userController.current)
|
||||
|
||||
api.post('/user/recover', userController.forgotPassword)
|
||||
api.post('/user/check_recover_code', userController.checkRecoverCode)
|
||||
@@ -38,7 +38,7 @@ api.post('/user/recover_password', userController.updatePasswordWithRecoverCode)
|
||||
|
||||
// register and add users
|
||||
api.post('/user/register', userController.register)
|
||||
api.post('/user', isAuth, isAdmin, userController.create)
|
||||
api.post('/user', isAuth, isAdmin, userController.create)
|
||||
|
||||
// update user
|
||||
api.put('/user', isAuth, userController.update)
|
||||
@@ -95,7 +95,6 @@ api.get('/export/:type', exportController.export)
|
||||
// get events in this range
|
||||
api.get('/event/:month/:year', eventController.getAll)
|
||||
|
||||
|
||||
// Handle 404
|
||||
api.use((req, res) => {
|
||||
debug('404 Page not found: %s', req.path)
|
||||
|
||||
@@ -76,7 +76,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||
cc: follower || [],
|
||||
content,
|
||||
summary: null,
|
||||
sensitive: false,
|
||||
sensitive: false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,5 +10,5 @@ module.exports = (sequelize, DataTypes) => {
|
||||
}
|
||||
}, {})
|
||||
|
||||
return event_notification
|
||||
return event_notification
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@ module.exports = (sequelize, DataTypes) => {
|
||||
},
|
||||
object: DataTypes.JSON
|
||||
}, {})
|
||||
fed_users.associate = function(models) {
|
||||
fed_users.associate = function (models) {
|
||||
fed_users.belongsTo(models.instances)
|
||||
// associations can be defined here
|
||||
};
|
||||
}
|
||||
return fed_users
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ let sequelize = null
|
||||
|
||||
try {
|
||||
sequelize = new Sequelize(config.db)
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
consola.warn(` ⚠️ Cannot connect to db, check your configuration => ${e}`)
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
15
server/api/models/instances.js
Normal file
15
server/api/models/instances.js
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict'
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const instances = sequelize.define('instances', {
|
||||
domain: DataTypes.STRING,
|
||||
name: DataTypes.STRING,
|
||||
blocked: DataTypes.BOOLEAN,
|
||||
data: DataTypes.JSON
|
||||
}, {})
|
||||
|
||||
instances.associate = function (models) {
|
||||
instances.hasMany(models.fed_users)
|
||||
}
|
||||
|
||||
return instances
|
||||
}
|
||||
@@ -7,7 +7,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||
index: true,
|
||||
primaryKey: true
|
||||
},
|
||||
weigth: { type: DataTypes.INTEGER, defaultValue: 0, allowNull: false },
|
||||
weigth: { type: DataTypes.INTEGER, defaultValue: 0, allowNull: false }
|
||||
}, {})
|
||||
|
||||
tag.associate = function (models) {
|
||||
|
||||
@@ -27,7 +27,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||
recover_code: DataTypes.STRING,
|
||||
is_admin: DataTypes.BOOLEAN,
|
||||
is_active: DataTypes.BOOLEAN,
|
||||
rsa: DataTypes.JSON,
|
||||
rsa: DataTypes.JSON
|
||||
}, {
|
||||
scopes: {
|
||||
withoutPassword: {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const { event: Event, comment: Comment } = require('../api/models')
|
||||
const config = require('config')
|
||||
const debug = require('debug')('fediverse:comment')
|
||||
|
||||
module.exports = {
|
||||
@@ -7,7 +6,7 @@ module.exports = {
|
||||
const body = req.body
|
||||
// search for related event
|
||||
const inReplyTo = body.object.inReplyTo
|
||||
const match = inReplyTo.match('.*\/federation\/m\/(.*)')
|
||||
const match = inReplyTo.match('.*/federation/m/(.*)')
|
||||
if (!match || match.length < 2) {
|
||||
debug('Comment not found %s', inReplyTo)
|
||||
return res.status(404).send('Event not found!')
|
||||
|
||||
@@ -14,12 +14,12 @@ module.exports = {
|
||||
},
|
||||
|
||||
async unboost (req, res) {
|
||||
const match = req.body.object.match*`${config.baseurl}/federation/m/(.*)`)
|
||||
if (!match || match.length < 2) return res.status(404).send('Event not found!')
|
||||
const match = req.body.object.match(`${config.baseurl}/federation/m/(.*)`)
|
||||
if (!match || match.length < 2) { return res.status(404).send('Event not found!') }
|
||||
debug('unboost %s', match[1])
|
||||
const event = await Event.findByPk(Number(match[1]))
|
||||
if (!event) return res.status(404).send('Event not found!')
|
||||
await event.update({ boost: [...event.boost.filter(actor => actor !== body.actor )]})
|
||||
if (!event) { return res.status(404).send('Event not found!') }
|
||||
await event.update({ boost: event.boost.filter(actor => actor !== req.body.actor) })
|
||||
},
|
||||
|
||||
async bookmark (req, res) {
|
||||
@@ -40,7 +40,7 @@ module.exports = {
|
||||
const event = await Event.findByPk(Number(match[1]))
|
||||
debug('%s unbookmark %s (%d)', body.actor, event.title, event.likes.length)
|
||||
if (!event) { return res.status(404).send('Event not found!') }
|
||||
await event.update({ likes: [...event.likes.filter(actor => actor !== body.actor)] })
|
||||
await event.update({ likes: event.likes.filter(actor => actor !== body.actor) })
|
||||
res.sendStatus(201)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ module.exports = {
|
||||
const body = req.body
|
||||
if (typeof body.object !== 'string') { return }
|
||||
const username = body.object.replace(`${config.baseurl}/federation/u/`, '')
|
||||
const user = await User.findOne({ where: { username }, include: { model: FedUsers, as: 'followers' }})
|
||||
const user = await User.findOne({ where: { username }, include: { model: FedUsers, as: 'followers' } })
|
||||
if (!user) { return res.status(404).send('User not found') }
|
||||
|
||||
// check for duplicate
|
||||
if (!user.followers.includes(body.actor)) {
|
||||
await user.addFollowers([req.fedi_user.id])
|
||||
// await user.update({ followers: [...user.followers, body.actor] })
|
||||
debug('%s followed by %s (%d)', username, body.actor, user.followers.length+1)
|
||||
debug('%s followed by %s (%d)', username, body.actor, user.followers.length + 1)
|
||||
} else {
|
||||
debug('duplicate %s followed by %s', username, body.actor)
|
||||
}
|
||||
@@ -37,7 +37,7 @@ module.exports = {
|
||||
async unfollow (req, res) {
|
||||
const body = req.body
|
||||
const username = body.object.object.replace(`${config.baseurl}/federation/u/`, '')
|
||||
const user = await User.findOne({ where: { username }, include: { model: FedUsers, as: 'followers'} })
|
||||
const user = await User.findOne({ where: { username }, include: { model: FedUsers, as: 'followers' } })
|
||||
if (!user) { return res.status(404).send('User not found') }
|
||||
|
||||
if (body.actor !== body.object.actor || body.actor !== req.fedi_user.id) {
|
||||
@@ -45,7 +45,7 @@ module.exports = {
|
||||
return res.status(400).send('Bad things')
|
||||
}
|
||||
|
||||
if (req.fedi_user) await user.removeFollowers(req.fedi_user.id)
|
||||
if (req.fedi_user) { await user.removeFollowers(req.fedi_user.id) }
|
||||
debug('%s unfollowed by %s', username, body.actor)
|
||||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
@@ -11,16 +11,16 @@ const settingsController = require('../api/controller/settings')
|
||||
const Helpers = {
|
||||
|
||||
// ignore unimplemented ping url from fediverse
|
||||
async spamFilter (req, res, next) {
|
||||
spamFilter (req, res, next) {
|
||||
const urlToIgnore = [
|
||||
'/api/v1/instance',
|
||||
'/api/meta',
|
||||
'/api/statusnet/version.json',
|
||||
'/api/gnusocial/version.json',
|
||||
'/api/statusnet/config.json',
|
||||
'/poco',
|
||||
'/poco'
|
||||
]
|
||||
if (urlToIgnore.includes(req.path)) return res.status(404).send('Not Found')
|
||||
if (urlToIgnore.includes(req.path)) { return res.status(404).send('Not Found') }
|
||||
next()
|
||||
},
|
||||
|
||||
@@ -52,7 +52,7 @@ const Helpers = {
|
||||
debug('sign %s => %s', ret.status, await ret.text())
|
||||
},
|
||||
|
||||
async sendEvent (event, user, type='Create') {
|
||||
async sendEvent (event, user, type = 'Create') {
|
||||
if (!settingsController.settings.enable_federation) {
|
||||
debug('event not send, federation disabled')
|
||||
return
|
||||
@@ -60,7 +60,7 @@ const Helpers = {
|
||||
|
||||
// event is sent by user that published it and by the admin instance
|
||||
// collect followers from admin and user
|
||||
const instanceAdmin = await User.findOne({ where: { email: config.admin_email }, include: { model: FedUsers, as: 'followers' } })
|
||||
const instanceAdmin = await User.findOne({ where: { email: config.admin_email }, include: { model: FedUsers, as: 'followers' } })
|
||||
if (!instanceAdmin || !instanceAdmin.username) {
|
||||
debug('Instance admin not found (there is no user with email => %s)', config.admin_email)
|
||||
return
|
||||
@@ -69,18 +69,18 @@ const Helpers = {
|
||||
let recipients = {}
|
||||
instanceAdmin.followers.forEach(follower => {
|
||||
const sharedInbox = follower.object.endpoints.sharedInbox
|
||||
if (!recipients[sharedInbox]) recipients[sharedInbox] = []
|
||||
if (!recipients[sharedInbox]) { recipients[sharedInbox] = [] }
|
||||
recipients[sharedInbox].push(follower.ap_id)
|
||||
})
|
||||
|
||||
for(const sharedInbox in recipients) {
|
||||
for (const sharedInbox in recipients) {
|
||||
debug('Notify %s with event %s (from admin %s) cc => %d', sharedInbox, event.title, instanceAdmin.username, recipients[sharedInbox].length)
|
||||
const body = {
|
||||
id: `${config.baseurl}/federation/m/${event.id}#create`,
|
||||
type,
|
||||
to: ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
cc: [`${config.baseurl}/federation/u/${instanceAdmin.username}/followers`, ...recipients[sharedInbox]],
|
||||
//cc: recipients[sharedInbox],
|
||||
// cc: recipients[sharedInbox],
|
||||
actor: `${config.baseurl}/federation/u/${instanceAdmin.username}`,
|
||||
// object: event.toAP(instanceAdmin.username, [`${config.baseurl}/federation/u/${instanceAdmin.username}/followers`, ...recipients[sharedInbox]])
|
||||
object: event.toAP(instanceAdmin.username, recipients[sharedInbox])
|
||||
|
||||
@@ -16,8 +16,10 @@ const debug = require('debug')('federation')
|
||||
*/
|
||||
|
||||
router.use(cors())
|
||||
|
||||
// is federation enabled? middleware
|
||||
router.use((req, res, next) => {
|
||||
if(settingsController.settings.enable_federation) return next()
|
||||
if (settingsController.settings.enable_federation) { return next() }
|
||||
debug('Federation disabled!')
|
||||
res.status(401).send('Federation disabled')
|
||||
next(false)
|
||||
@@ -27,7 +29,7 @@ router.use(express.json({ type: ['application/json', 'application/activity+json'
|
||||
|
||||
router.get('/m/:event_id', async (req, res) => {
|
||||
const event_id = req.params.event_id
|
||||
if (req.accepts('html')) return res.redirect(301, `/event/${event_id}`)
|
||||
if (req.accepts('html')) { return res.redirect(301, `/event/${event_id}`) }
|
||||
|
||||
const event = await Event.findByPk(req.params.event_id, { include: [ User, Tag, Place ] })
|
||||
if (!event) { return res.status(404).send('Not found') }
|
||||
@@ -57,7 +59,7 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
|
||||
Ego.boost(req, res)
|
||||
break
|
||||
case 'Note':
|
||||
console.error('This is a note ! I probably should not receive this')
|
||||
debug('This is a note! I probably should create a comment here')
|
||||
break
|
||||
case 'Like':
|
||||
Ego.bookmark(req, res)
|
||||
@@ -70,7 +72,7 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
|
||||
if (b.object.type === 'Note' && b.object.inReplyTo) {
|
||||
await Comments.create(req, res)
|
||||
} else {
|
||||
console.error('Create what? ', b.object.type)
|
||||
debug('Create with unsupported Object or not a reply => %s ', b.object.type)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ const debug = require('debug')('fediverse:user')
|
||||
module.exports = {
|
||||
async get (req, res) {
|
||||
const name = req.params.name
|
||||
if (!name) return res.status(400).send('Bad request.')
|
||||
const user = await User.findOne({where: { username: name }})
|
||||
if (!user) return res.status(404).send(`No record found for ${name}`)
|
||||
if (!name) { return res.status(400).send('Bad request.') }
|
||||
const user = await User.findOne({ where: { username: name } })
|
||||
if (!user) { return res.status(404).send(`No record found for ${name}`) }
|
||||
const ret = {
|
||||
'@context': [
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
@@ -44,9 +44,9 @@ module.exports = {
|
||||
const name = req.params.name
|
||||
const page = req.query.page
|
||||
debug('Retrieve %s followers', name)
|
||||
if (!name) return res.status(400).send('Bad request.')
|
||||
const user = await User.findOne({where: { username: name }, include: { model: FedUsers, as: 'followers' }})
|
||||
if (!user) return res.status(404).send(`No record found for ${name}`)
|
||||
if (!name) { return res.status(400).send('Bad request.') }
|
||||
const user = await User.findOne({ where: { username: name }, include: { model: FedUsers, as: 'followers' } })
|
||||
if (!user) { return res.status(404).send(`No record found for ${name}`) }
|
||||
|
||||
res.type('application/activity+json; charset=utf-8')
|
||||
|
||||
@@ -58,7 +58,7 @@ module.exports = {
|
||||
type: 'OrderedCollection',
|
||||
totalItems: user.followers.length,
|
||||
first: `${config.baseurl}/federation/u/${name}/followers?page=true`,
|
||||
last: `${config.baseurl}/federation/u/${name}/followers?page=true`,
|
||||
last: `${config.baseurl}/federation/u/${name}/followers?page=true`
|
||||
})
|
||||
}
|
||||
return res.json({
|
||||
@@ -66,22 +66,22 @@ module.exports = {
|
||||
id: `${config.baseurl}/federation/u/${name}/followers?page=${page}`,
|
||||
type: 'OrderedCollectionPage',
|
||||
totalItems: user.followers.length,
|
||||
partOf: `${config.baseurl}/federation/u/${name}/followers` ,
|
||||
orderedItems: user.followers
|
||||
partOf: `${config.baseurl}/federation/u/${name}/followers`,
|
||||
orderedItems: user.followers
|
||||
})
|
||||
},
|
||||
|
||||
async outbox (req, res) {
|
||||
const name = req.params.name
|
||||
const page = req.query.page
|
||||
|
||||
if (!name) return res.status(400).send('Bad request.')
|
||||
|
||||
if (!name) { return res.status(400).send('Bad request.') }
|
||||
const user = await User.findOne({
|
||||
include: [ { model: Event, include: [ Place, Tag ] } ],
|
||||
where: { username: name }
|
||||
})
|
||||
|
||||
if (!user) return res.status(404).send(`No record found for ${name}`)
|
||||
if (!user) { return res.status(404).send(`No record found for ${name}`) }
|
||||
|
||||
debug('Inside outbox, should return all events from this user')
|
||||
|
||||
@@ -98,14 +98,14 @@ module.exports = {
|
||||
last: `${config.baseurl}/federation/u/${name}/outbox?page=true`
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
debug('With pagination %s', page)
|
||||
return res.json({
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: `${config.baseurl}/federation/u/${name}/outbox?page=${page}`,
|
||||
type: 'OrderedCollectionPage',
|
||||
totalItems: user.events.length,
|
||||
partOf: `${config.baseurl}/federation/u/${name}/outbox` ,
|
||||
partOf: `${config.baseurl}/federation/u/${name}/outbox`,
|
||||
orderedItems: user.events.map(e => ({
|
||||
id: `${config.baseurl}/federation/m/${e.id}#create`,
|
||||
type: 'Create',
|
||||
@@ -115,6 +115,6 @@ module.exports = {
|
||||
actor: `${config.baseurl}/federation/u/${user.username}`,
|
||||
object: e.toAP(user.username)
|
||||
}))
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,11 @@ const debug = require('debug')('webfinger')
|
||||
router.use(cors())
|
||||
router.use((req, res, next) => {
|
||||
// is federation enabled ?
|
||||
if (req.settings.enable_federation) return next()
|
||||
if (req.settings.enable_federation) { return next() }
|
||||
debug('Federation disabled')
|
||||
res.status(404).send('Federation disabled')
|
||||
})
|
||||
|
||||
|
||||
router.get('/webfinger', async (req, res) => {
|
||||
if (!req.query || !req.query.resource || !req.query.resource.includes('acct:')) {
|
||||
debug('Bad webfinger request => %s', resource.query)
|
||||
@@ -28,7 +27,7 @@ router.get('/webfinger', async (req, res) => {
|
||||
|
||||
if (domain !== req_domain) {
|
||||
debug('Bad webfinger request, requested domain "%s" instead of "%s"', req_domain, domain)
|
||||
return res.status(400).send('Bad request. Please make sure "acct:USER@DOMAIN" is what you are sending as the "resource" query parameter.')
|
||||
return res.status(400).send('Bad request. Please make sure "acct:USER@DOMAIN" is what you are sending as the "resource" query parameter.')
|
||||
}
|
||||
|
||||
const user = await User.findOne({ where: { username: name } })
|
||||
|
||||
@@ -21,7 +21,7 @@ module.exports = {
|
||||
consola.info(`Save configuration to ${config_path}`)
|
||||
try {
|
||||
fs.writeFileSync(config_path, JSON.stringify(config, null, 2))
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
consola.warn(` ⚠️ ${e}. You can specify configuration path using '--config'`)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ async function main () {
|
||||
await nuxt.ready()
|
||||
}
|
||||
nuxt.listen()
|
||||
consola.info('Listen on %s:%d , visit me here => %s', config.server.host, config.server.port, config.baseurl )
|
||||
consola.info('Listen on %s:%d , visit me here => %s', config.server.host, config.server.port, config.baseurl)
|
||||
|
||||
// close connections/port/unix socket
|
||||
function shutdown () {
|
||||
|
||||
@@ -1,31 +1,32 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('tags',
|
||||
{
|
||||
tag: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
index: true,
|
||||
primaryKey: true
|
||||
},
|
||||
weigth: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0, allowNull: false
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
})
|
||||
{
|
||||
tag: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
index: true,
|
||||
primaryKey: true
|
||||
},
|
||||
weigth: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0,
|
||||
allowNull: false
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('tags')
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('places',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER,
|
||||
},
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
unique: true,
|
||||
index: true,
|
||||
allowNull: false
|
||||
},
|
||||
address: Sequelize.STRING,
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
})
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
unique: true,
|
||||
index: true,
|
||||
allowNull: false
|
||||
},
|
||||
address: Sequelize.STRING,
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
@@ -26,4 +26,4 @@ module.exports = {
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('settings')
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
@@ -8,7 +8,7 @@ module.exports = {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
username: {
|
||||
type: Sequelize.STRING,
|
||||
@@ -43,6 +43,6 @@ module.exports = {
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('users');
|
||||
return queryInterface.dropTable('users')
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('events',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
title: Sequelize.STRING,
|
||||
slug: Sequelize.STRING,
|
||||
description: Sequelize.TEXT,
|
||||
multidate: Sequelize.BOOLEAN,
|
||||
start_datetime: {
|
||||
type: Sequelize.INTEGER,
|
||||
index: true
|
||||
},
|
||||
end_datetime: {
|
||||
type: Sequelize.INTEGER,
|
||||
index: true
|
||||
},
|
||||
image_path: Sequelize.STRING,
|
||||
is_visible: Sequelize.BOOLEAN,
|
||||
recurrent: Sequelize.JSON,
|
||||
// parent: Sequelize.INTEGER
|
||||
likes: { type: Sequelize.JSON, defaultValue: [] },
|
||||
boost: { type: Sequelize.JSON, defaultValue: [] },
|
||||
placeId: {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: 'places',
|
||||
key: 'id',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'SET NULL',
|
||||
},
|
||||
userId: {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: 'users',
|
||||
key: 'id',
|
||||
title: Sequelize.STRING,
|
||||
slug: Sequelize.STRING,
|
||||
description: Sequelize.TEXT,
|
||||
multidate: Sequelize.BOOLEAN,
|
||||
start_datetime: {
|
||||
type: Sequelize.INTEGER,
|
||||
index: true
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'SET NULL',
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
})
|
||||
end_datetime: {
|
||||
type: Sequelize.INTEGER,
|
||||
index: true
|
||||
},
|
||||
image_path: Sequelize.STRING,
|
||||
is_visible: Sequelize.BOOLEAN,
|
||||
recurrent: Sequelize.JSON,
|
||||
// parent: Sequelize.INTEGER
|
||||
likes: { type: Sequelize.JSON, defaultValue: [] },
|
||||
boost: { type: Sequelize.JSON, defaultValue: [] },
|
||||
placeId: {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: 'places',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'SET NULL'
|
||||
},
|
||||
userId: {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: 'users',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'SET NULL'
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('events')
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('comments',
|
||||
{
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
activitypub_id: {
|
||||
type: Sequelize.STRING(18),
|
||||
index: true,
|
||||
unique: true
|
||||
},
|
||||
eventId: {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: 'events',
|
||||
key: 'id',
|
||||
{
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'SET NULL',
|
||||
},
|
||||
data: Sequelize.JSON,
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
})
|
||||
activitypub_id: {
|
||||
type: Sequelize.STRING(18),
|
||||
index: true,
|
||||
unique: true
|
||||
},
|
||||
eventId: {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: 'events',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'SET NULL'
|
||||
},
|
||||
data: Sequelize.JSON,
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('comments')
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
@@ -23,4 +23,4 @@ module.exports = {
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('fed_users')
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
@@ -32,4 +32,4 @@ module.exports = {
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('user_followers')
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('notifications',{
|
||||
return queryInterface.createTable('notifications', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
filters: Sequelize.JSON,
|
||||
email: Sequelize.STRING,
|
||||
@@ -33,4 +33,4 @@ module.exports = {
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('notifications')
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
@@ -12,4 +12,4 @@ module.exports = {
|
||||
return queryInterface.removeIndex('notifications',
|
||||
['actions', 'type'])
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
@@ -16,25 +16,25 @@ module.exports = {
|
||||
primaryKey: true,
|
||||
references: {
|
||||
model: 'events',
|
||||
key: 'id',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
tagTag: {
|
||||
primaryKey: true,
|
||||
type: Sequelize.STRING,
|
||||
references: {
|
||||
model: 'tags',
|
||||
key: 'tag',
|
||||
key: 'tag'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
onDelete: 'CASCADE'
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('event_tags')
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
@@ -16,20 +16,20 @@ module.exports = {
|
||||
primaryKey: true,
|
||||
references: {
|
||||
model: 'events',
|
||||
key: 'id',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
notificationId: {
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: 'notifications',
|
||||
key: 'id',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
36
server/migrations/20191027130750-create-instances.js
Normal file
36
server/migrations/20191027130750-create-instances.js
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict'
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('instances', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
domain: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
blocked: {
|
||||
type: Sequelize.BOOLEAN
|
||||
},
|
||||
data: {
|
||||
type: Sequelize.JSON
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
})
|
||||
},
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('instances')
|
||||
}
|
||||
}
|
||||
19
server/migrations/20191027132035-fed_users_instances.js
Normal file
19
server/migrations/20191027132035-fed_users_instances.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.addColumn('fed_users', 'instanceId', {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: 'instances',
|
||||
key: 'id'
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE'
|
||||
})
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropColumn('fed_users', 'instanceId')
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ const { event: Event, notification: Notification, event_notification: EventNotif
|
||||
const eventController = require('./api/controller/event')
|
||||
|
||||
const notifier = {
|
||||
async sendNotification (notification, event) {
|
||||
sendNotification (notification, event) {
|
||||
const promises = []
|
||||
debug('Send %s notification %s', notification.type, notification.action)
|
||||
let p
|
||||
@@ -19,6 +19,7 @@ const notifier = {
|
||||
case 'admin_email':
|
||||
p = mail.send([config.smtp.auth.user, config.admin_email], 'event', { event, to_confirm: !event.is_visible, config, notification })
|
||||
promises.push(p)
|
||||
break
|
||||
case 'ap':
|
||||
p = fediverseHelpers.sendEvent(event, event.user, notification.action)
|
||||
promises.push(p)
|
||||
@@ -26,13 +27,13 @@ const notifier = {
|
||||
return Promise.all(promises)
|
||||
},
|
||||
async notifyEvent (action, eventId) {
|
||||
let event = await Event.findByPk(eventId, {
|
||||
const event = await Event.findByPk(eventId, {
|
||||
|
||||
include: [ Tag, Place, Notification, { model: User, include: { model: FedUsers, as: 'followers'}} ]
|
||||
include: [ Tag, Place, Notification, { model: User, include: { model: FedUsers, as: 'followers' } } ]
|
||||
})
|
||||
|
||||
debug('%s -> %s', action, event.title)
|
||||
|
||||
|
||||
// insert notifications
|
||||
const notifications = await eventController.getNotifications(event, action)
|
||||
await event.addNotifications(notifications)
|
||||
@@ -59,7 +60,7 @@ const notifier = {
|
||||
if (!event.place) { return }
|
||||
const notification = await Notification.findByPk(e.notificationId)
|
||||
try {
|
||||
await sendNotification(type, notification, event)
|
||||
await notifier.sendNotification(notification, event)
|
||||
e.status = 'sent'
|
||||
return e.save()
|
||||
} catch (err) {
|
||||
|
||||
@@ -26,7 +26,7 @@ router.use('/media/', express.static(config.upload_path))
|
||||
// get instance settings
|
||||
router.use(helpers.initMiddleware)
|
||||
|
||||
// rss/ics/atom feed
|
||||
// rss/ics/atom feed
|
||||
router.get('/feed/:type', cors(), exportController.export)
|
||||
|
||||
// api!
|
||||
|
||||
Reference in New Issue
Block a user