Writing to a file (for .ics export)

Background

I’m writing a plugin that takes all blocks with a scheduled or deadline time and writes them to an ICS file (iCalendar/Google Calendar compatible events format). (GitHub for the interested)

Currently, I have a proof of concept for writing the raw text of what would be an .ics file into the developer console. I’m able to copy this into a .ics file and successfully view events in the calendar.

What I’d like to accomplish

I’d like to have the ICS file automatically created or automatically imported into my calendar. The easiest way I see to accomplish this is to write the ICS string into a file or directory on a webserver that my calendar program can point to.

My first thought was to use fs, but because plugins are run from Logseq we don’t have access to the filesystem API directly. I get this when trying to write a file:

TypeError: Hc.writeFile is not a function

Is there a way to write to a file with the current plugin API? Is this the correct approach?

Thanks for reading.

Hi, I think you can use this polyfill for saving files purely with the web technology: GitHub - eligrey/FileSaver.js: An HTML5 saveAs() FileSaver implementation

btw I like your plugin idea :smiley:

Hi there, if this ICS file is not too big (>10M or more), currently you can use Logseq.updateSettings to persist this ICS file string :slight_smile:

A sample - logseq-plugin-samples/logseq-awesome-fonts at master · logseq/logseq-plugin-samples · GitHub
API docs - LSPluginUser | @logseq/libs

Sorry I got it wrong. I read your codebase, you want to export a .ics file to the local file system in a background process. Actually, it’s impossible that plugin API to write local files anywhere for security. We planned to provide an storage layer API that could support files manipulation in specific file root (like ~/.logseq/storage/xxx-plugin-id/could-write-any-file-here.ics).

So what do you think?

Hi, I think you can use this polyfill for saving files purely with the web technology: GitHub - eligrey/FileSaver.js: An HTML5 saveAs() FileSaver implementation

@Peng_Xiao This could work as a stop gap solution, but ideally the plugin would write to a file that my calendar program reads from immediately.

btw I like your plugin idea :smiley:

Thanks :smiley:


Actually, it’s impossible that plugin API to write local files anywhere for security. We planned to provide an storage layer API that could support files manipulation in specific file root (like ~/.logseq/storage/xxx-plugin-id/could-write-any-file-here.ics).

@Charlie This seems like a sensible approach as long as that storage directory is predictable (if it uses the plugin ID, I don’t see why it wouldn’t be).

I see that part of the future work for the Plugin API includes “Page related apis ( create page, delete page, change block to page, update page properties)”. If this is still planned, I could write a .ics file to a newly created page in my Logseq pages directory (it doesn’t need to be a particular place on the filesystem). Is this still a planned feature?

Either way, I would find a storage API super useful. Is there a way I can help build this?

… (if it uses the plugin ID, I don’t see why it wouldn’t be).

Hi, @lomz The purpose of this is to isolate the storage of different plugins for security.

“Page related APIs ( create a page, delete page, change block to a page, update page properties)”. If this is still planned …

Yes, it’s still in the plan. But Page is conceptual that just a page, maybe not a real file, although it corresponds to a file (.md or .org) currently. At the same time, the page file suffix can’t be modified. So I’m not sure that will meet your needs.

Either way, I would find a storage API super useful. Is there a way I can help build this?

It would be greatly appreciated! I will open a PR on Github for the storage API feature as soon as possible, you could get involved in discussion or implementation, anything you’re interested in :wink:

I will open a PR on Github for the storage API feature as soon as possible, you could get involved in discussion or implementation, anything you’re interested in :wink:

@Charlie Sounds perfect! Please feel free to request me for review :raised_hands: