blob: 4d1ece2b7dcac3401526278043137d83561c266c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package simple
import akka.actor.ActorSystem
import spray.http.{HttpEntity, MediaTypes}
import spray.routing.SimpleRoutingApp
object Server extends SimpleRoutingApp{
def main(args: Array[String]): Unit = {
implicit val system = ActorSystem()
startServer("localhost", port = 8080){
get{
pathSingleSlash{
complete{
HttpEntity(
MediaTypes.`text/html`,
Page.skeleton.render
)
}
} ~
getFromResourceDirectory("")
} ~
post{
path("ajax" / "list"){
extract(_.request.entity.asString) { e =>
complete {
upickle.write(list(e))
}
}
}
}
}
}
def list(path: String) = {
val (dir, last) = path.splitAt(path.lastIndexOf("/") + 1)
val files =
Option(new java.io.File("./" + dir).listFiles())
.toSeq.flatten
for{
f <- files
if f.getName.startsWith(last)
} yield FileData(f.getName, f.length())
}
}
|