Created
October 20, 2015 20:53
-
-
Save giodamelio/4185781d2a36a600555e to your computer and use it in GitHub Desktop.
A simple Terminator plugin to allow quick opening of IPFS/IPNS hashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urlparse import urljoin | |
import terminatorlib.plugin as plugin | |
NAME = "IPFSURLHandler" | |
# Make terminator recognize plugin | |
AVAILABLE = [NAME] | |
available = AVAILABLE # For old versions of terminator | |
SETTINGS = { | |
"gatewayURL": "https://ipfs.io/", | |
} | |
class IPFSURLHandler(plugin.URLHandler): | |
"""Open IPFS and IPNS urls on a gateway""" | |
capabilities = ["url_handler"] | |
handler_name = "ipfs_handler" | |
match = "(/ip[fn]s/)?Qm[a-zA-Z0-9]{44}" | |
nameopen = "Open on Gateway" | |
namecopy = "Copy Gateway URL" | |
def callback(self, url): | |
if url.startswith("/ipfs/"): | |
return urljoin(SETTINGS["gatewayURL"], url) | |
elif url.startswith("/ipns/"): | |
return urljoin(SETTINGS["gatewayURL"], url) | |
else: | |
return urljoin(SETTINGS["gatewayURL"], "/ipfs/" + url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment