8000 fix: hash parsing from IPFS url by eric-zero-dev · Pull Request #492 · zer0-os/zNS-dapp · GitHub
[go: up one dir, main page]

Skip to content
8000
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/lib/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { DEFAULT_IPFS_GATEWAY } from 'constants/ipfs';

/**
* Pulls the IPFS hash from an IPFS url
* Note: this will currently not handle nested IPFS content, i.e. ipfs.io/ipfs/[hash]/content
* @param url IPFS url to get hash from
* @returns IPFS hash from url
*/
export const getHashFromIPFSUrl = (url: string) => {
const hashIndex = url.lastIndexOf('/') + 1;
return url.slice(hashIndex);
const regex = /Qm[a-zA-Z0-9/]*/;

if (regex.test(url)) {
const matches = url.match(regex) as string[];
return matches[0];
}

return '';
};

export const getWebIPFSUrlFromHash = (hash: string) => {
Expand Down
0