[lint] linting

This commit is contained in:
les 2019-10-28 17:33:20 +01:00
parent bda72f1559
commit e467a28902
56 changed files with 373 additions and 306 deletions

View file

@ -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 {
}
}
}
</script>
</script>

View file

@ -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"

View file

@ -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 }) }
},
}
}
}
</script>
</script>

View file

@ -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'])
}
</script>
</script>

View file

@ -1,4 +1,4 @@
export default [
'Europe/Rome',
'Europe/Paris',
]
'Europe/Paris'
]

View file

@ -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: {

View file

@ -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;
}
</style>
</style>

View file

@ -52,8 +52,8 @@
</template>
<script>
import { mapState, mapActions } from 'vuex'
import { Message, MessageBox } from 'element-ui'
import { mapState } from 'vuex'
import { Message } from 'element-ui'
import Users from '../components/admin/Users'
import Places from '../components/admin/Places'
import Settings from '../components/admin/Settings'
@ -91,7 +91,7 @@ export default {
paginatedEvents () {
return this.events.slice((this.eventPage - 1) * this.perPage,
this.eventPage * this.perPage)
},
}
},
methods: {
preview (id) {

View file

@ -16,21 +16,20 @@
<script>
import { mapState } from 'vuex'
import Event from '../../components/Event'
import moment from 'dayjs'
import get from 'lodash/get'
export default {
layout: 'event_iframe',
components: { Event },
data: {
loading: true
data () {
return {
loading: true
}
},
async asyncData ({ $axios, params, error, store }) {
try {
const [ id, start_datetime ] = params.event_id.split('_')
const event = await $axios.$get(`/event/${id}`)
event.start_datetime = start_datetime ? Number(start_datetime) : event.start_datetime
event.end_datetime = event.end_datetime
return { event, id: Number(id) }
} catch (e) {
error({ statusCode: 404, message: 'Event not found' })

View file

@ -2,10 +2,7 @@
List(:events="events" :title='title')
</template>
<script>
import { mapState } from 'vuex'
import List from '../../components/List'
import moment from 'dayjs'
import get from 'lodash/get'
export default {
layout: 'iframe',
@ -19,7 +16,6 @@ export default {
const title = query.title
const tags = query.tags
const places = query.places
const now = new Date()
let params = []
if (places) { params.push(`places=${places}`) }

View file

@ -50,7 +50,7 @@
small.mr-3 🔖 {{event.likes.length}}
small {{event.boost.length}}<br/>
strong(v-if='settings.enable_comments') {{$tc('common.comments', event.comments.length)}} -
strong(v-if='settings.enable_comments') {{$tc('common.comments', event.comments.length)}} -
small {{$t('event.interact_with_me_at')}} <u>{{fedi_user}}@{{settings.baseurl|url2host}}</u>
.card-header(v-if='settings.enable_comments' v-for='comment in event.comments' :key='comment.id')
@ -61,37 +61,40 @@
</template>
<script>
import { mapState, mapActions, mapGetters } from 'vuex'
import { MessageBox } from 'element-ui'
import { mapState, mapGetters } from 'vuex'
import EventAdmin from './eventAdmin'
import moment from 'dayjs'
export default {
name: 'Event',
transition: null,
components: { EventAdmin },
data () {
return {
copied: false
}
},
components: { EventAdmin },
head () {
if (!this.event) { return {} }
const tags_feed = this.event.tags.map(tag => ({ rel: 'alternate', type: 'application/rss+xml',
title: `${this.settings.title} events tagged ${tag}`, href: this.settings.baseurl + `/feed/rss?tags=${tag}` }))
const place_feed = { rel: 'alternate', type: 'application/rss+xml',
title: `${this.settings.title} events @${this.event.place.name}`, href: this.settings.baseurl + `/feed/rss?places=${this.event.placeId}` }
const tags_feed = this.event.tags.map(tag => ({ rel: 'alternate',
type: 'application/rss+xml',
title: `${this.settings.title} events tagged ${tag}`,
href: this.settings.baseurl + `/feed/rss?tags=${tag}` }))
const place_feed = { rel: 'alternate',
type: 'application/rss+xml',
title: `${this.settings.title} events @${this.event.place.name}`,
href: this.settings.baseurl + `/feed/rss?places=${this.event.placeId}` }
return {
title: `${this.settings.title} - ${this.event.title}`,
meta: [
// hid is used as unique identifier. Do not use `vmid` for it as it will not work
{ hid: 'description',
name: 'description',
content: this.event.description.replace("\n",'').slice(0, 1000) },
content: this.event.description.replace('\n', '').slice(0, 1000) },
{ hid: 'og-description',
name: 'og:description',
content: this.event.description.replace("\n",'').slice(0, 100) },
content: this.event.description.replace('\n', '').slice(0, 100) },
{ hid: 'og-title', property: 'og:title', content: this.event.title },
{ hid: 'og-url', property: 'og:url', content: `${this.settings.baseurl}/event/${this.event.id}` },
{ property: 'og:type', content: 'event' },
@ -99,18 +102,18 @@ export default {
{ property: 'og:site_name', content: this.settings.title },
{ property: 'og:updated_time', content: moment.unix(this.event.start_datetime).format() },
{ property: 'article:published_time', content: moment.unix(this.event.start_datetime).format() },
{ property: 'article:section', content: 'event'},
{ property: 'twitter:card', content: 'summary'},
{ property: 'article:section', content: 'event' },
{ property: 'twitter:card', content: 'summary' },
{ property: 'twitter:title', content: this.event.title },
{ property: 'twitter:image', content: `${this.settings.baseurl}${this.imgPath}` },
{ property: 'twitter:description', content: this.event.description.replace("\n",'').slice(0, 100) }
{ property: 'twitter:description', content: this.event.description.replace('\n', '').slice(0, 100) }
],
link: [
{ rel: 'image_src', href: `${this.settings.baseurl}${this.imgPath}` },
{ rel: 'alternate', type: 'application/rss+xml', title: this.settings.title, href: this.settings.baseurl + '/feed/rss' },
...tags_feed,
place_feed
]
]
}
},
async asyncData ({ $axios, params, error, store }) {
@ -118,7 +121,6 @@ export default {
const [ id, start_datetime ] = params.id.split('_')
const event = await $axios.$get(`/event/${id}`)
event.start_datetime = start_datetime ? Number(start_datetime) : event.start_datetime
event.end_datetime = event.end_datetime
const now = new Date()
const events = await $axios.$get(`/event/${now.getMonth()}/${now.getFullYear()}`)
store.commit('setEvents', events)
@ -168,11 +170,11 @@ export default {
},
methods: {
copyLink () {
this.copied=true
setTimeout(() => this.copied=false, 3000)
this.copied = true
setTimeout(() => { this.copied = false }, 3000)
},
comment_filter (value) {
return value.replace(/<a.*href="([^">]+).*>(?:.(?!\<\/a\>))*.<\/a>/, (orig, url) => {
return value.replace(/<a.*href="([^">]+).*>(?:.(?!<\/a>))*.<\/a>/, (orig, url) => {
// get extension
const ext = url.slice(-4)
if (['.mp3', '.ogg'].includes(ext)) {
@ -181,7 +183,7 @@ export default {
return orig
}
})
},
}
}
}
</script>
@ -247,7 +249,6 @@ export default {
}
}
@media only screen and (max-width: 768px) {
#eventDetail {
.menu {

View file

@ -44,4 +44,4 @@ export default {
}
}
}
</script>
</script>

View file

@ -53,11 +53,8 @@
</template>
<script>
import { mapState, mapGetters } from 'vuex'
import Calendar from '@/components/Calendar'
import List from '@/components/List'
import Search from '@/components/Search'
import { intersection } from 'lodash'
import { Message } from 'element-ui'
export default {
@ -68,12 +65,6 @@ export default {
title: `${this.settings.title} - ${this.$t('common.export')}`
}
},
async asyncData ({ $axios, params, store }) {
// get metadata just in case we are not coming from home
if (store.state.tags.length) return
const { tags, places } = await $axios.$get('/event/meta')
store.commit('update', { tags, places })
},
data () {
return {
type: 'rss',
@ -81,6 +72,12 @@ export default {
list: { title: 'Gancio' }
}
},
async asyncData ({ $axios, params, store }) {
// get metadata just in case we are not coming from home
if (store.state.tags.length) { return }
const { tags, places } = await $axios.$get('/event/meta')
store.commit('update', { tags, places })
},
methods: {
copy (msg) {
this.$copyText(msg).then(e => console.error('ok ', e)).catch(e => console.error('err ', e))

View file

@ -13,11 +13,8 @@ import { mapState } from 'vuex'
export default {
name: 'Index',
computed: mapState(['settings']),
mounted (ctx) {
moment.tz.setDefault(this.settings.instance_timezone)
},
async fetch ({ store, $axios }) {
try {
try {
moment.tz.setDefault(store.state.settings.instance_timezone)
const now = new Date()
const events = await $axios.$get(`/event/${now.getMonth()}/${now.getFullYear()}`)
@ -28,6 +25,9 @@ export default {
console.error(e)
}
},
mounted (ctx) {
moment.tz.setDefault(this.settings.instance_timezone)
},
components: { Nav, Home }
}
</script>

View file

@ -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',

View file

@ -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' })
})
},

View file

@ -49,4 +49,4 @@ export default {
}
}
}
</script>
</script>

View file

@ -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') {

View file

@ -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) {

View file

@ -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'] },

View file

@ -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 }
}]
}
})

View file

@ -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!' }) }

View file

@ -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)

View file

@ -76,7 +76,7 @@ module.exports = (sequelize, DataTypes) => {
cc: follower || [],
content,
summary: null,
sensitive: false,
sensitive: false
}
}

View file

@ -10,5 +10,5 @@ module.exports = (sequelize, DataTypes) => {
}
}, {})
return event_notification
return event_notification
}

View file

@ -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
}
}

View file

@ -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)
}

View 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
}

View file

@ -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) {

View file

@ -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: {

View file

@ -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!')

View file

@ -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)
}
}

View file

@ -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)
}

View file

@ -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])

View file

@ -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
}

View file

@ -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)
}))
})
})
}
}

View file

@ -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 } })

View file

@ -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'`)
}

View file

@ -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 () {

View file

@ -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')
}
};
}

View file

@ -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) => {

View file

@ -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')
}
};
}

View file

@ -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')
}
};
}

View file

@ -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')
}
};
}

View file

@ -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')
}
};
}

View file

@ -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')
}
};
}

View file

@ -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')
}
};
}

View file

@ -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')
}
};
}

View file

@ -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'])
}
};
}

View file

@ -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')
}
};
}

View file

@ -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'
}
})
},

View 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')
}
}

View 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')
}
}

View file

@ -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) {

View file

@ -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!

View file

@ -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<year || page.year===year && page.month<=month )
commit('setPast', page.year < year || (page.year === year && page.month <= month))
const events = await this.$axios.$get(`/event/${page.month - 1}/${page.year}`)
commit('setEvents', events)
},