Skip to content

Commit

Permalink
fix: pin URL with hash or query
Browse files Browse the repository at this point in the history
Closes: #567
  • Loading branch information
lidel committed Sep 13, 2018
1 parent 40fd1a7 commit 86760a5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions add-on/src/popup/browser-action/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = (state, emitter) => {

try {
const ipfs = await getIpfsApi()
const currentPath = await resolveToIPFS(ipfs, state.currentTab.url)
const currentPath = await resolveToPinPath(ipfs, state.currentTab.url)
const pinResult = await ipfs.pin.add(currentPath, { recursive: true })
console.log('ipfs.pin.add result', pinResult)
state.isPinned = true
Expand All @@ -90,7 +90,7 @@ module.exports = (state, emitter) => {

try {
const ipfs = await getIpfsApi()
const currentPath = await resolveToIPFS(ipfs, state.currentTab.url)
const currentPath = await resolveToPinPath(ipfs, state.currentTab.url)
const result = await ipfs.pin.rm(currentPath, { recursive: true })
state.isPinned = false
console.log('ipfs.pin.rm result', result)
Expand Down Expand Up @@ -244,7 +244,7 @@ module.exports = (state, emitter) => {
// skip update if there is an ongoing pin or unpin
if (state.isPinning || state.isUnPinning) return
try {
const currentPath = await resolveToIPFS(ipfs, status.currentTab.url)
const currentPath = await resolveToPinPath(ipfs, status.currentTab.url)
const response = await ipfs.pin.ls(currentPath, { quiet: true })
console.log(`positive ipfs.pin.ls for ${currentPath}: ${JSON.stringify(response)}`)
state.isPinned = true
Expand Down Expand Up @@ -273,8 +273,11 @@ async function getIpfsApi () {
return (bg && bg.ipfsCompanion) ? bg.ipfsCompanion.ipfs : null
}

async function resolveToIPFS (ipfs, urlOrPath) {
let path = safeIpfsPath(urlOrPath) // https://github.com/ipfs/ipfs-companion/issues/303
async function resolveToPinPath (ipfs, url) {
// https://github.com/ipfs-shipyard/ipfs-companion/issues/567
url = url.split('#')[0].split('?')[0]
// https://github.com/ipfs/ipfs-companion/issues/303
let path = safeIpfsPath(url)
if (/^\/ipns/.test(path)) {
const response = await ipfs.name.resolve(path, { recursive: true, nocache: false })
// old API returned object, latest one returns string ¯\_(ツ)_/¯
Expand Down

0 comments on commit 86760a5

Please sign in to comment.