-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbda92e
commit 71cf82c
Showing
4 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import axios, { AxiosRequestConfig, AxiosResponse } from "axios"; | ||
|
||
import { NFT, setupURI } from "."; | ||
|
||
import { proxy } from ".."; | ||
|
||
import { Default } from "./index"; | ||
import { extractType } from ".."; | ||
|
||
const cheerio = require("cherio"); | ||
|
||
export const hederaParser = async ( | ||
collectionIdent: string, | ||
nft: any, | ||
account: string, | ||
whitelisted: boolean, | ||
chainId?: string | ||
) => { | ||
let parsed; | ||
switch (true) { | ||
case /(0x000000000000000000000000000000000008f387)/.test( | ||
collectionIdent | ||
): | ||
parsed = await BRONZE(nft, account, whitelisted); | ||
break; | ||
|
||
default: | ||
parsed = await Default(nft, account, whitelisted); | ||
break; | ||
} | ||
|
||
return parsed; | ||
}; | ||
|
||
const BRONZE = async (nft: any, account: string, whitelisted: boolean) => { | ||
const { | ||
native, | ||
native: { contract, tokenId, chainId }, | ||
collectionIdent, | ||
uri, | ||
} = nft; | ||
|
||
try { | ||
const response = (await axios(`${proxy}${setupURI(uri)}`))?.data; | ||
|
||
if (!response) throw new Error("Could not fetch hedera nft::BRONZE"); | ||
|
||
let img = response.image?.description | ||
? (await axios(`${proxy}${setupURI(response.image.description)}`)) | ||
?.data | ||
: ""; | ||
|
||
if (img) { | ||
const $ = cheerio.load(img); | ||
const link = $( | ||
"#content table tbody tr:first-child td:nth-child(2) > a" | ||
).attr("href"); | ||
img = "https://cloudflare-ipfs.com" + link; | ||
} | ||
|
||
const nft: NFT = { | ||
native, | ||
chainId, | ||
tokenId, | ||
owner: account, | ||
uri, | ||
contract, | ||
collectionIdent, | ||
metaData: { | ||
name: response.name, | ||
description: response.description?.description, | ||
image: img, | ||
imageFormat: extractType(img), | ||
whitelisted: true, | ||
}, | ||
}; | ||
|
||
return nft; | ||
} catch (error) { | ||
console.error(error); | ||
|
||
return nft; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters