File manager frontend

This commit is contained in:
Guntis Smaukstelis
2023-05-15 16:37:03 +03:00
parent 851229ce9b
commit db900d6a33
11 changed files with 215 additions and 37 deletions
+8
View File
@@ -74,4 +74,12 @@ object DBService {
val dateStr: String = date.format(formatter)
readFileNames(dataPath).map(_.filter(_.startsWith(dateStr)).sorted)
}
def getFileContent(fileName: String): IO[String] = {
val file = new File(dataPath, fileName)
val sourceResource = Resource.fromAutoCloseable(IO(Source.fromFile(file)))
sourceResource.use(source => IO(source.getLines().mkString("<br/>\n"))).handleErrorWith { error =>
IO(println(s"Failed to read file: $error")) *> IO.pure("")
}
}
}
+4
View File
@@ -71,6 +71,10 @@ object Server {
Ok(fileNames.asJson.pretty)
)
// http://0.0.0.0:8080/api/show/file/20230423_12:30.csv
case GET -> Root / "show" / "file" / (fileName: String) =>
DBService.getFileContent(fileName).flatMap(Ok(_))
// http://0.0.0.0:8080/api/help
case GET -> Root / "help" => {
val host = "weather-tool.fly.dev"