raucao / webmarks

remoteStorage-enabled bookmarking app
https://webmarks.5apps.com
Other
76 stars 11 forks source link

Import from other places #66

Open fiatjaf opened 6 years ago

fiatjaf commented 6 years ago

Is there an easy way to import bookmarks from other places?

Or maybe there's a way to inject the data directly on remoteStorage, but what is the format the data is expected to have?

raucao commented 6 years ago

I had something in some branch years ago (iirc it was importing from Delicious), but there's nothing supported in the app right now.

You could easily write an import script for node.js and/or browsers, using rs.js and the bookmarks module. Something like this should be enough (not tested):

import RemoteStorage from 'remotestoragejs';
import RemoteStorage from 'remotestorage-module-bookmarks';

const remoteStorage = new RemoteStorage({modules: [Bookmarks.default]});
remoteStorage.access.claim('bookmarks', 'rw');
remoteStorage.connect('joe@example.com', 'this-could-be-an-oauth-token');

const bookmarks = [];
// Fill up bookmarks with stuff to import;

function importBookmarks () {
  bookmarks.forEach(bookmark => {
    remoteStorage.bookmarks.archive.store({
      title: bookmark.title,
      url: bookmark.url,
      description: bookmark.desc,
      tags: bookmark.tags // array of strings
    })
    .then(() => console.log(`Imported ${bookmark.url}`).
    .catch(err => console.error(`Failed to import ${bookmark.url}:`, err));
  });
});

The store() function will validate the format using the data module JSON Schema, and it would tell you exactly what's wrong or missing. Also, this function would be idempotent (meaning you can run it multiple times with the same result and no additional bookmarks stored), because the bookmarks' ID (and thus document/file name) will automatically be the MD5 hash of the URL.

raucao commented 5 years ago

I definitely want some kind of feature to import bookmarks from popular silos. However, I'm wondering if it belongs in Webmarks itself, or if it should be part of some larger data liberation app/agent.

I guess even if the app wouldn't connect to proprietary APIs, it could at least allow to import from exported-data files from those services.