Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avatar ipfs support #2271

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion packages/providers/src.ts/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,15 @@ export class Resolver implements EnsResolver {
const metadata = await fetchJson(metadataUrl);

// Pull the image URL out
if (!metadata || typeof(metadata.image) !== "string" || !metadata.image.match(/^(https:\/\/|data:)/i)) {
if (!metadata || typeof(metadata.image) !== "string" || !metadata.image.match(/^(https:\/\/|ipfs:\/\/|data:)/i)) {
return null;
}

// If image URL is IPFS transform to HTTP URL
if(metadata.image.match(/^ipfs:\/\//i)){
metadata.image = metadata.image.replace("ipfs://", "https://gateway.ipfs.io/ipfs/");
}

linkage.push({ type: "metadata", content: JSON.stringify(metadata) });
linkage.push({ type: "url", content: metadata.image });

Expand Down
4 changes: 4 additions & 0 deletions packages/web/src.ts/browser-geturl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export async function getUrl(href: string, options?: Options): Promise<GetUrlRes
request.referrer = "client"; // no-referrer, *client
};

if(href.startsWith("ipfs")){
href = href.replace("ipfs://", "https://gateway.ipfs.io/ipfs/");
}

const response = await fetch(href, request);
const body = await response.arrayBuffer();

Expand Down
6 changes: 6 additions & 0 deletions packages/web/src.ts/geturl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ export async function getUrl(href: string, options?: Options): Promise<GetUrlRes
case "https:":
req = https.request(request);
break;
case "ipfs:":
request.protocol = "https:";
request.hostname = "gateway.ipfs.io";
request.path = "/ipfs/" + request.path
req = https.request(request);
break;
default:
/* istanbul ignore next */
logger.throwError(`unsupported protocol ${ url.protocol }`, Logger.errors.UNSUPPORTED_OPERATION, {
Expand Down