Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function validIpnsPath (path, dnsLink) {
if (IsIpfs.ipnsPath(path)) {
// we may have false-positives here, so we do additional checks below
const ipnsRoot = path.match(/^\/ipns\/([^/]+)/)[1]
// console.log('==> IPNS root', ipnsRoot)
// first check if root is a regular CID
if (IsIpfs.cid(ipnsRoot)) {
// console.log('==> IPNS is a valid CID', ipnsRoot)
return true
}
// then see if there is an DNSLink entry for 'ipnsRoot' hostname
// TODO: use dnslink cache only
if (dnsLink.readAndCacheDnslink(ipnsRoot)) {
// console.log('==> IPNS for FQDN with valid dnslink: ', ipnsRoot)
return true
}
}
return false
}
if (domain.startsWith('_dnslink.')) {
// The supplied domain contains a _dnslink component
// Check the non-_dnslink domain
dnslinkRecord = await resolveDnslink(domain.replace('_dnslink.', ''))
} else {
// Check the _dnslink subdomain
const _dnslinkDomain = `_dnslink.${domain}`
// If this throws then we propagate the error
dnslinkRecord = await resolveDnslink(_dnslinkDomain)
}
}
const result = dnslinkRecord.replace('dnslink=', '')
const domainOrCID = result.split('/')[2]
const isIPFSCID = isIPFS.cid(domainOrCID)
if (isIPFSCID || !depth) {
return result
}
return recursiveResolveDnslink(domainOrCID, depth - 1)
}
.then((out) => {
b58Hash = out.split(' ')[1]
expect(isIpfs.cid(b58Hash)).to.be.true()
b64Hash = new CID(b58Hash).toV1().toBaseEncodedString('base64')
return ipfs(`resolve /ipfs/${b58Hash} --cid-base=base64`)
})
.then((out) => {
module.exports.evaluate = (ctx, cmd, cmdArgs) => {
debug(cmd, cmdArgs)
cmd = cmd || ''
if (isIpfs.cid(cmd) || isIpfs.cid(cmd.split('/')[0])) {
cmdArgs = [`/ipfs/${cmd}`]
cmd = 'cd'
} else if (isIpfs.path(cmd)) {
cmdArgs = [cmd]
cmd = 'cd'
}
if (!cmd) return
if (!Commands[cmd]) throw new Error(`${cmd}: command not found`)
return Commands[cmd](ctx, ...cmdArgs)
}
get (path) {
let cid
if (CID.isCID(path)) {
cid = path
path = ''
} else {
const { cidOrFqdn, rest } = parsePath(path)
if (!isIpfs.cid(cidOrFqdn)) {
throw new Error(`invalid cid ${cidOrFqdn}`)
}
cid = new CID(cidOrFqdn)
path = rest ? rest.slice(1) : ''
}
debug('get for', cid.toBaseEncodedString(), path)
return new Promise((resolve, reject) => {
this._ipld.get(cid, path, (err, res) => {
if (err) return reject(err)
resolve(res.value)
})
})
}
onBrowse (evt) {
evt.preventDefault()
if (this.isValid) {
let path = this.path
if (isIPFS.cid(path)) {
path = `/ipfs/${path}`
}
this.props.onBrowse(path)
this.setState({ path: '' })
}
}
export default function removePinFromIPFS(pinataApiKey, pinataSecretApiKey, ipfsPinHash) {
validateApiKeys(pinataApiKey, pinataSecretApiKey);
if (!ipfsPinHash) {
throw new Error('ipfsPinHash value is required for removing a pin from Pinata');
}
if (!isIPFS.cid(ipfsPinHash)) {
throw new Error(`${ipfsPinHash} is an invalid IPFS CID`);
}
const endpoint = `${baseUrl}/pinning/removePinFromIPFS`;
const body = {
ipfs_pin_hash: ipfsPinHash
};
return new Promise((resolve, reject) => {
axios.post(
endpoint,
body,
{
withCredentials: true,
headers: {
'pinata_api_key': pinataApiKey,