Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Shaarli #7

Open
sebw opened this issue Dec 18, 2022 · 7 comments
Open

Support for Shaarli #7

sebw opened this issue Dec 18, 2022 · 7 comments
Labels
bookmark manager (New) bookmark management service enhancement New feature or request

Comments

@sebw
Copy link

sebw commented Dec 18, 2022

Hey there!

Love this extension! Somehow Linkding still has a couple of issues that doesn't make it production ready for me.

I've use Shaarli for years and I would love a similar extension compatible with it.

I've looked at your code (even though I'm not versed in building browser extensions) and it looks like it would be fairly simple to transpose API calls from Linkding to Shaarli API calls.

Only difference is around auth, Shaarli works on a JWT token: https://github.com/shaarli/api-documentation/blob/master/api-authentication.md

API call for search is fairly classic: https://bookmark.example.com/api/v1/links?searchterm=linux&limit=10

Output:

[
	{
		"id": 4956,
		"url": "https:\/\/addons.mozilla.org\/en-GB\/firefox\/addon\/blah\/",
		"shorturl": "PJJIcg",
		"title": "the title",
		"description": "the description",
		"tags": [
			"extension",
			"firefox"
		],
		"private": false,
		"created": "2022-12-18T22:13:45+01:00",
		"updated": "2022-12-18T22:14:00+01:00"
	}
]

I can spin up a Shaarli instance if needed.

@Fivefold
Copy link
Owner

Hey @sebw!

A few thoughts:

  1. Yeah, looks like most of the work would probably be on the configuration side (user UI for choosing linkding or Shaarli API and configuring that).

  2. This is likely not relevant to you personally but would probably mean the extension should be renamed to bookmark-injector or similar down the line.

  3. Of course the injected results would still be styled like linkding, but theming support is not essential and not something I'm willing to tackle for now.

Is this a feature request only or do you intend to make a PR? In case of the latter I would ask you to wait until the next release. I'm in the process of changing the extension to support manifest v3 and that will include changes in a lot of files.

@Fivefold Fivefold added the enhancement New feature or request label Dec 19, 2022
@sebw
Copy link
Author

sebw commented Dec 19, 2022

Hey @Fivefold

  1. one extension covering multiple bookmarking services would be even better!
  2. agree bookmark-injector would make sense
  3. I like the theme as it is!
  4. as much as I'd love to help out, I have never built an extension before and never wrote anything in node but I can definitely test, document or translate stuff! I actually gave a shot to building the extension, but the resulting ZIP wouldn't load (firefox reporting it corrupted, but can still install in debug mode, but quickly fail at the configuration step... I see the testConnection and get a 200 but get an error still).

@Fivefold
Copy link
Owner

Maybe you can write and test a JavaScript function for encoding/generation of the JWT token as shown for PHP at the shaarli docs https://github.com/shaarli/api-documentation/blob/master/api-authentication.md#php
You can do this completely outside of the extension context.

This would take some of the work off me. It will still most likely take weeks until I can actually get to implement it though.

@sebw
Copy link
Author

sebw commented Dec 19, 2022

Here's a working example using jsonwebtoken library.

let jwt = require('jsonwebtoken');
let now = Math.floor(Date.now() / 1000)

const shaarli_api_secret = 'shaarli-api-secret';
const payload = {
  "iat": now
};

let token = jwt.sign(payload, shaarli_api_secret, { algorithm: 'HS512'});

console.log(token)

@Fivefold
Copy link
Owner

Thank you very much, @sebw! Looks good and easy.

Unfortunately I just found out using node modules in browser extensions requires bundling them with the extension. I'm using rollup as a bundler, mostly because I started from the code of the official linkding extension and it seemed to do the job well. I'm very inexperienced with rollup. It can probably bundle node modules too but it would likely take a lot of time for me to set it up just for encoding the JWT token. I might take a shot at it nontheless.

Ideally, I'm looking for a vanilla JavaScript solution, although I'm not sure if JavaScript supports base64 encoding or sha512 hashing out of the box or how much trouble it would be to implement them.

If you do know rollup that would be even better and cleaner though.

@gingerbeardman
Copy link

Just checking out the project and though I might be of help

@Fivefold
Copy link
Owner

Thank you @gingerbeardman, this looks good! I wasn't aware of the subtlecrypto API. Will try it out the next time I take a shot at this.

In the meantime I tried to get rollup to bundle node modules with the help of ChatGPT but even then I was unable to get the bundling working properly. Apparently it should be enough to add preferBuiltins: false to the resolve Plugin in rollup.js.

resolve({ browser: true }),

resolve({ browser: true }),

The resolve plugin itself is from @rollup/plugin-node-resolve and is specifically there to bundle node modules. Unfortunately I still got ReferenceErrors when trying to access stuff from imported node modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bookmark manager (New) bookmark management service enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants