File manager frontend
This commit is contained in:
@@ -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("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user