[TW5] Is it possible to write a plugin that integrates with Pinboard's API?

156 views
Skip to first unread message

Daniel Metcalfe

unread,
Aug 17, 2016, 11:06:03 AM8/17/16
to tiddl...@googlegroups.com
I use both Pinboard & TiddlyWiki as places to store knowledge. Pinboard is a simple bookmarking service that stores URLs with tags and optional associated plain text notes.

I've decided to write a plugin that will read the tags of my tiddlers and call the Pinboard API to enrich them with links and text from bookmarks in Pinboard that have the same tags. However my web development knowledge is not that good and I've quickly run into problems. Here's what I've tried so far:

  • Using Single-file TiddlyWiki
    • Javascript Macro
      • Call API using XMLHttpRequest().
        • CORS error. Pinboard does not return Access-Control-Allow-Origin headers.
      • Retrieve Pinboard feed using JSONP.
        • Script tag is disabled in TiddlyWiki so cannot use JSONP.
  • Using Node Server TiddlyWiki
    • Javascript Macro
      • Call API using XMLHttpRequest().
        • XMLHttpRequest() is not defined error. Provided by browser.

At this point I decided I did not know enough and should seek advice. I could probably just modify some JS in the TiddlyWiki core to intervene as the tiddler is loaded but then the functionality will not be easily reusable. I could perhaps write a Chrome extension that can bypass CORS restrictions but that limits reusability too.

I'd really appreciate any pointers or advice, is there a way to do this using TiddlyWiki's plugin mechanism?

PMario

unread,
Aug 17, 2016, 3:27:39 PM8/17/16
to TiddlyWiki
Hi Daniel,

If you try to write from a local file based Tiddlywiki to an online API you'll have no luck. Browser vendors consider this behaviour insecure and block it.

JSONP .. search for "jsonp security" and you probably don't want to use it.

If you did access the piboard api from a local file it may explain the  CORS, errors too.

Can you describe your setup a bit closer?

-mario

Daniel Metcalfe

unread,
Aug 18, 2016, 3:53:15 AM8/18/16
to tiddl...@googlegroups.com
If I remember correctly I tried it using both a local file and the same wiki hosted on TiddlySpot. I believe the CORS restrictions apply equally to both local files and hosted files, because either way the domain is different to pinboard.in.

I understand that what I've tried doesn't work for good reasons so I'm just wondering if there are any workarounds or alternative approaches. Basically I just like to know if it's even possible!

Cheers,
Dan

Danielo Rodríguez

unread,
Aug 18, 2016, 4:39:00 AM8/18/16
to TiddlyWiki
All you need is a backend that is not restricted to CORS (any server code should work) and an endpoint that allows your wikis to fetch data allowing CORS to your domains.

So, in summary (and as example) you could need

  1. Node.js app that gets the information you need and saves it into a database.
  2. The same node.js app can expose an endpoint with CORS enabled

If that is a problem to you (don't want or can't get a node app running) you can try with IFTT maker channel:

In fact, this may be the preferred options because IFTT also has a pinboard channel:


If you get something cool and working, don't hesitate to share it!

PMario

unread,
Aug 18, 2016, 5:07:40 AM8/18/16
to TiddlyWiki
In its first sentence at pinnboard.in the site states:

quote
Pinboard is a fast, no-nonsense bookmarking site for people who value privacy and speed.

So if you use ifttt you notify everyone, what you do. So for me that's not really the preferred option, if I care about privacy. ... There is a second problem with the https settings for the site. I did notify their support.

have fun!
mario

Daniel Metcalfe

unread,
Aug 18, 2016, 1:40:54 PM8/18/16
to tiddl...@googlegroups.com
Thanks Danielo, that's provided me some extra clarity on what I thought I might have to do. I could run TiddlyWiki as a node server and change some of the core JS code that is not subject to CORS restrictions.

My main concern is if there is a way to do it using TiddlyWiki plugin mechanism though? From the examples I've seen things you can add via plugins just run within the browser once you've loaded a TiddlyWiki.

I'd like it to be easily shareable like you suggested, if I have to modify TiddlyWiki core code then it is not very shareable, people will have to deploy my fork of the repo.

Danielo Rodríguez

unread,
Aug 18, 2016, 1:47:10 PM8/18/16
to TiddlyWiki


El jueves, 18 de agosto de 2016, 11:07:40 (UTC+2), PMario escribió:


So if you use ifttt you notify everyone, what you do. 

Exactly why? Can't you just do it in a private-way?

Danielo Rodríguez

unread,
Aug 18, 2016, 1:49:25 PM8/18/16
to TiddlyWiki


El jueves, 18 de agosto de 2016, 19:40:54 (UTC+2), Daniel Metcalfe escribió:
Thanks Danielo,
You're welcome
 

My main concern is if there is a way to do it using TiddlyWiki plugin mechanism though? From the examples I've seen things you can add via plugins just run within the browser once you've loaded a TiddlyWiki.

That is not exactly true. If you plan to run your TW in node, part of your plugin can run just on the browser and part of your plugin can run just on node. That way you can create some client-server architecture within your plugin. The only restriction for the people wanting to use it is that they would have to run your plugin in a node TW.
 

I'd like it to be easily shareable like you suggested, if I have to modify TiddlyWiki core code then it is not very shareable, people will have to deploy my fork of the repo.

As I said, TW has the ability to run code on the browser, the server or both. The filesystem adaptor is an example of it. 

Daniel Metcalfe

unread,
Aug 18, 2016, 6:52:40 PM8/18/16
to tiddl...@googlegroups.com
Thank you for pointing out the filesystem adaptor Danielo, I've had a look at it and can see that in the TiddlyWiki core code it checks for modules of type 'syncadaptor' and uses the exported methods there, so the JS in filesystem is executed server side from within the core.

I can see also that code in my JS macro is executed once at startup in a node context without failures, but then when calling as a macro from the TiddlyWiki in the browser the same JS code fails due to node-specific things like 'require' (as well as CORS restrictions on the request to Pinboard).

I'm unsure as to how I should write my plugin so that my JS code can be executed in a node context rather than a browser context. I'm looking at the other module types wondering if perhaps one of those will allow my plugin modules to be triggered from the open TiddlyWiki in the browser but still executed server side where they are not subject to CORS.

Thank you for your help so far,
Dan

PMario

unread,
Aug 19, 2016, 6:09:37 AM8/19/16
to TiddlyWiki

As soon, as you use a 3rd party service that is server based, you notify them, by accessing their service. ... That's the same reason, why all the "social buttons eg: twitter, google, facebook, ..." are a privacy problem and add blockers block them. As soon as you load the page, and the button is shown, it's code sends a message to their owners, that you visited the site, where the button is included.

-m
Reply all
Reply to author
Forward
0 new messages