Access Files for a Draw.io Plugin

Hallo Takuya,

First: Hello everybody
Second: Takuya, thanks for this great App

Now to my question:

To make Sketches I use Draw.io and I want to integrate it with Inkdrop over a Plugin.
As far as I see it, there is almost everything already in place.

  • I can insert an Draw.io SVG into a note and it displays nicely
  • I can download the SVG and edit it again. So it is stored correctly

My functionality for a plugin would be:

My question is now, how to access the svg file?

When I fetch the file from the database:

inkdrop.main.dataStore.getLocalDB().files.get(‘file:feijRJFs7’)

there is no _attachments:index:data

3 Likes

Hi Andreas,

I’m glad that you are trying to create a plugin!
To fetch the attachment in the docs, just add attachments: true option to the method call like so:

inkdrop.main.dataStore.getLocalDB().files.get('file:feijRJFs7', { attachments: true })

Please refer to PouchDB’s documentation for more detail.

When you save the SVG file, do not overwrite the existing file with put method.
Instead, create a new file document and delete the old one.
That’s because the app basically assumes that the file will never be changed by design at the moment.
The mobile app caches image files in local and won’t update even if you overwritten them.

Another option for this issue would be to support drawio codeblock like math plugin.
Let’s say that you have the following codeblock in a note:

```drawio
<svg>...</svg>
```

And your plugin renders it as a SVG image in preview.
That allows your plugin to work without handling file documents.

Hope that helps!

1 Like

Hi Andreas,

great idea. Do you plan to publish the plugin as open source?

Regards

Mike

1 Like

thanks for the input.
A first version is now available: https://my.inkdrop.app/plugins/drawio

On each save a new file is created and replaced in the note.

2 Likes

Great job, Andreas!
It would be nicer to remove old files with db.files.remove(id):

Let me know when it’s ready to use officially.

Hi,

I looked into deleting old diagrams.
The problem I see, is with revisions. When I delete the file on save, I cant go back to older revision.

How is this done for the deletion of images?

You are right. It is not possible to restore deleted diagrams. So you can keep them if you would rewind the edits.