<commit_before>package fink.web

import scala.collection.JavaConversions._
import java.lang.{Long=>JLong}

import fink.data._
import fink.support._

import javax.servlet.ServletConfig

import org.scalatra.fileupload.FileUploadSupport
import org.scalatra.scalate.ScalateSupport
import org.scalatra.ScalatraServlet
import org.scalatra.servlet._

import net.liftweb.json._
import net.liftweb.json.Serialization.{read, write}
import java.io.File

class Admin extends ScalatraServlet with RepositorySupport with AuthenticationRoutes with ResourceRoutes with ScalateSupport with FileUploadSupport {

  override implicit val jsonFormats = Serialization.formats(ShortTypeHints(List(classOf[Page], classOf[Category], classOf[Tag]))) + FieldSerializer[Post]()  + FieldSerializer[Gallery]() + FieldSerializer[Image]()

  def adminTemplateBase = "/WEB-INF/admin"

  def uri(uri: String) = {
    if (uri.startsWith("/")) {
      request.getContextPath + uri
    } else {
      uri
    }
  }

  before() {
    contentType = "text/html"
  }

  get("/") {
    if (request.getPathInfo == null) redirect("/admin/")
    templateAttributes("layout") = ("/admin/layouts/default.jade")
    jade("/admin/index.jade") 
  }

  get("/uploads/images/:hash/:spec/:file") {
    (for {
      hash <- Option(params("hash"))
      image <- imageRepository.byHash(hash)
      ext <- MediaManager.imageExtensions.get(image.contentType)
      spec <- MediaManager.imageSpecs.filter(_.name == params("spec")).headOption
    } yield {
      val file = new File("%s/%s-%s.%s".format(Config.mediaDirectory, hash, spec.name, ext))
      if (!file.exists) halt(404)
      response.addHeader("Content-Disposition", "inline;filename=\"%s\"".format(image.filename))<commit_msg>Using hash from image.<commit_after>package fink.web

import scala.collection.JavaConversions._
import java.lang.{Long=>JLong}

import fink.data._
import fink.support._

import javax.servlet.ServletConfig

import org.scalatra.fileupload.FileUploadSupport
import org.scalatra.scalate.ScalateSupport
import org.scalatra.ScalatraServlet
import org.scalatra.servlet._

import net.liftweb.json._
import net.liftweb.json.Serialization.{read, write}
import java.io.File

class Admin extends ScalatraServlet with RepositorySupport with AuthenticationRoutes with ResourceRoutes with ScalateSupport with FileUploadSupport {

  override implicit val jsonFormats = Serialization.formats(ShortTypeHints(List(classOf[Page], classOf[Category], classOf[Tag]))) + FieldSerializer[Post]()  + FieldSerializer[Gallery]() + FieldSerializer[Image]()

  def adminTemplateBase = "/WEB-INF/admin"

  def uri(uri: String) = {
    if (uri.startsWith("/")) {
      request.getContextPath + uri
    } else {
      uri
    }
  }

  before() {
    contentType = "text/html"
  }

  get("/") {
    if (request.getPathInfo == null) redirect("/admin/")
    templateAttributes("layout") = ("/admin/layouts/default.jade")
    jade("/admin/index.jade") 
  }

  get("/uploads/images/:hash/:spec/:file") {
    (for {
      hash <- Option(params("hash"))
      image <- imageRepository.byHash(hash)
      ext <- MediaManager.imageExtensions.get(image.contentType)
      spec <- MediaManager.imageSpecs.filter(_.name == params("spec")).headOption
    } yield {
      val file = new File("%s/%s-%s.%s".format(Config.mediaDirectory, image.hash, spec.name, ext))
      if (!file.exists) halt(404)
      response.addHeader("Content-Disposition", "inline;filename=\"%s\"".format(image.filename))
{'fraction_non_alphanumeric': 0.14018960068945704, 'fraction_numerical': 0.0017236426314277506, 'mean_word_length': 4.212574850299402, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1348294', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1063, 'n_words': 198}