Skip to content

Commit

Permalink
Merge pull request #291 from Kunkka0822/feat/integrate-noizd-accumulator
Browse files Browse the repository at this point in the history
Integrate noizd with music-os-accumulator
  • Loading branch information
TimDaub authored Sep 29, 2022
2 parents 30c5b3c + cb07562 commit bd3c46e
Showing 1 changed file with 23 additions and 37 deletions.
60 changes: 23 additions & 37 deletions src/strategies/music-os-accumulator/extractor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ const strategies = [
files: [
"zora-get-tokenuri-transformation",
"soundxyz-get-tokenuri-transformation",
"noizd-get-tokenuri-transformation",
],
map: new Map(),
accumulator: (map) => {
return (line) => {
const data = JSON.parse(line);

const IPFSIANAScheme = "ipfs://";
if (data.erc721.tokenURI.includes(IPFSIANAScheme)) {
data.tokenURI = data.tokenURI.replace(
IPFSIANAScheme,
env.IPFS_HTTPS_GATEWAY
);
}
data.tokenURI = normalifyTokenURI(data.tokenURI);

map.set(data.erc721.tokenURI, data);
};
},
Expand All @@ -40,6 +36,7 @@ const strategies = [
files: [
"zora-call-tokenmetadatauri-transformation",
"soundxyz-call-tokenuri-transformation",
"noizd-call-tokenuri-transformation",
],
map: new Map(),
accumulator: (map) => {
Expand All @@ -50,22 +47,8 @@ const strategies = [
data.metadata.tokenId
);

if (
data.tokenURI.includes("https://") &&
data.tokenURI.includes("ipfs")
) {
const parts = data.tokenURI.split("/");
const hash = parts.pop();
data.tokenURI = `${env.IPFS_HTTPS_GATEWAY}${hash}`;
}

const IPFSIANAScheme = "ipfs://";
if (data.tokenURI.includes(IPFSIANAScheme)) {
data.tokenURI = data.tokenURI.replace(
IPFSIANAScheme,
env.IPFS_HTTPS_GATEWAY
);
}
data.tokenURI = normalifyTokenURI(data.tokenURI);

map.set(id, data);
map.set(data.tokenURI, data);
};
Expand All @@ -82,19 +65,8 @@ const strategies = [
data.metadata.tokenId
);

if (data.tokenURI.includes("https://")) {
const parts = data.tokenURI.split("/");
const hash = parts.pop();
data.tokenURI = `${env.IPFS_HTTPS_GATEWAY}${hash}`;
}

const IPFSIANAScheme = "ipfs://";
if (data.tokenURI.includes(IPFSIANAScheme)) {
data.tokenURI = data.tokenURI.replace(
IPFSIANAScheme,
env.IPFS_HTTPS_GATEWAY
);
}
data.tokenURI = normalifyTokenURI(data.tokenURI);

map.set(id, data);
map.set(data.tokenURI, data);
};
Expand Down Expand Up @@ -141,6 +113,17 @@ async function lineReader(filePath, accumulator) {
return;
}

function normalifyTokenURI(tokenURI) {
if (tokenURI.includes("https://"))
return `${env.IPFS_HTTPS_GATEWAY}${tokenURI.split("/").pop()}`;

const IPFSIANAScheme = "ipfs://";
if (tokenURI.includes(IPFSIANAScheme))
return tokenURI.replace(IPFSIANAScheme, env.IPFS_HTTPS_GATEWAY);

return tokenURI;
}

function caip19(address, tokenId) {
return `eip155:1/erc721:${address}/${tokenId}`;
}
Expand Down Expand Up @@ -195,7 +178,10 @@ export async function init() {
metadata.manifestations[0].mimetype = "audio";
tracks.set(tokenURI, metadata);
}
} else if (metadata.platform.name === "Sound") {
} else if (
metadata.platform.name === "Sound" ||
metadata.platform.name === "Noizd"
) {
const chainData = data.uris.get(tokenURI);
metadata.erc721.createdAt = chainData.metadata.block.number;
metadata.erc721.address = chainData.metadata.contract.address;
Expand Down

0 comments on commit bd3c46e

Please sign in to comment.