fwenzel / copy-shorturl

A Firefox extension to quickly create a short URL for the current page and copy it to the clipboard.
https://addons.mozilla.org/addon/copy-shorturl
Apache License 2.0
35 stars 15 forks source link

Kutt self-hosted support #137

Open sasakitz opened 2 years ago

sasakitz commented 2 years ago

I would like to see support for kutt in self-hostd as well as kutt.it.

fwenzel commented 2 years ago

That is probably not too hard, since I assume the API of kutt.it and a self-hosted instance is identical. However, I do not really have a way to test it?

sasakitz commented 2 years ago

Thank you.

I am now using the following bookmarklet to create a shortened URL for my self-hosted kutt.

javascript: (function() {
  fetch("https://HOSTED_DOMAIN/api/v2/links", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-Key": "KUTT_API_KEY"
    },
    body: JSON.stringify({
      target: location.href
    })
  }).then(response => response.json()).then(data => {
    navigator.clipboard.writeText(data.link).then(alert("Copied! " + data.link));
  }).catch(error => {
    navigator.clipboard.writeText(location.href).then(alert("Copied! " + location.href));
  });
})();

I am wondering if it would be possible if the domain of the following fetch point is not fixed to kutt.it but variable. https://github.com/fwenzel/copy-shorturl/blob/f9b791d01fa24581e0c751a65c9ebcabcf464976/src/lib/shortener.js#L80

You can help with testing methods to the extent possible, either by testing them myself or by issuing API keys for self-hosted kutt.

fwenzel commented 2 years ago

Oh thank you this is super helpful. I have a setting for custom shortener domain in there but I think that's less important than the self-hosted domain type.

sasakitz commented 2 years ago

Support for self-hosting may be less important for the majority. However, kutt.it is currently unable to accept new signup and a reverse proxy is required to support SSL for custom domains.

fwenzel commented 2 years ago

Makes sense to me - the request for self-hosting is pretty common from Copy ShortURL users. I think I'll just add a new setting for it.