Skip to content

Commit

Permalink
split up Sourced to fit in pattern matching address space (ugly)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Hamblen committed Apr 17, 2011
1 parent 62ebf22 commit 64bcf51
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/main/scala/Sourced.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ trait Encoding {
/** Sourced - serving scala for the _good_ of mankind */
class Sourced extends Responses with Urls with Requests with Auth with Encoding with unfiltered.filter.Plan {
import stores.{DocStore, OrgStore}
import javax.servlet.http.{HttpServletRequest => Req}
import javax.servlet.http.{HttpServletRequest => Req, HttpServletResponse}
import com.google.appengine.api.blobstore._
import QParams._


val blobs = BlobstoreServiceFactory.getBlobstoreService
val blogInfoFact = new BlobInfoFactory

def intent = {

case req @ POST(Path(Seg(org :: project :: version :: srcName :: _))) =>
Ok ~> ResponseString(blobs.createUploadUrl(
"/upload?org=%s&path=%s" format (urlencode(org),
Expand Down Expand Up @@ -86,13 +84,6 @@ class Sourced extends Responses with Urls with Requests with Auth with Encoding
response(400, fails map { fl => "%s is required".format(fl.name) } mkString ". ")
}

case GET(Path("/uploaded") & Params(p)) =>
val expected = for {
status <- lookup("status") is(int(_ => ())) is(required())
msg <- lookup("msg") is(required())
} yield Status(status.get) ~> ResponseString(msg.get)
expected(p) orFail { _ => InternalServerError }

case req @ GET(Path(Seg(org :: project :: version :: srcName :: _))) =>
DocStore(url(req.underlying)) flatMap { src =>
Option(src.blobKey) map { key =>
Expand All @@ -103,6 +94,21 @@ class Sourced extends Responses with Urls with Requests with Auth with Encoding
}
}
} getOrElse NotFound

}
}
class Sourced2 extends Responses with Urls with Requests with Auth with Encoding with unfiltered.filter.Plan {
import stores.{DocStore, OrgStore}
import javax.servlet.http.{HttpServletRequest => Req, HttpServletResponse}
import QParams._

def intent = {
case GET(Path("/uploaded") & Params(p)) =>
val expected = for {
status <- lookup("status") is(int(_ => ())) is(required())
msg <- lookup("msg") is(required())
} yield Status(status.get) ~> ResponseString(msg.get)
expected(p) orFail { _ => InternalServerError }

case req @ GET(Path(Seg("admin" :: Nil))) => adminPage(req.underlying) {
<form action="setkey" method="post">
Expand Down
11 changes: 11 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter>
<filter-name>Sourced2</filter-name>
<display-name>Sourced Filter2</display-name>
<filter-class>implicitly.Sourced2</filter-class>
</filter>
<filter-mapping>
<filter-name>Sourced2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter>
<filter-name>SourcedUpload</filter-name>
<display-name>Sourced Upload Filter</display-name>
Expand Down

0 comments on commit 64bcf51

Please sign in to comment.