Skip to content
Snippets Groups Projects
Verified Commit 2b4bbb7e authored by Jakob Moser's avatar Jakob Moser
Browse files

Implement canAccess

parent 4689cc13
No related branches found
No related tags found
Loading
Pipeline #6524 passed
......@@ -34,7 +34,25 @@
* to determine if the user is logged in.
*/
async function canAccess(imageUrl) {}
/**
* Checks if the browser can access the image at the given URL. This must be a valid image, otherwise
* the check will always fail.
*
* @param {String} imageUrl A url to an image file (likely hosted on some other origin)
*/
async function canAccess(imageUrl) {
try {
await new Promise((resolve, reject) => {
const img = document.createElement("img")
img.addEventListener("load", resolve)
img.addEventListener("error", reject)
img.src = imageUrl
})
return true
} catch {
return false
}
}
export async function isLoggedIn() {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment