Added support for data URLs for avatar metadata.
This commit is contained in:
parent
1e1c93effa
commit
b8391b0e61
@ -404,6 +404,8 @@ export class Resolver implements EnsResolver {
|
||||
async getAvatar(): Promise<null | Avatar> {
|
||||
const linkage: Array<{ type: string, content: string }> = [ ];
|
||||
try {
|
||||
// test data for ricmoo.eth
|
||||
//const avatar = "eip155:1/erc721:0x265385c7f4132228A0d54EB1A9e7460b91c0cC68/29233";
|
||||
const avatar = await this.getText("avatar");
|
||||
if (avatar == null) { return null; }
|
||||
|
||||
@ -475,7 +477,7 @@ 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:\/\//i)) {
|
||||
if (!metadata || typeof(metadata.image) !== "string" || !metadata.image.match(/^(https:\/\/|data:)/i)) {
|
||||
return null;
|
||||
}
|
||||
linkage.push({ type: "metadata", content: JSON.stringify(metadata) });
|
||||
|
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
import { encode as base64Encode } from "@ethersproject/base64";
|
||||
import { decode as base64Decode, encode as base64Encode } from "@ethersproject/base64";
|
||||
import { hexlify, isBytesLike } from "@ethersproject/bytes";
|
||||
import { shallowCopy } from "@ethersproject/properties";
|
||||
import { toUtf8Bytes, toUtf8String } from "@ethersproject/strings";
|
||||
@ -150,6 +150,33 @@ export function _fetchData<T = Uint8Array>(connection: string | ConnectionInfo,
|
||||
};
|
||||
}
|
||||
}
|
||||
const reData = new RegExp("^data:([a-z0-9-]+/[a-z0-9-]+);base64,(.*)$", "i");
|
||||
const dataMatch = ((url) ? url.match(reData): null);
|
||||
if (dataMatch) {
|
||||
try {
|
||||
const response = {
|
||||
statusCode: 200,
|
||||
statusMessage: "OK",
|
||||
headers: { "content-type": dataMatch[1] },
|
||||
body: base64Decode(dataMatch[2])
|
||||
};
|
||||
|
||||
let result: T = <T><unknown>response.body;
|
||||
if (processFunc) {
|
||||
result = processFunc(response.body, response);
|
||||
}
|
||||
return Promise.resolve(<T><unknown>result);
|
||||
|
||||
} catch (error) {
|
||||
logger.throwError("processing response error", Logger.errors.SERVER_ERROR, {
|
||||
body: bodyify(dataMatch[1], dataMatch[2]),
|
||||
error: error,
|
||||
requestBody: null,
|
||||
requestMethod: "GET",
|
||||
url: url
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (body) {
|
||||
options.method = "POST";
|
||||
|
Loading…
Reference in New Issue
Block a user