Open sebw opened 1 year ago
Hey @sebw!
A few thoughts:
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).
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.
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.
Hey @Fivefold
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.
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)
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.
Just checking out the project and though I might be of help
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.
https://github.com/Fivefold/linkding-injector/blob/a66b0e883d6df9ef37a8290d23a7b20025902507/rollup.config.js#L56
https://github.com/Fivefold/linkding-injector/blob/a66b0e883d6df9ef37a8290d23a7b20025902507/rollup.config.js#L81
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.
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:
I can spin up a Shaarli instance if needed.