Skip to content

Commit

Permalink
Incorporated review suggestions for issue ipfs#2244: Updated constant…
Browse files Browse the repository at this point in the history
…s, refactored image check code, and simplified settings text.
  • Loading branch information
acul71 committed Sep 4, 2024
1 parent 7a64e72 commit fda5381
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
4 changes: 2 additions & 2 deletions public/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"translationProjectLink": "Join the IPFS Translation Project"
},
"apiDescription": "<0>If your node is configured with a <1>custom Kubo RPC API address</1>, including a port other than the default 5001, enter it here.</0>",
"publicSubdomainGatewayDescription": "<0>Choose which <1>Subdomain Gateway</1> you want to use when generating shareable links (Default: Subdomain Isolation)</0>",
"publicPathGatewayDescription": "<0>Choose which <1>Path Gateway</1> you want to use when generating shareable links (Fallback: Path Gateway used for CIDs > 63 char)</0>",
"publicSubdomainGatewayDescription": "<0>Select a default <1>Subdomain Gateway</1> for generating shareable links.</0>",
"publicPathGatewayDescription": "<0>Select a fallback <1>Path Gateway</1> for generating shareable links for CIDs that exceed the 63-character DNS limit.</0>",
"cliDescription": "<0>Enable this option to display a \"view code\" <1></1> icon next to common IPFS commands. Clicking it opens a modal with that command's CLI code, so you can paste it into the IPFS command-line interface in your terminal.</0>",
"cliModal": {
"extraNotesJsonConfig": "If you've made changes to the config in this page's code editor that you'd like to save, click the download icon next to the copy button to download it as a JSON file."
Expand Down
27 changes: 8 additions & 19 deletions src/bundles/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ const checkImgSrcPromise = (imgUrl) => {
return true
}

let timer = setTimeout(() => { if (timeout()) reject(new Error()) }, imgCheckTimeout)
let timer = setTimeout(() => { if (timeout()) reject(new Error(`Image load timed out after ${imgCheckTimeout / 1000} seconds for URL: ${imgUrl}`)) }, imgCheckTimeout)
const img = new Image()

img.onerror = () => {
timeout()
reject(new Error())
reject(new Error(`Failed to load image from URL: ${imgUrl}`))
}

img.onload = () => {
Expand Down Expand Up @@ -120,23 +120,12 @@ async function expectSubdomainRedirect (url) {
* @returns {Promise<void>} A promise that resolves if the image loads successfully within the timeout, otherwise it rejects with an error.
*/
async function checkViaImgUrl (imgUrl) {
const imgCheckTimeout = 15000
await new Promise((resolve, reject) => {
const img = new Image()
const timer = setTimeout(() => {
reject(new Error(`Timeout when attempting to load img from '${img.src}`))
}, imgCheckTimeout)
img.onerror = () => {
clearTimeout(timer)
reject(new Error(`Error when attempting to load img from '${img.src}`))
}
img.onload = () => {
clearTimeout(timer)
console.log(`Successfully loaded img from '${img.src}'`)
resolve(undefined)
}
img.src = imgUrl.toString()
})
try {
await checkImgSrcPromise(imgUrl)
console.log(`Successfully loaded img from '${imgUrl.toString()}'`)
} catch (error) {
throw new Error(`Error or timeout when attempting to load img from '${imgUrl.toString()}'`)
}
}

/**
Expand Down

0 comments on commit fda5381

Please sign in to comment.