<commit_before>package capture
package server

import unfiltered.request._
import unfiltered.response._

import unfiltered.netty.async
import unfiltered.netty.ServerErrorResponse

case class Attachment(filename: String) extends Responder[Any] {
  def respond(res: HttpResponse[Any]) {
    res.header("Content-Disposition", "attachment; filename=%s".format(filename))
  }
}

trait Interface extends DefaultPlan with Lmxml {
  import lmxml.transforms.Empty

  val pattern = new java.text.SimpleDateFormat("MM-dd-yy KK:mm:ss a")

  val validFiles =
    List("jquery.js", "desktop.js", "interface.js", "viewport.js")

  def data = Seq("connect-check" -> Empty)

  def preload: async.Plan.Intent

  def defaults: async.Plan.Intent = {
    case req @ Path("/view.html") =>
      req.respond(index(Resource.retrieve("index.lmxml")))
    case req @ Path(Seg(ValidJs(rf) :: Nil)) => req.respond(rf)
    case req @ Path(Seg(Bootstrap(rf) :: Nil)) => req.respond(rf)
    case req @ Path(Seg("img" :: Bootstrap(rf) :: Nil)) => req.respond(rf)
    case req @ Path(Seg("snapshot.jpg" :: Nil)) =>
      val now = new java.util.Date(System.currentTimeMillis)
      req.respond(
        Ok ~>
        Attachment("Snapshot-%s.jpg".format(pattern.format(now))) ~>
        ContentType("image/jpeg") ~>
        ResponseBytes(capture.control.Robot.screenshot.data(1.0f))
      )
  }

  def intent = preload orElse defaults
}

trait DefaultPlan extends async.Plan with ServerErrorResponse {
  // Allow plan to determine what js files are valid
  val validFiles: List[String]

  object ValidJs {
    def unapply(file: String) = {
      if (validFiles.exists(_ == file))
        Some(
          Ok ~>
          ContentType("text/javascript") ~>
          ResponseString(Resource.retrieve(file))
        )
      else
        None
    }
  }
}

object Bootstrap {
  object Js {
    val Pattern = """^bootstrap\-\w+\.js""".r<commit_msg>Pointer in screenshot<commit_after>package capture
package server

import unfiltered.request._
import unfiltered.response._

import unfiltered.netty.async
import unfiltered.netty.ServerErrorResponse

case class Attachment(filename: String) extends Responder[Any] {
  def respond(res: HttpResponse[Any]) {
    res.header("Content-Disposition", "attachment; filename=%s".format(filename))
  }
}

trait Interface extends DefaultPlan with Lmxml {
  import lmxml.transforms.Empty

  val pattern = new java.text.SimpleDateFormat("MM-dd-yy KK:mm:ss a")

  val validFiles =
    List("jquery.js", "desktop.js", "interface.js", "viewport.js")

  def data = Seq("connect-check" -> Empty)

  def preload: async.Plan.Intent

  def defaults: async.Plan.Intent = {
    case req @ Path("/view.html") =>
      req.respond(index(Resource.retrieve("index.lmxml")))
    case req @ Path(Seg(ValidJs(rf) :: Nil)) => req.respond(rf)
    case req @ Path(Seg(Bootstrap(rf) :: Nil)) => req.respond(rf)
    case req @ Path(Seg("img" :: Bootstrap(rf) :: Nil)) => req.respond(rf)
    case req @ Path(Seg("snapshot.jpg" :: Nil)) =>
      val now = new java.util.Date(System.currentTimeMillis)
      req.respond(
        Ok ~>
        Attachment("Snapshot-%s.jpg".format(pattern.format(now))) ~>
        ContentType("image/jpeg") ~>
        ResponseBytes(capture.control.Robot.screenshot.withPointer.data(1.0f))
      )
  }

  def intent = preload orElse defaults
}

trait DefaultPlan extends async.Plan with ServerErrorResponse {
  // Allow plan to determine what js files are valid
  val validFiles: List[String]

  object ValidJs {
    def unapply(file: String) = {
      if (validFiles.exists(_ == file))
        Some(
          Ok ~>
          ContentType("text/javascript") ~>
          ResponseString(Resource.retrieve(file))
        )
      else
        None
    }
  }
}

object Bootstrap {
  object Js {
    val Pattern = """^bootstrap\-\w+\.js""".r
{'fraction_non_alphanumeric': 0.13954094940010434, 'fraction_numerical': 0.0010432968179447052, 'mean_word_length': 3.2801339285714284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '114162', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1195, 'n_words': 263}