sebbo2002 / ical-generator

ical-generator is a small piece of code which generates ical calendar files
MIT License
749 stars 162 forks source link

Setting custom x attribute #195

Closed shriharip closed 4 years ago

shriharip commented 4 years ago

Sorry, if this is not appropriate.

I am trying to specify the X attribute and passing in the values. But the generated file does not contain the value.

This is my event

cal.createEvent({
                    start: start,
                    end: end,
                    timestamp: moment(),
                    summary: summary,
                    htmlDescription: htmldesc,
                    location: location,
                    x: { "X-IMAGE;FMTTYPE": `${media}` } // I also tried x:  { "X-IMAGE;FMTTYPE=image/jpeg": `${media}` }

                });

I get the following output

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//MyCompany ApS//events-ical//DA
NAME: ACME Events
X-WR-CALNAME:ACME Events
TIMEZONE-ID:Europe/Copenhagen
X-WR-TIMEZONE:Europe/Copenhagen
BEGIN:VEVENT
UID:ib8z@acme.dk
SEQUENCE:0
DTSTAMP:20200702T113639Z
DTSTART:20200702T073000Z
DTEND:20200702T140000Z
SUMMARY:LANDSBYHØJSKOLE UDEGRUPPEN \"Cirkus for børn og voksne\" læs mere.
 ..
LOCATION:torsdag på friskolen\, Vestermøllevej\, Fjaltring
X-ALT-DESC;FMTTYPE=text/html:torsdag 2.+fredag 3. +lørdag 4.juli 9.30-16.0
 0 (pause 12.15-14.00\, hvor medbragt madpakke spises. Der vil være voksen 
 til stede). Voksne og børn udvikler numrene i fællesskab\, ud fra børnenes
  behov\, interesser og medbragte talenter.Ambitionen for aktiviteterne er\
 , at alle får en spændende\, sjov og tilpas udfordrende oplevelse\, and more
END:VEVENT

What is that I am missing? Thanks .

sebbo2002 commented 4 years ago

Can you provide a self containing example? If I do this, it works quite well:

const ical = require('ical-generator');
const cal = ical();
cal.createEvent({
    start: new Date(),
    end: new Date(),
    timestamp: new Date(),
    summary: 'summary',
    htmlDescription: 'htmldesc',
    location: 'location',
    x: {
        "X-IMAGE;FMTTYPE": "foo"
    }
});

console.log(cal.toString());
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//sebbo.net//ical-generator//EN
BEGIN:VEVENT
UID:3tll@undefined
SEQUENCE:0
DTSTAMP:20200702T182845Z
DTSTART:20200702T182845Z
DTEND:20200702T182845Z
SUMMARY:summary
LOCATION:location
X-ALT-DESC;FMTTYPE=text/html:htmldesc
X-IMAGE;FMTTYPE:foo
END:VEVENT
END:VCALENDAR
shriharip commented 4 years ago

Thanks for the response.

It is very strange. I tried with one of the many JSON data that I loop over and using default values . You can find the code here https://runkit.com/embed/v0694gs3ubnp And as you mention it does get the value.

However, if you run this https://europe-west1-minlandsby-v2.cloudfunctions.net/getData/events/village/2622170

Then I am not getting the output.

The only thing that is different in my code is I use

 const eventdata = cal.createEvent({
                    start: start,
                    end: end,
                    timestamp: moment(),
                    summary: summary,
                    // organizer: organizer,
                    htmlDescription: htmldesc,
                    location: location,
                    x: { "X-IMAGE;FMTTYPE": `${media}` } 
                });
                events.push(eventdata);
            });

            cal['events'] = events;
            cal.serve(res);

So is cal.serve causing issue compared to toString()?

Also, is the FMTYPE =image/jpeg not necessary?

I am now moving this application from php to javascript. The php one creates something like

BEGIN:VEVENT
ATTACH;FMTTYPE=image/jpeg:http://api.app.minlandsby.dk/images/dynamic/even
ts/7ca679ea-a99e-ea11-811d-0a000fa90c6f.JPG?width=750&version=63726023121
7161685
CATEGORIES:Gesten
CREATED:20200714T073000Z
DESCRIPTION:Krolf hver tirsdag kl. 9.30 - 11.30.
DTEND:20200714T093000Z
DTSTAMP:20200701T141840Z
DTSTART:20200714T073000Z
LOCATION:Kvisten\, Hovedgaden 2\, 1.\, 6621 Gesten
ORGANIZER;CN=Hanna Mailand Nielsen:mailto:knve@profibermail.dk
SEQUENCE:0
SUMMARY:Krolf
TEL:29897543
UID:7ca679ea-a99e-ea11-811d-0a000fa90c6f
END:VEVENT

The second line FMTTYPE has image type jpeg.

and the https://icalendar.org/New-Properties-for-iCalendar-RFC-7986/5-10-image-property.html also points to image type. So the question is do we have to type that in for FMTTYPE.

However, I think the code(ical-generator) capitalizes the key in x attribute, so I am not sure if we can retain =image/jpeg in lowercase. Could you please clarify. Thanks again.

sebbo2002 commented 4 years ago

Okay, you have a lot of questions here, but some of them I don't think are for this repository. But first things first.

It is very strange. I tried with one of the many JSON data that I loop over and using default values . You can find the code here https://runkit.com/embed/v0694gs3ubnp And as you mention it does get the value.

However, if you run this https://europe-west1-minlandsby-v2.cloudfunctions.net/getData/events/village/2622170

Then I am not getting the output.

As you have found out yourself, this library works in the simplified example. Why it doesn't work in your production setup I can't tell you and as long as you can't give a simple example that shows a bug or something like that I can't help you with your problem.

cal['events'] = events;

Where did you come up with that line? It doesn't work that way. createEvent() already adds the event to the calendar itself.

So is cal.serve causing issue compared to toString()?

No, toString() and serve() both use _generate() and thus produce the same output when the input is the same.

shriharip commented 4 years ago

oh ok. Then, I will remove the cal['events'] line. And I will try to work on the issue. For now will use the serve function. Thanks again for the response and will get back if I am able to find the issue.