From 37d6b7f1e27fbc407f9206d7c204554e963d3fc4 Mon Sep 17 00:00:00 2001 From: Andre Alves Garzia Date: Wed, 11 Mar 2020 10:06:46 +0000 Subject: [PATCH] bugfixes --- ssb-custom-uri.js | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/ssb-custom-uri.js b/ssb-custom-uri.js index 39f9f79..c430ca1 100644 --- a/ssb-custom-uri.js +++ b/ssb-custom-uri.js @@ -16,6 +16,18 @@ let ssbCustomUri = { setCustomProtocolSchema: (schema) => { ssbCustomUri.protocolSchema = schema }, + removeProtocolSchemaFromLink: (link) => { + // remove // if present, some browsers add it automatically (I'm looking at you Firefox) + if (link.indexOf("//") !== -1) { + link = link.replace("//", "") + } + + // remove `ssb:` if present. + if (link.slice(0, ssbCustomUri.protocolSchema.length + 1) === `${ssbCustomUri.protocolSchema}:`) { + link = link.slice(ssbCustomUri.protocolSchema.length + 1) + } + return link + }, fromSigilLink: (sigilLinkString) => { let sigil = sigilLinkString[0] let prefix @@ -40,19 +52,16 @@ let ssbCustomUri = { return `${ssbCustomUri.protocolSchema}:${prefix}/${format}/${encodeURIComponent(hash)}` }, - toSigilLink: (uriLinkString) => { - // remove `ssb:` if present. - if (uriLinkString.slice(0, ssbCustomUri.protocolSchema.length + 1) === `${ssbCustomUri.protocolSchema}:`) { - uriLinkString = uriLinkString.slice(4) - } + toSigilLink: (link) => { + link = ssbCustomUri.removeProtocolSchemaFromLink(link) - let prefix = uriLinkString.slice(0, uriLinkString.indexOf("/")) - uriLinkString = uriLinkString.slice(uriLinkString.indexOf("/") + 1) // remove prefix. + let prefix = link.slice(0, link.indexOf("/")) + link = link.slice(link.indexOf("/") + 1) // remove prefix. - let format = uriLinkString.slice(0, uriLinkString.indexOf("/")) - uriLinkString = uriLinkString.slice(uriLinkString.indexOf("/") + 1) // remove format. + let format = link.slice(0, link.indexOf("/")) + link = link.slice(link.indexOf("/") + 1) // remove format. - let hash = decodeURIComponent(uriLinkString) + let hash = decodeURIComponent(link) let sigil; @@ -88,10 +97,8 @@ let ssbCustomUri = { return `${ssbCustomUri.protocolSchema}:invite/${type}/${invite}/${feed}` }, peerInviteFromLink: (link) => { - // remove `ssb:` if present. - if (link.slice(0, ssbCustomUri.protocolSchema.length + 1) === `${ssbCustomUri.protocolSchema}:`) { - link = link.slice(4) - } + link = ssbCustomUri.removeProtocolSchemaFromLink(link) + let urlKind = link.slice(0, link.indexOf("/")) if (urlKind !== "invite") { @@ -135,10 +142,8 @@ let ssbCustomUri = { return `${ssbCustomUri.protocolSchema}:invite/${type}/${host}/${port}/${invite}/${feed}` }, pubInviteFromLink: (link) => { - // remove `ssb:` if present. - if (link.slice(0, ssbCustomUri.protocolSchema.length + 1) === `${ssbCustomUri.protocolSchema}:`) { - link = link.slice(4) - } + link = ssbCustomUri.removeProtocolSchemaFromLink(link) + let urlKind = link.slice(0, link.indexOf("/")) if (urlKind !== "invite") { @@ -173,4 +178,8 @@ let ssbCustomUri = { } } -export default ssbCustomUri \ No newline at end of file +if (window) { + window.ssbCustomUri = ssbCustomUri +} + +export default ssbCustomUri -- 2.45.2