summaryrefslogblamecommitdiff
path: root/cask/src/cask/endpoints/StaticEndpoints.scala
blob: fd194ca447b7d3b87e77cf99e31670b947ab175c (plain) (tree)
1
2
3
4
5
6
7
8
9

                      
                         
                         
 
                                                     
                      
                          
                          
                                           
                             
                                                                  
                            




                                                                      
     










                                                                                                              
                                                                  
                            





                                                                      
     
   
 
                                                
 
package cask.endpoints

import cask.main.Endpoint
import cask.model.Request

class staticFiles(val path: String) extends Endpoint{
  type Output = String
  val methods = Seq("get")
  type Input = Seq[String]
  type InputParser[T] = QueryParamReader[T]
  override def subpath = true
  def wrapFunction(ctx: Request, delegate: Delegate): Returned = {
    delegate(Map()).map(t =>
      cask.model.StaticFile(
        (cask.internal.Util.splitPath(t) ++ ctx.remainingPathSegments)
          .filter(s => s != "." && s != "..")
          .mkString("/")
      )
    )
  }

  def wrapPathSegment(s: String): Input = Seq(s)
}

class staticResources(val path: String, resourceRoot: ClassLoader = getClass.getClassLoader) extends Endpoint{
  type Output = String
  val methods = Seq("get")
  type Input = Seq[String]
  type InputParser[T] = QueryParamReader[T]
  override def subpath = true
  def wrapFunction(ctx: Request, delegate: Delegate): Returned = {
    delegate(Map()).map(t =>
      cask.model.StaticResource(
        (cask.internal.Util.splitPath(t) ++ ctx.remainingPathSegments)
          .filter(s => s != "." && s != "..")
          .mkString("/"),
        resourceRoot
      )
    )
  }

  def wrapPathSegment(s: String): Input = Seq(s)
}