2025-03-16 13:33:52 +02:00
|
|
|
package server
|
|
|
|
|
|
|
|
|
|
import cats.effect.IO
|
|
|
|
|
import cats.implicits.toTraverseOps
|
|
|
|
|
import fs2.io.file.{Files, Path}
|
|
|
|
|
|
|
|
|
|
object DebugUtils {
|
|
|
|
|
case class FileInfo(name: String, isDirectory: Boolean)
|
|
|
|
|
case class DirectoryStructure(path: String, files: List[FileInfo])
|
|
|
|
|
case class FolderStructureResponse(
|
|
|
|
|
current: DirectoryStructure,
|
|
|
|
|
data: DirectoryStructure,
|
2025-03-16 15:38:11 +02:00
|
|
|
tmp: DirectoryStructure,
|
2025-03-16 13:33:52 +02:00
|
|
|
grib: DirectoryStructure
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
private def getDirectoryStructure(path: Path): IO[DirectoryStructure] = {
|
|
|
|
|
for {
|
|
|
|
|
absolutePath <- IO(path.toString)
|
|
|
|
|
files <- Files[IO].list(path).compile.toList
|
|
|
|
|
fileInfos <- files.traverse { filePath =>
|
|
|
|
|
Files[IO].isDirectory(filePath).map { isDir =>
|
|
|
|
|
FileInfo(filePath.fileName.toString, isDir)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} yield DirectoryStructure(absolutePath, fileInfos)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def getFolderStructure: IO[FolderStructureResponse] = {
|
|
|
|
|
val currentPath = Path(".")
|
|
|
|
|
val dataPath = Path("data")
|
2025-03-16 15:38:11 +02:00
|
|
|
val tmpPath = Path("data/tmp")
|
2025-03-16 13:33:52 +02:00
|
|
|
val gribPath = Path("data/grib")
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
current <- getDirectoryStructure(currentPath)
|
|
|
|
|
data <- getDirectoryStructure(dataPath)
|
2025-03-16 15:38:11 +02:00
|
|
|
tmp <- getDirectoryStructure(tmpPath)
|
2025-03-16 13:33:52 +02:00
|
|
|
grib <- getDirectoryStructure(gribPath)
|
2025-03-16 15:38:11 +02:00
|
|
|
response = FolderStructureResponse(current, data, tmp, grib)
|
2025-03-16 13:33:52 +02:00
|
|
|
} yield response
|
|
|
|
|
}
|
|
|
|
|
}
|