This commit is contained in:
lesion
2019-05-30 12:12:51 +02:00
parent 6099d538c0
commit 745b9247c9
46 changed files with 543 additions and 181 deletions

View File

@@ -11,6 +11,7 @@ const Auth = {
next()
},
async isAuth(req, res, next) {
console.error('ma sono dentro auth ?!?!', req.user)
if (!req.user) {
return res
.status(403)

View File

@@ -12,6 +12,7 @@ moment.locale('it')
const botController = {
bot: null,
async initialize () {
console.error('dentro bot inizialiteds')
const settings = await settingsController.settings()
if (!settings.mastodon_auth || !settings.mastodon_auth.access_token) return
const mastodon_auth = settings.mastodon_auth

View File

@@ -21,24 +21,22 @@ const eventController = {
async getMeta(req, res) {
const places = await Place.findAll({
group: ['place.id'],
order: [[Sequelize.fn("COUNT", Sequelize.col('events.id')), 'DESC']],
order: [[Sequelize.literal('weigth'), 'DESC']],
attributes: {
include: [[Sequelize.fn("COUNT", Sequelize.col('events.id')), 'eventsCount']],
exclude: ['createdAt', 'updatedAt']
include: [[Sequelize.fn('count', Sequelize.col('events.placeId')) ,'weigth']], // <---- Here you will get the total count of user
exclude: ['weigth', 'createdAt', 'updatedAt']
},
include: { model: Event, attributes: [] }
include: [{ model: Event, attributes: [] }],
group: ['place.id']
})
const tags = await Tag.findAll({
group: ['tag'],
order: [[Sequelize.fn("COUNT", Sequelize.col('events.id')), 'DESC']],
includeIgnoreAttributes:false,
order: [['weigth' , 'DESC']],
includeIgnoreAttributes: false,
attributes: {
include: [[Sequelize.fn("COUNT", Sequelize.col('events.id')), 'eventsCount']],
exclude: ['createdAt', 'updatedAt']
},
include: { model: Event, attributes: [] }})
}
})
res.json({ tags, places })
},
@@ -92,7 +90,7 @@ const eventController = {
Comment,
{ model: Place, attributes: ['name', 'address'] }
] ,
order: [ [Comment, 'id', 'DESC'] ]
order: [ [Comment, 'id', 'DESC'], [Tag, 'weigth', 'DESC'] ]
})
res.json(event)
},
@@ -177,15 +175,17 @@ const eventController = {
{ start_datetime: { [Op.lte]: end } }
]
},
order: [['start_datetime', 'ASC']],
order: [
['start_datetime', 'ASC'],
[Tag, 'weigth', 'DESC']
],
include: [
{ model: User, required: false },
Comment,
Tag,
{ model: Place, required: false }
// { model: User, required: false },
// { type: Comment, required: false, attributes: ['']
{ model: Tag, required: false, attributes: ['tag', 'weigth','color'] },
{ model: Place, required: false, attributes: ['id', 'name', 'address'] }
]
})
// console.log(events)
res.json(events)
}

View File

@@ -8,6 +8,7 @@ const exportController = {
async export (req, res) {
console.log('type ', req.params.type)
console.error(req)
const type = req.params.type
const tags = req.query.tags
const places = req.query.places
@@ -18,14 +19,20 @@ const exportController = {
whereTag.tag = tags.split(',')
}
if (places) {
wherePlace.name = places.split(',')
wherePlace.id = places.split(',')
}
console.error(places)
const events = await Event.findAll({
where: { is_visible: true, start_datetime: { [Op.gte]: yesterday } },
include: [Comment, {
model: Tag,
where: whereTag
}, { model: Place, where: wherePlace } ]
order: ['start_datetime'],
where: {
is_visible: true,
start_datetime: { [Op.gte]: yesterday },
placeId: places.split(',')
},
attributes: {
exclude: ['createdAt', 'updatedAt']
},
include: [{model: Place, attributes: ['name', 'id', 'address', 'weigth']}]
})
switch (type) {
case 'feed':

View File

@@ -74,17 +74,14 @@ const userController = {
async addEvent(req, res) {
const body = req.body
// remove description tag and create anchor tags
const description = body.description
.replace(/(<([^>]+)>)/ig, '')
.replace(/(https?:\/\/[^\s]+)/g, '<a href="$1">$1</a>')
const eventDetails = {
title: body.title,
description,
description: body.description.replace(/(<([^>]+)>)/ig, ''),
multidate: body.multidate,
start_datetime: body.start_datetime,
end_datetime: body.end_datetime,
// publish this event if authenticated
is_visible: !!req.user
}
@@ -94,7 +91,7 @@ const userController = {
let event = await Event.create(eventDetails)
// create place
// create place if needs to
let place
try {
place = await Place.findOrCreate({ where: { name: body.place_name },
@@ -140,7 +137,7 @@ const userController = {
body.description = body.description
.replace(/(<([^>]+)>)/ig, '') // remove all tags from description
.replace(/(https?:\/\/[^\s]+)/g, '<a href="$1">$1</a>') // add links
// .replace(/(https?:\/\/[^\s]+)/g, '<a href="$1">$1</a>') // add links
await event.update(body)
let place

View File

@@ -19,7 +19,8 @@ const Event = db.define('event', {
})
const Tag = db.define('tag', {
tag: { type: Sequelize.STRING, index: true, unique: true, },
tag: { type: Sequelize.STRING, index: true, unique: true, primaryKey: true },
weigth: { type: Sequelize.INTEGER, defaultValue: 0 },
color: { type: Sequelize.STRING }
})
@@ -43,6 +44,7 @@ const Notification = db.define('notification', {
const Place = db.define('place', {
name: { type: Sequelize.STRING, unique: true, index: true },
weigth: { type: Sequelize.INTEGER, defaultValue: 0 },
address: { type: Sequelize.STRING }
})

View File

@@ -5,7 +5,7 @@ const db = require('../db')
const User = db.define('user', {
email: {
type: Sequelize.STRING,
unique: { msg: 'Email already exists' },
unique: { msg: 'err.register_error' },
index: true,
allowNull: false
},

View File

@@ -0,0 +1,4 @@
p= t('confirm_email')
hr
small #{config.baseurl}

View File

@@ -0,0 +1,18 @@
h3 #{event.title}
p Dove: #{event.place.name} - #{event.place.address}
p Quando: #{datetime(event.start_datetime)}
br
if event.image_path
<img style="width: 100%" src="#{config.apiurl}/uploads/#{event.image_path}" />
p #{event.description}
each tag in event.tags
span ##{tag.tag}
br
<a href="#{config.baseurl}/event/#{event.id}">#{config.baseurl}/event/#{event.id}</a>
hr
if to_confirm
p Puoi confermare questo evento <a href="#{config.baseurl}/admin/confirm/#{event.id}">qui</a>
else
p Puoi eliminare queste notifiche <a href="#{config.baseurl}/del_notification/#{notification.remove_code}">qui</a>
<a href="#{config.baseurl}">#{config.title} - #{config.description}</a>

View File

@@ -0,0 +1 @@
= `[${config.title}] ${event.title} @${event.place.name} ${datetime(event.start_datetime)}`

8
server/emails/mail.css Normal file
View File

@@ -0,0 +1,8 @@
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid #555;
}

View File

@@ -0,0 +1,3 @@
p= t('recover_email')
<a href="#{config.baseurl}/recover/#{user.recover_code}">#{t('press here')}</a>

View File

@@ -0,0 +1 @@
= `[Gancio] Richiesta password recovery`

View File

@@ -0,0 +1,6 @@
p= t('registration_email')
hr
small #{config.title} / #{config.description}
br
small #{config.baseurl}

View File

@@ -0,0 +1 @@
= `[Gancio] Richiesta registrazione`

View File

@@ -7,11 +7,14 @@ const path = require('path')
const { Nuxt, Builder } = require('nuxt')
const app = express()
const cors = require('cors')
const notifier = require('./notifier')
const corsConfig = {
allowedHeaders: ['Authorization'],
exposeHeaders: ['Authorization']
}
// Import and Set Nuxt.js options
const config = require('../nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
@@ -47,3 +50,4 @@ async function start() {
})
}
start()
notifier.startLoop(20)

View File

@@ -21,6 +21,7 @@ async function sendNotification (notification, event, eventNotification) {
if (settings.mastodon_auth.instance && settings.mastodon_auth.access_token) {
const b = bot.post(settings.mastodon_auth, event).then(b => {
event.activitypub_id = b.data.id
// event.activitypub_ids.push(b.data.id)
return event.save()
})
promises.push(b)
@@ -29,7 +30,8 @@ async function sendNotification (notification, event, eventNotification) {
return Promise.all(promises)
}
async function loop () {
async function notify() {
console.error('dentro il loop di notify')
settings = await settingsController.settings()
// get all event notification in queue
const eventNotifications = await EventNotification.findAll({ where: { status: 'new' } })
@@ -51,5 +53,14 @@ async function loop () {
return Promise.all(promises)
}
setInterval(loop, 260000)
loop()
let interval
function startLoop(seconds) {
console.error('starting notifier loop')
interval = setInterval(notify, seconds*1000)
}
function stopLoop() {
stopInterval(interval)
}
module.exports = { startLoop, stopLoop }