[mega] settings, timezone

This commit is contained in:
les
2019-10-20 14:22:55 +02:00
parent 4a03d60667
commit 66aa6a8692
24 changed files with 214 additions and 85 deletions

View File

@@ -1,10 +1,11 @@
const crypto = require('crypto')
const moment = require('moment')
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 Sequelize = require('sequelize')
const exportController = require('./export')
const debug = require('debug')('controller:event')
const eventController = {
@@ -90,6 +91,7 @@ const eventController = {
// TODO retrieve next/prev event also
// select id, start_datetime, title from events where start_datetime > (select start_datetime from events where id=89) order by start_datetime limit 20;
async get (req, res) {
const format = req.params.format || 'json'
const is_admin = req.user && req.user.is_admin
const id = req.params.event_id
const event = await Event.findByPk(id, {
@@ -107,7 +109,11 @@ const eventController = {
})
if (event && (event.is_visible || is_admin)) {
res.json(event)
if (format === 'json') {
res.json(event)
} else if (format === 'ics') {
exportController.ics(req, res, [event])
}
} else {
res.sendStatus(404)
}
@@ -190,13 +196,11 @@ const eventController = {
.month(req.params.month)
.startOf('month')
.startOf('week')
.utc(false)
let end = moment()
.year(req.params.year)
.month(req.params.month)
.endOf('month')
.utc(false)
const shownDays = end.diff(start, 'days')
if (shownDays <= 35) { end = end.add(1, 'week') }
@@ -235,7 +239,7 @@ const eventController = {
if (!recurrent.frequency) { return false }
let cursor = moment(start).startOf('week')
const start_date = moment.unix(e.start_datetime).utc(false)
const start_date = moment.unix(e.start_datetime)
const duration = moment.unix(e.end_datetime).diff(start_date, 's')
const frequency = recurrent.frequency
const days = recurrent.days
@@ -280,7 +284,7 @@ const eventController = {
cursor.day(d - 1)
}
if (cursor.isAfter(dueTo) || cursor.isBefore(start)) { return }
e.start_datetime = cursor.utc(true).unix()
e.start_datetime = cursor.unix()
e.end_datetime = e.start_datetime + duration
events.push(Object.assign({}, e))
})

View File

@@ -1,7 +1,6 @@
const { event: Event, place: Place, tag: Tag } = require('../models')
const { Op } = require('sequelize')
const moment = require('moment')
const config = require('config')
const moment = require('moment-timezone')
const ics = require('ics')
const exportController = {
@@ -36,31 +35,38 @@ const exportController = {
switch (type) {
case 'rss':
case 'feed':
return exportController.feed(res, events.slice(0, 20))
return exportController.feed(req, res, events.slice(0, 20))
case 'ics':
return exportController.ics(res, events)
return exportController.ics(req, res, events)
case 'json':
return res.json(events)
}
},
feed (res, events) {
feed (req, res, events) {
res.type('application/rss+xml; charset=UTF-8')
res.render('feed/rss.pug', { events, config, moment })
res.render('feed/rss.pug', { events, settings: req.settings, moment })
},
ics (res, events) {
ics (req, res, events) {
const eventsMap = events.map(e => {
const tmpStart = moment.unix(e.start_datetime).utc(false)
const tmpEnd = moment.unix(e.end_datetime).utc(false)
const start = [tmpStart.year(), tmpStart.month() + 1, tmpStart.date(), tmpStart.hour(), tmpStart.minute()]
const end = [tmpEnd.year(), tmpEnd.month() + 1, tmpEnd.date(), tmpEnd.hour(), tmpEnd.minute()]
const tmpStart = moment.unix(e.start_datetime)
const tmpEnd = moment.unix(e.end_datetime)
const start = tmpStart.utc(true).format('YYYY-M-D-H-m').split('-')
const end = tmpEnd.utc(true).format('YYYY-M-D-H-m').split('-')
return {
start,
// startOutputType: 'utc',
end,
title: e.title,
// endOutputType: 'utc',
title: `[1${req.settings.title}] ${e.title}`,
description: e.description,
location: e.place.name + ' ' + e.place.address
location: `${e.place.name} - ${e.place.address}`,
url: `${req.settings.baseurl}/event/${e.id}`,
alarms: [{
action: 'display',
trigger: {hours: 1, before: true}
}]
}
})
res.type('text/calendar; charset=UTF-8')

View File

@@ -249,8 +249,10 @@ const userController = {
}
req.body.recover_code = crypto.randomBytes(16).toString('hex')
debug('Register user ', req.body.email)
const user = await User.create(req.body)
try {
debug(`Sending registration email to ${user.email}`)
mail.send(user.email, 'register', { user, config })
mail.send(config.admin_email, 'admin_register', { user, config })
} catch (e) {