Skip to content

Commit

Permalink
minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tempe-techie committed Sep 18, 2024
1 parent 19d270f commit 7cabc1c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/nft/collection/ChangeMediaModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default {
url = url.trim();
}
if (!url.startsWith("http") && !url.startsWith("ipfs")) {
if (!url.startsWith("http://") && !url.startsWith("https://") && !url.startsWith("ipfs://") && !url.startsWith("ar://")) {
if (!url.includes("/") && !url.includes(".")) {
return "ipfs://" + url;
} else if (url.split(".").length > 2) {
Expand Down
3 changes: 2 additions & 1 deletion utils/ipfsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function getIpfsUrl(url) {
}

export async function getWorkingUrl(url) {
const config = useRuntimeConfig();
let ipfsUrl = url

if (url.startsWith("http")) {
Expand Down Expand Up @@ -87,7 +88,7 @@ export async function getWorkingUrl(url) {
}
}
} else if (url.startsWith("ar://")) {
const arweaveUrl = url.replace("ar://", this.$config.arweaveGateway)
const arweaveUrl = url.replace("ar://", config.arweaveGateway)

try {
const response = await axios.head(arweaveUrl, { signal: AbortSignal.timeout(abortTimeout) })
Expand Down
15 changes: 11 additions & 4 deletions utils/textUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export function findFirstUrl(text) {
}

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

if (!text) {
return []
}
Expand Down Expand Up @@ -100,7 +102,7 @@ export function getAllImagesFromText(text) {
} else {
for (let i = 0; i < imageLinks.length; i++) {
if (imageLinks[i].startsWith('ar://')) {
imageLinks[i] = imageLinks[i].replace('ar://', this.$config.arweaveGateway)
imageLinks[i] = imageLinks[i].replace('ar://', config.arweaveGateway)
} else if (imageLinks[i].startsWith('ipfs://')) {
imageLinks[i] = imageLinks[i].replace('ipfs://', 'https://ipfs.io/ipfs/')
}
Expand All @@ -111,6 +113,8 @@ export function getAllImagesFromText(text) {
}

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

if (!text) {
return null
}
Expand All @@ -137,7 +141,7 @@ export function getImageFromText(text) {
} else {
for (let i = 0; i < imageLinks.length; i++) {
if (imageLinks[i].startsWith('ar://')) {
imageLinks[i] = imageLinks[i].replace('ar://', this.$config.arweaveGateway)
imageLinks[i] = imageLinks[i].replace('ar://', config.arweaveGateway)
} else if (imageLinks[i].startsWith('ipfs://')) {
imageLinks[i] = imageLinks[i].replace('ipfs://', 'https://ipfs.io/ipfs/')
}
Expand Down Expand Up @@ -403,6 +407,7 @@ export function hasTextBlankCharacters(text) {
}

export function imgParsing(text) {
const config = useRuntimeConfig();
const imageRegex = /(?:https?:\/\/|ipfs:\/\/|ar:\/\/)(?:[^\/\s]+\/)+[^\s]+\.(?:jpe?g|gif|webp|png|img)/gi

if (!imageRegex.test(text)) {
Expand All @@ -412,7 +417,7 @@ export function imgParsing(text) {
return text.replace(imageRegex, function (url) {
let newUrl = url
if (url.startsWith('ar://')) {
newUrl = url.replace('ar://', this.$config.arweaveGateway)
newUrl = url.replace('ar://', config.arweaveGateway)
} else if (url.startsWith('ipfs://')) {
newUrl = url.replace('ipfs://', 'https://ipfs.io/ipfs/')
}
Expand All @@ -422,6 +427,8 @@ export function imgParsing(text) {
}

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

// if image doesn't have an extension, it won't be parsed by imgParsing
// so we need to parse it here
// but image link needs to end with "?.img" to be parsed (otherwise frontend will think it's a link)
Expand All @@ -437,7 +444,7 @@ export function imgWithoutExtensionParsing(text) {

return text.replace(imageRegex, function (url) {
if (url.startsWith('ar://')) {
url = url.replace('ar://', this.$config.arweaveGateway)
url = url.replace('ar://', config.arweaveGateway)
} else if (url.startsWith('ipfs://')) {
url = url.replace('ipfs://', 'https://ipfs.io/ipfs/')
}
Expand Down

0 comments on commit 7cabc1c

Please sign in to comment.