Skip to content

Commit

Permalink
custom IPFS gateway link in nuxt config; replace the spheron IPFS gat…
Browse files Browse the repository at this point in the history
…eway with the one defined in nuxt config
  • Loading branch information
tempe-techie committed Dec 4, 2023
1 parent e5e080d commit adc0410
Showing 5 changed files with 25 additions and 4 deletions.
5 changes: 3 additions & 2 deletions components/storage/FileUploadInput.vue
Original file line number Diff line number Diff line change
@@ -123,9 +123,10 @@ export default {
if (this.uploadToken) {
const token = this.uploadToken;
const { protocolLink } = await upload([this.file], { token });
const { protocolLink, cid } = await upload([this.file], { token });
const fullFileUrl = protocolLink + "/" + this.newFileName;
//const fullFileUrl = protocolLink + "/" + this.newFileName;
const fullFileUrl = this.$config.ipfsGateway + cid + "/" + this.newFileName;
// emit file url
this.$emit("processUploadedFileUrl", fullFileUrl);
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ export default defineNuxtConfig({
iggyPostAddress: "0x63FE8216a66737CFE474DF3949F9081EbD4Bd800",
iggyPostMinterAddress: "0xF48D3812ceD80bC78C8553d7C3b702b0F0d63903",
iggyPostStatsAddress: "0xFCF878b629fF0Ef3bC033eFfCfFD39B00c9a68C5",
ipfsGateway: "https://cloudflare-ipfs.com/ipfs/",
keysAddress: "0x34E7D66455BE3f6f0cCbF3df3b7c56b482530C8E", // FriendKeys contract address
keysContext: "kjzl6cwe1jw14akr2rh1j3fhup1ewfr2uyyd6l85qllbe2d5fxywt7d8rqnau6j",
keysFeatured: ["tempe", "tekr"],
9 changes: 9 additions & 0 deletions pages/nft/index.vue
Original file line number Diff line number Diff line change
@@ -293,6 +293,15 @@ export default {
collection["image"] = cImage;
}
// check if collection image uses Spheron IPFS gateway (in that case replace it with the IPFS gateway defined in the config)
if (collection.image.includes(".ipfs.sphn.link/")) {
const linkParts = collection.image.split(".ipfs.sphn.link/");
const cid = linkParts[0].replace("https://", "");
const newImageLink = this.$config.ipfsGateway + cid + "/" + linkParts[1];
collection["image"] = newImageLink;
cImage = newImageLink;
}
// store collection object in storage
storeCollection(window, inputArray[i], collection);
5 changes: 3 additions & 2 deletions utils/linkPreviewUtils.js
Original file line number Diff line number Diff line change
@@ -66,16 +66,17 @@ async function fetchNftMetadata(url, addr, tokenId, rpcUrl, marketplace) {
if (nftMetadataUri.startsWith("ipfs://")) {
// ipfs://QmeSjSinHpPnmXmspMjwiXyN6zS4E9zccariGR3jxcaWtq/2614
// https://dweb.link/ipfs/QmeSjSinHpPnmXmspMjwiXyN6zS4E9zccariGR3jxcaWtq/2614
// https://cloudflare-ipfs.com/ipfs/QmeSjSinHpPnmXmspMjwiXyN6zS4E9zccariGR3jxcaWtq/2614

nftMetadataUri = nftMetadataUri.replace("ipfs://", "https://dweb.link/ipfs/");
nftMetadataUri = nftMetadataUri.replace("ipfs://", "https://cloudflare-ipfs.com/ipfs/");
}

const res = await axios.get(nftMetadataUri);
json = await res.data;
}

if (json["image"].startsWith("ipfs://")) {
json["image"] = json["image"].replace("ipfs://", "https://dweb.link/ipfs/");
json["image"] = json["image"].replace("ipfs://", "https://cloudflare-ipfs.com/ipfs/");
}

if (!json["description"]) {
9 changes: 9 additions & 0 deletions utils/textUtils.js
Original file line number Diff line number Diff line change
@@ -338,12 +338,21 @@ export function hasTextBlankCharacters(text) {
}

export function imgParsing(text) {
const config = useRuntimeConfig();

const imageRegex = /(?:https?:\/\/(?:www\.)?)?(?:[-\w]+\.)+[^\s]+\.(?:jpe?g|gif|png|img)/gi;
//const imageRegex = /(https?:\/\/.*\.(?:png|jpg|jpeg|gif))/i;

if (!imageRegex.test(text)) { return text };

return text.replace(imageRegex, function(url) {
if (url.includes(".ipfs.sphn.link/")) {
// replace a link to Spheron IPFS Gateway with an IPFS Gateway set in config
const linkParts = url.split(".ipfs.sphn.link/");
const ipfsHash = linkParts[0].replace("https://", "");
const ipfsLink = config.ipfsGateway + ipfsHash + "/" + linkParts[1];
return '<div></div><img class="img-fluid rounded" style="max-height: 500px;" src="' + ipfsLink + '" />';
}
return '<div></div><img class="img-fluid rounded" style="max-height: 500px;" src="' + url + '" />';
})
}

0 comments on commit adc0410

Please sign in to comment.