{"size": 1937, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "cohan/imgy-src", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "index.js", "max_issues_repo_name": "cohan/imgy-src", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "index.js", "max_forks_repo_name": "cohan/imgy-src", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.9135802469, "max_line_length": 168, "alphanum_fraction": 0.5085183273}
async function handleRequest(request) {
    var url = new URL(request.url);

    // Override our source
    url.hostname = "imgy-live.s3.eu-west-2.amazonaws.com";

    let response = await fetch(url, request, {
        cf: {
            cacheTtl: 604800,
            cacheEverything: true, 
        }, 
    });
    
    response = new Response(response.body, response);

    if ( response.status >= 100 && response.status <= 399 ) {
        response.headers.set("Cache-Control", "max-age=604800")
        return response;
    }

    let body =
`<!DOCTYPE html>
<html>
<head>
    <title>Image error</title>
</head>
<body>
    <div class="flex-container">
        <div class="row">
            <div class="flex-item">Image error: ` + response.status + `</div>
            <div class="flex-item small">If you were expecting something to be here and it's vanished, please do <a href='https://ic4.io/contact'>let me know</a>!</div>
        </div>
    </div>
    <style>
        html, body {
            height: 100%;
            background-color: white;
            color: #15202b;
        }
        body {
            margin: 0;
        }
        a, a:visited {
            color: #123456;
        }
        .flex-container {
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .row {
            width: auto;
        }
        .flex-item {
            font-size: 2em;
            text-align: center;
            margin-bottom: 1.4em;
        }
        .small {
            font-size: 1.2em;
        }
    </style>
</body>
</html>`;

    let imageNotFound = new Response(body, {
        status: response.status,
        statusText: "Image error",
        headers: {
            "Content-Type": "text/html"
        }
    });

    return imageNotFound;
    
}

addEventListener('fetch', event => {
    event.respondWith(handleRequest(event.request));
});