async function handleRequest(request) {

  if (request.url.includes("check")){
    const data = await request.formData()
    console.log(data)
    const enteredCaptcha = data.get("enteredCaptcha")
    const uid = data.get("uid")

    if (await checkCaptcha(uid, enteredCaptcha)){

      const token = await generateCaptchaToken(uid, enteredCaptcha)
      return Response.redirect(request.url.replace("check", "success?token=" + token), 301)
    }else{
      return Response.redirect(request.url.replace("check", "failed"), 301)
    }

  }else if (request.url.includes("success")){
    return new Response(SuccessView(decodeURI(request.url.split("?")[1])), {
      headers: { 'content-type': 'text/html' },
    })
  }else if (request.url.includes("failed")){
    await increaseFailureTimes(request.headers.get("cf-connecting-ip"))
    const message = await getFailureTimes(request.headers.get("cf-connecting-ip")) + " failures from this IP: " + request.headers.get("cf-connecting-ip")

    return new Response(FailedView(message), {
      headers: { 'content-type': 'text/html' },
    })
  }else{
    const captchaValue = createRandom(6)
    const captchaImageUrl = generateImage(captchaValue)
    const tempUID = createRandom(10)
    const response = new Response(CaptchaView(captchaImageUrl, tempUID), {
      headers: { 'content-type': 'text/html' },
    })
    await saveCookieUID(captchaValue, response, tempUID)
    await saveCaptchaKV(tempUID, captchaValue)
    return response
  }


}
/**
 * Respond with hello worker text
 * @param {Request} request
 */
Respond with hello worker text
@param {Request} request
Respond with hello worker text @param { Request } request
async function handleRequest(request) {
  if (request.url.includes("check")){
    const data = await request.formData()
    console.log(data)
    const enteredCaptcha = data.get("enteredCaptcha")
    const uid = data.get("uid")
    if (await checkCaptcha(uid, enteredCaptcha)){
      const token = await generateCaptchaToken(uid, enteredCaptcha)
      return Response.redirect(request.url.replace("check", "success?token=" + token), 301)
    }else{
      return Response.redirect(request.url.replace("check", "failed"), 301)
    }
  }else if (request.url.includes("success")){
    return new Response(SuccessView(decodeURI(request.url.split("?")[1])), {
      headers: { 'content-type': 'text/html' },
    })
  }else if (request.url.includes("failed")){
    await increaseFailureTimes(request.headers.get("cf-connecting-ip"))
    const message = await getFailureTimes(request.headers.get("cf-connecting-ip")) + " failures from this IP: " + request.headers.get("cf-connecting-ip")
    return new Response(FailedView(message), {
      headers: { 'content-type': 'text/html' },
    })
  }else{
    const captchaValue = createRandom(6)
    const captchaImageUrl = generateImage(captchaValue)
    const tempUID = createRandom(10)
    const response = new Response(CaptchaView(captchaImageUrl, tempUID), {
      headers: { 'content-type': 'text/html' },
    })
    await saveCookieUID(captchaValue, response, tempUID)
    await saveCaptchaKV(tempUID, captchaValue)
    return response
  }
}
async function handleRequest ( request ) { if ( request . url . includes ( "check" ) ) { const data = await request . formData ( ) console . log ( data ) const enteredCaptcha = data . get ( "enteredCaptcha" ) const uid = data . get ( "uid" ) if ( await checkCaptcha ( uid , enteredCaptcha ) ) { const token = await generateCaptchaToken ( uid , enteredCaptcha ) return Response . redirect ( request . url . replace ( "check" , "success?token=" + token ) , 301 ) } else { return Response . redirect ( request . url . replace ( "check" , "failed" ) , 301 ) } } else if ( request . url . includes ( "success" ) ) { return new Response ( SuccessView ( decodeURI ( request . url . split ( "?" ) [ 1 ] ) ) , { headers : { 'content-type' : 'text/html' } , } ) } else if ( request . url . includes ( "failed" ) ) { await increaseFailureTimes ( request . headers . get ( "cf-connecting-ip" ) ) const message = await getFailureTimes ( request . headers . get ( "cf-connecting-ip" ) ) + " failures from this IP: " + request . headers . get ( "cf-connecting-ip" ) return new Response ( FailedView ( message ) , { headers : { 'content-type' : 'text/html' } , } ) } else { const captchaValue = createRandom ( 6 ) const captchaImageUrl = generateImage ( captchaValue ) const tempUID = createRandom ( 10 ) const response = new Response ( CaptchaView ( captchaImageUrl , tempUID ) , { headers : { 'content-type' : 'text/html' } , } ) await saveCookieUID ( captchaValue , response , tempUID ) await saveCaptchaKV ( tempUID , captchaValue ) return response } }
Respond with hello worker text
 @param {Request} request
Respond with hello worker text @param { Request } request