Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tempe-techie committed Sep 15, 2024
1 parent ec6f0f7 commit 0ea0633
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions components/profile/ProfileImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export default {
this.imgPath = this.image;
sessionStorage.setItem(String(this.address).toLowerCase()+"-img", this.image);
}
if (this.imgPath.startsWith("ipfs://")) {
this.imgPath = this.imgPath.replace("ipfs://", "https://ipfs.io/ipfs/");
} else if (this.imgPath.startsWith("ar://")) {
this.imgPath = this.imgPath.replace("ar://", "https://arweave.net/");
}
},
watch: {
Expand Down
16 changes: 12 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://', 'https://arweave.net/')
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://', 'https://arweave.net/')
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,8 @@ 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 +418,7 @@ export function imgParsing(text) {
return text.replace(imageRegex, function (url) {
let newUrl = url
if (url.startsWith('ar://')) {
newUrl = url.replace('ar://', 'https://arweave.net/')
newUrl = url.replace('ar://', config.arweaveGateway)
} else if (url.startsWith('ipfs://')) {
newUrl = url.replace('ipfs://', 'https://ipfs.io/ipfs/')
}
Expand All @@ -422,6 +428,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 +445,7 @@ export function imgWithoutExtensionParsing(text) {

return text.replace(imageRegex, function (url) {
if (url.startsWith('ar://')) {
url = url.replace('ar://', 'https://arweave.net/')
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 0ea0633

Please sign in to comment.