diff --git a/components/Login.vue b/components/Login.vue index 941d8517..2fa5f4b8 100644 --- a/components/Login.vue +++ b/components/Login.vue @@ -34,7 +34,7 @@ export default { return { password: '', email: '', - loading: false, + loading: false } }, computed: { @@ -61,7 +61,7 @@ export default { Message({ message: this.$t('login.check_email'), type: 'success' }) }, async submit (e) { - if (this.disabled) return false + if (this.disabled) { return false } e.preventDefault() try { this.loading = true @@ -79,4 +79,4 @@ export default { } } } - \ No newline at end of file + diff --git a/components/Register.vue b/components/Register.vue index 70aea48d..b342a1a2 100644 --- a/components/Register.vue +++ b/components/Register.vue @@ -9,7 +9,7 @@ :placeholder='$t("common.username")' prefix-icon='el-icon-user') el-input.mb-2(ref='email' v-model='user.email' type='email' required - :placeholder='$t("common.email")' autocomplete='email' + :placeholder='$t("common.email")' autocomplete='email' prefix-icon='el-icon-message' name='email') el-input.mb-2(v-model='user.password' type="password" diff --git a/components/admin/Federation.vue b/components/admin/Federation.vue index dd9ef5ac..a7d99e63 100644 --- a/components/admin/Federation.vue +++ b/components/admin/Federation.vue @@ -22,12 +22,12 @@ export default { }, enable_comments: { get () { return this.settings.enable_comments }, - set (value) { this.setSetting({ key: 'enable_comments', value }) } + set (value) { this.setSetting({ key: 'enable_comments', value }) } }, disable_gamification: { get () { return this.settings.disable_gamification }, set (value) { this.setSetting({ key: 'disable_gamification', value }) } - }, + } } } - \ No newline at end of file + diff --git a/components/admin/Settings.vue b/components/admin/Settings.vue index c855f8f3..d32b5d54 100644 --- a/components/admin/Settings.vue +++ b/components/admin/Settings.vue @@ -5,7 +5,7 @@ el-form-item(:label="$t('admin.select_instance_timezone')") el-select(v-model='instance_timezone' filterable) el-option(v-for='timezone in timezones' :key='timezone.value' :value='timezone.value') - span.float-left {{timezone.value}} + span.float-left {{timezone.value}} small.float-right.text-danger {{timezone.offset}} //- allow open registration @@ -57,8 +57,8 @@ export default { recurrent_event_visible: { get () { return this.settings.recurrent_event_visible }, set (value) { this.setSetting({ key: 'recurrent_event_visible', value }) } - }, + } }, methods: mapActions(['setSetting']) } - \ No newline at end of file + diff --git a/components/admin/timezones.js b/components/admin/timezones.js index 68fb7316..3bc863ab 100644 --- a/components/admin/timezones.js +++ b/components/admin/timezones.js @@ -1,4 +1,4 @@ export default [ 'Europe/Rome', - 'Europe/Paris', -] \ No newline at end of file + 'Europe/Paris' +] diff --git a/locales/it.js b/locales/it.js index b78f3bea..fdb15373 100644 --- a/locales/it.js +++ b/locales/it.js @@ -137,7 +137,7 @@ export default { due: 'alle', from: 'Dalle', image_too_big: 'Immagine troppo grande! Massimo 4M', - interact_with_me_at: 'Seguimi nel fediverso su', + interact_with_me_at: 'Seguimi nel fediverso su' }, admin: { diff --git a/pages/add/_edit.vue b/pages/add/_edit.vue index 3030d7bd..519af700 100644 --- a/pages/add/_edit.vue +++ b/pages/add/_edit.vue @@ -118,7 +118,6 @@ import List from '@/components/List' import { Message } from 'element-ui' export default { - name: 'Add', name: 'newEvent', components: { List }, validate ({ store }) { @@ -241,6 +240,7 @@ export default { } else if (freq === '1d') { return this.$t('event.recurrent_each_day') } + return }, todayEvents () { if (this.event.type === 'multidate') { @@ -250,11 +250,11 @@ export default { return this.events.filter(e => !e.multidate ? date_start.isSame(moment.unix(e.start_datetime), 'day') || - date_start.isBefore(moment.unix(e.start_dateime)) && date_end.isAfter(moment.unix(e.start_datetime)) + (date_start.isBefore(moment.unix(e.start_dateime)) && date_end.isAfter(moment.unix(e.start_datetime))) : date_start.isSame(moment.unix(e.start_datetime), 'day') || date_start.isSame(moment.unix(e.end_datetime)) || - date_start.isAfter(moment.unix(e.start_datetime)) && date_start.isBefore(moment.unix(e.end_datetime))) + (date_start.isAfter(moment.unix(e.start_datetime)) && date_start.isBefore(moment.unix(e.end_datetime)))) } else if (this.event.type === 'recurrent') { - + return [] } else { const date = moment(this.date) return this.events.filter(e => @@ -292,13 +292,17 @@ export default { switch (Number(this.activeTab)) { case 0 + t: return true + break case 1 + t: return this.event.title.length > 0 + break case 2 + t: return this.event.place.name.length > 0 && this.event.place.address.length > 0 + break case 3 + t: if (this.date && this.time.start) { return true } + break case 4 + t: return this.event.place.name.length > 0 && this.event.place.address.length > 0 && @@ -312,7 +316,7 @@ export default { recurrentDays () { if (this.event.type !== 'recurrent' || !this.date || !this.date.length) { return } const type = this.event.recurrent.type - if (type === 'ordinal') { return map(this.date, d => moment(d).date()) } else if (type === 'weekday') { return map(this.date, moment(d).day() + 1) } + if (type === 'ordinal') { return map(this.date, d => moment(d).date()) } else if (type === 'weekday') { return map(this.date, d => moment(d).day() + 1) } }, next () { this.activeTab = String(Number(this.activeTab) + 1) @@ -424,4 +428,4 @@ export default { #picker { max-width: 400px; } - \ No newline at end of file + diff --git a/pages/admin.vue b/pages/admin.vue index 3fa9dbe5..5c9a69ca 100644 --- a/pages/admin.vue +++ b/pages/admin.vue @@ -52,8 +52,8 @@ @@ -247,7 +249,6 @@ export default { } } - @media only screen and (max-width: 768px) { #eventDetail { .menu { diff --git a/pages/event/eventAdmin.vue b/pages/event/eventAdmin.vue index 7de3da7c..659967f0 100644 --- a/pages/event/eventAdmin.vue +++ b/pages/event/eventAdmin.vue @@ -44,4 +44,4 @@ export default { } } } - \ No newline at end of file + diff --git a/pages/export.vue b/pages/export.vue index eb81635c..b8f1f873 100644 --- a/pages/export.vue +++ b/pages/export.vue @@ -53,11 +53,8 @@ diff --git a/pages/recover/_code.vue b/pages/recover/_code.vue index 23846980..719719c0 100644 --- a/pages/recover/_code.vue +++ b/pages/recover/_code.vue @@ -29,7 +29,7 @@ export default { methods: { async change_password () { try { - const res = await this.$axios.$post('/user/recover_password', { recover_code: this.code, password: this.new_password }) + await this.$axios.$post('/user/recover_password', { recover_code: this.code, password: this.new_password }) Message({ showClose: true, type: 'success', diff --git a/pages/settings.vue b/pages/settings.vue index 906da722..88a35429 100644 --- a/pages/settings.vue +++ b/pages/settings.vue @@ -50,7 +50,7 @@ export default { }, async asyncData ({ $axios, params }) { const user = await $axios.$get('/auth/user') - return { user, username_editable: user.username.length===0 } + return { user, username_editable: user.username.length === 0 } }, computed: { ...mapState(['settings']), @@ -77,8 +77,8 @@ export default { cancelButtonText: this.$t('common.cancel'), type: 'error' }).then(async () => { - this.user = await this.$axios.$put('/user', { ...this.user, password: this.password }) - }).catch( e => { + this.user = await this.$axios.$put('/user', { ...this.user, password: this.password }) + }).catch(e => { Message({ message: e, showClose: true, type: 'warning' }) }) }, diff --git a/pages/user_confirm/_code.vue b/pages/user_confirm/_code.vue index 774039df..4467944f 100644 --- a/pages/user_confirm/_code.vue +++ b/pages/user_confirm/_code.vue @@ -49,4 +49,4 @@ export default { } } } - \ No newline at end of file + diff --git a/plugins/filters.js b/plugins/filters.js index 9c053091..94ca3904 100644 --- a/plugins/filters.js +++ b/plugins/filters.js @@ -2,7 +2,6 @@ import Vue from 'vue' import moment from 'moment-timezone' export default ({ app, store }) => { - // set timezone to instance_timezone!! // to show local time relative to event's place // not where in the worlds I'm looking at the page from @@ -18,14 +17,14 @@ export default ({ app, store }) => { // shown in mobile homepage Vue.filter('day', value => moment.unix(value).locale(store.state.locale).format('dddd, D MMM')) - Vue.filter('to', value => moment().to(value.start_datetime*1000)) + Vue.filter('to', value => moment().to(value.start_datetime * 1000)) // format event start/end datetime based on page Vue.filter('when', (event, where) => { moment.locale(store.state.locale) const start = moment.unix(event.start_datetime) const end = moment.unix(event.end_datetime) - + const normal = `${start.format('dddd, D MMMM (HH:mm-')}${end.format('HH:mm) ')}` // recurrent event if (event.recurrent && where !== 'home') { diff --git a/plugins/i18n.js b/plugins/i18n.js index 4c7e2367..185eb63e 100644 --- a/plugins/i18n.js +++ b/plugins/i18n.js @@ -7,10 +7,9 @@ import messages from '../locales' Vue.use(VueI18n) export default async ({ app, store, req }) => { - if (process.server) { store.commit('setLocale', req.settings.locale) - if (req.settings.user_locale) store.commit('setUserLocale', req.settings.user_locale) + if (req.settings.user_locale) { store.commit('setUserLocale', req.settings.user_locale) } } if (store.state.user_locale) { diff --git a/server/api/controller/event.js b/server/api/controller/event.js index 2a7f1dea..958fee5e 100644 --- a/server/api/controller/event.js +++ b/server/api/controller/event.js @@ -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'] }, diff --git a/server/api/controller/export.js b/server/api/controller/export.js index 5917b36f..73b71bf3 100644 --- a/server/api/controller/export.js +++ b/server/api/controller/export.js @@ -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 } }] } }) diff --git a/server/api/controller/user.js b/server/api/controller/user.js index 1d9cf4f7..e39810ea 100644 --- a/server/api/controller/user.js +++ b/server/api/controller/user.js @@ -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!' }) } diff --git a/server/api/index.js b/server/api/index.js index a006c96a..bba88c21 100644 --- a/server/api/index.js +++ b/server/api/index.js @@ -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) diff --git a/server/api/models/event.js b/server/api/models/event.js index e95812f3..867e29d9 100644 --- a/server/api/models/event.js +++ b/server/api/models/event.js @@ -76,7 +76,7 @@ module.exports = (sequelize, DataTypes) => { cc: follower || [], content, summary: null, - sensitive: false, + sensitive: false } } diff --git a/server/api/models/eventnotification.js b/server/api/models/eventnotification.js index fd99c944..5e1cff64 100644 --- a/server/api/models/eventnotification.js +++ b/server/api/models/eventnotification.js @@ -10,5 +10,5 @@ module.exports = (sequelize, DataTypes) => { } }, {}) - return event_notification + return event_notification } diff --git a/server/api/models/fed_users.js b/server/api/models/fed_users.js index 7b478052..9ab557e6 100644 --- a/server/api/models/fed_users.js +++ b/server/api/models/fed_users.js @@ -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 -} \ No newline at end of file +} diff --git a/server/api/models/index.js b/server/api/models/index.js index c9051d8a..175639e7 100644 --- a/server/api/models/index.js +++ b/server/api/models/index.js @@ -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) } diff --git a/server/api/models/instances.js b/server/api/models/instances.js new file mode 100644 index 00000000..9d232468 --- /dev/null +++ b/server/api/models/instances.js @@ -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 +} diff --git a/server/api/models/tag.js b/server/api/models/tag.js index a21311a1..59dd7465 100644 --- a/server/api/models/tag.js +++ b/server/api/models/tag.js @@ -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) { diff --git a/server/api/models/user.js b/server/api/models/user.js index af468fd4..1ddeb14f 100644 --- a/server/api/models/user.js +++ b/server/api/models/user.js @@ -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: { diff --git a/server/federation/comments.js b/server/federation/comments.js index 5aba22ed..d7fa96c1 100644 --- a/server/federation/comments.js +++ b/server/federation/comments.js @@ -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!') diff --git a/server/federation/ego.js b/server/federation/ego.js index 5a9dacdd..ceed2002 100644 --- a/server/federation/ego.js +++ b/server/federation/ego.js @@ -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) } } diff --git a/server/federation/follows.js b/server/federation/follows.js index fc8b76d0..ee823ad3 100644 --- a/server/federation/follows.js +++ b/server/federation/follows.js @@ -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) } diff --git a/server/federation/helpers.js b/server/federation/helpers.js index 2f434f64..f50901b3 100644 --- a/server/federation/helpers.js +++ b/server/federation/helpers.js @@ -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]) diff --git a/server/federation/index.js b/server/federation/index.js index 0e212634..e736c175 100644 --- a/server/federation/index.js +++ b/server/federation/index.js @@ -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 } diff --git a/server/federation/users.js b/server/federation/users.js index c654228e..d88f1438 100644 --- a/server/federation/users.js +++ b/server/federation/users.js @@ -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) })) - }) + }) } } diff --git a/server/federation/webfinger.js b/server/federation/webfinger.js index 6a29acbc..71f30d48 100644 --- a/server/federation/webfinger.js +++ b/server/federation/webfinger.js @@ -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 } }) diff --git a/server/firstrun.js b/server/firstrun.js index f0f6c65d..f3becb51 100644 --- a/server/firstrun.js +++ b/server/firstrun.js @@ -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'`) } diff --git a/server/index.js b/server/index.js index 6d9edac0..5195231c 100644 --- a/server/index.js +++ b/server/index.js @@ -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 () { diff --git a/server/migrations/20191025133803-tags.js b/server/migrations/20191025133803-tags.js index 0c2ac465..99b6065b 100644 --- a/server/migrations/20191025133803-tags.js +++ b/server/migrations/20191025133803-tags.js @@ -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') } -}; +} diff --git a/server/migrations/20191025134318-places.js b/server/migrations/20191025134318-places.js index ef81a8df..6aae5d3f 100644 --- a/server/migrations/20191025134318-places.js +++ b/server/migrations/20191025134318-places.js @@ -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) => { diff --git a/server/migrations/20191025135631-settings.js b/server/migrations/20191025135631-settings.js index 9d43eba5..5308b517 100644 --- a/server/migrations/20191025135631-settings.js +++ b/server/migrations/20191025135631-settings.js @@ -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') } -}; +} diff --git a/server/migrations/20191025141447-users.js b/server/migrations/20191025141447-users.js index a3fa4a2c..381d377b 100644 --- a/server/migrations/20191025141447-users.js +++ b/server/migrations/20191025141447-users.js @@ -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') } -}; +} diff --git a/server/migrations/20191025142724-events.js b/server/migrations/20191025142724-events.js index 64481054..162ad359 100644 --- a/server/migrations/20191025142724-events.js +++ b/server/migrations/20191025142724-events.js @@ -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') } -}; +} diff --git a/server/migrations/20191025143411-comments.js b/server/migrations/20191025143411-comments.js index 248537d9..7f1778bb 100644 --- a/server/migrations/20191025143411-comments.js +++ b/server/migrations/20191025143411-comments.js @@ -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') } -}; +} diff --git a/server/migrations/20191025145312-fed_users.js b/server/migrations/20191025145312-fed_users.js index b72acbaa..3db22dc1 100644 --- a/server/migrations/20191025145312-fed_users.js +++ b/server/migrations/20191025145312-fed_users.js @@ -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') } -}; +} diff --git a/server/migrations/20191025145516-followers.js b/server/migrations/20191025145516-followers.js index ba46651c..d36e983a 100644 --- a/server/migrations/20191025145516-followers.js +++ b/server/migrations/20191025145516-followers.js @@ -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') } -}; +} diff --git a/server/migrations/20191025150200-notifications.js b/server/migrations/20191025150200-notifications.js index 70bc9cba..6eea835c 100644 --- a/server/migrations/20191025150200-notifications.js +++ b/server/migrations/20191025150200-notifications.js @@ -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') } -}; +} diff --git a/server/migrations/20191025150506-notifications_index.js b/server/migrations/20191025150506-notifications_index.js index e0057716..03416e82 100644 --- a/server/migrations/20191025150506-notifications_index.js +++ b/server/migrations/20191025150506-notifications_index.js @@ -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']) } -}; +} diff --git a/server/migrations/20191025151459-event_tags.js b/server/migrations/20191025151459-event_tags.js index 5b7b21cb..07ebe533 100644 --- a/server/migrations/20191025151459-event_tags.js +++ b/server/migrations/20191025151459-event_tags.js @@ -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') } -}; +} diff --git a/server/migrations/20191025152224-event_notifications.js b/server/migrations/20191025152224-event_notifications.js index 64c6c9ba..395fb28d 100644 --- a/server/migrations/20191025152224-event_notifications.js +++ b/server/migrations/20191025152224-event_notifications.js @@ -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' } }) }, diff --git a/server/migrations/20191027130750-create-instances.js b/server/migrations/20191027130750-create-instances.js new file mode 100644 index 00000000..0589113a --- /dev/null +++ b/server/migrations/20191027130750-create-instances.js @@ -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') + } +} diff --git a/server/migrations/20191027132035-fed_users_instances.js b/server/migrations/20191027132035-fed_users_instances.js new file mode 100644 index 00000000..64dd559b --- /dev/null +++ b/server/migrations/20191027132035-fed_users_instances.js @@ -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') + } +} diff --git a/server/notifier.js b/server/notifier.js index bc6af4b9..56ef9c96 100644 --- a/server/notifier.js +++ b/server/notifier.js @@ -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) { diff --git a/server/routes.js b/server/routes.js index f612d25b..eefa1387 100644 --- a/server/routes.js +++ b/server/routes.js @@ -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! diff --git a/store/index.js b/store/index.js index 08958f22..f4ba22c9 100644 --- a/store/index.js +++ b/store/index.js @@ -148,7 +148,7 @@ export const mutations = { export const actions = { // this method is called server side only for each request // we use it to get configuration from db, setting locale, etc... - async nuxtServerInit ({ commit }, { app, store, req }) { + nuxtServerInit ({ commit }, { app, store, req }) { const settings = req.settings commit('setSettings', settings) // apply settings @@ -157,7 +157,7 @@ export const actions = { async updateEvents ({ commit }, page) { const month = moment().month() const year = moment().year() - commit('setPast', page.year