Verified Commit 2b4bbb7e authored by Jakob Moser's avatar Jakob Moser
Browse files

Implement canAccess

parent 4689cc13
Loading
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -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() {}