do not use end time when not used, fix #233

This commit is contained in:
lesion 2023-02-04 10:42:06 +01:00
parent 9d17770c3d
commit a36c8c29cb
No known key found for this signature in database
GPG key ID: 352918250B012177
2 changed files with 12 additions and 5 deletions

View file

@ -81,14 +81,13 @@ const exportController = {
ics (_req, res, events, alarms = []) {
const settings = res.locals.settings
const eventsMap = events.map(e => {
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('-').map(Number)
const end = tmpEnd.utc(true).format('YYYY-M-D-H-m').split('-').map(Number)
return {
const ret = {
uid: `${e.id}@${settings.hostname}`,
start,
end,
title: `[${settings.title}] ${e.title}`,
description: htmlToText(e.description),
htmlContent: e.description,
@ -98,6 +97,14 @@ const exportController = {
categories: e.tags.map(t => t.tag),
alarms
}
if (e.end_datetime) {
const tmpEnd = moment.unix(e.end_datetime)
const end = tmpEnd.utc(true).format('YYYY-M-D-H-m').split('-').map(Number)
ret.end = end
}
return ret
})
res.type('text/calendar; charset=UTF-8')
ics.createEvents(eventsMap, (err, value) => {

View file

@ -69,7 +69,7 @@ module.exports = (sequelize, DataTypes) => {
url: `${config.baseurl}/event/${this.slug || this.id}`,
type: 'Event',
startTime: dayjs.unix(this.start_datetime).tz().locale(locale).format(),
endTime: this.end_datetime ? dayjs.unix(this.end_datetime).tz().locale(locale).format() : null,
...( this.end_datetime ? { endTime : dayjs.unix(this.end_datetime).tz().locale(locale).format() } : {} ),
location: {
name: this.place.name,
address: this.place.address,