diff --git a/src/main/scala/db/DBService.scala b/src/main/scala/db/DBService.scala
index 2ca4736..56cf8f3 100644
--- a/src/main/scala/db/DBService.scala
+++ b/src/main/scala/db/DBService.scala
@@ -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("
\n"))).handleErrorWith { error =>
+ IO(println(s"Failed to read file: $error")) *> IO.pure("")
+ }
+ }
}
diff --git a/src/main/scala/server/Server.scala b/src/main/scala/server/Server.scala
index eb51deb..a365325 100644
--- a/src/main/scala/server/Server.scala
+++ b/src/main/scala/server/Server.scala
@@ -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"
diff --git a/web/src/App.tsx b/web/src/App.tsx
index bab8dcf..00cd43c 100644
--- a/web/src/App.tsx
+++ b/web/src/App.tsx
@@ -2,7 +2,7 @@ import type { Component } from 'solid-js';
import logo from './assets/logo.svg';
import styles from './css/App.module.css';
-import { FetchedDates } from './FetchedDates';
+import { FileManager } from './fileManager/FileManager';
console.log("env:", import.meta.env.MODE);
console.log("api host:", import.meta.env.VITE_API_HOST);
@@ -10,8 +10,8 @@ console.log("api host:", import.meta.env.VITE_API_HOST);
const App: Component = () => {
return (
Weather tool web diff --git a/web/src/FetchedDates.tsx b/web/src/FetchedDates.tsx deleted file mode 100644 index 6be6a55..0000000 --- a/web/src/FetchedDates.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import { createResource } from "solid-js"; - -const apiHost = import.meta.env.VITE_API_HOST; - -export function FetchedDates() { - const fetchDates = async () => { - const response = await fetch(`${apiHost}/api/show/all_dates`); - const json = await response.json(); - return json; - } - - const [datesResource] = createResource(fetchDates); - - return ( -