Merge remote-tracking branch 'origin/v2' into v2

# Conflicts:
#	gameyfin/src/main/frontend/components/general/input/FileTreeView.tsx
#	gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/filesystem/FilesystemService.kt
This commit is contained in:
grimsi
2025-04-05 21:58:33 +02:00
2 changed files with 26 additions and 19 deletions
@@ -57,8 +57,8 @@ export default function FileTreeView({onPathChange}: { onPathChange: (file: stri
path = path.replace(`${pathSeparator}${pathSeparator}`, pathSeparator);
if (node.parent === null) {
if (hostOSType === OperatingSystemType.WINDOWS) return path ? path : node.name
return path ? `${node.name}${pathSeparator}${path}` : node.name;
if (hostOSType === OperatingSystemType.WINDOWS) return path;
return `${pathSeparator}${path}`;
}
const parentNode = flattenedFileTree.find(n => n.id === node.parent);
@@ -21,27 +21,23 @@ class FilesystemService {
*/
fun listContents(path: String?): List<FileDto> {
if (path == null || path.isEmpty()) {
return FileSystems.getDefault().rootDirectories
.map {
FileDto(
it.root.toString(),
if (it.isDirectory()) FileType.DIRECTORY else FileType.FILE,
it.hashCode()
)
}
val roots = FileSystems.getDefault().rootDirectories.toList()
if (roots.size > 1) return roots.map {
FileDto(
it.root.toString(),
if (it.isDirectory()) FileType.DIRECTORY else FileType.FILE,
it.hashCode()
)
}
// If there is only one root, return its contents
return safeReadDirectoryContents(roots.first().toString())
}
var path = FilenameUtils.separatorsToSystem(path)
if (path.startsWith("\\")) path = path.substring(1)
return try {
Path(path).toFile().listFiles()
.filter { f -> !f.isHidden }
.map { FileDto(it.name, if (it.isDirectory) FileType.DIRECTORY else FileType.FILE, it.hashCode()) }
} catch (_: Exception) {
log.error { "Error listing contents of path $path" }
emptyList()
}
return safeReadDirectoryContents(path)
}
/**
@@ -64,4 +60,15 @@ class FilesystemService {
else -> OperatingSystemType.UNKNOWN
}
}
private fun safeReadDirectoryContents(path: String): List<FileDto> {
return try {
Path(path).toFile().listFiles()
.filter { !it.isHidden }
.map { FileDto(it.name, if (it.isDirectory) FileType.DIRECTORY else FileType.FILE, it.hashCode()) }
} catch (e: Exception) {
log.error(e) { "Error reading directory contents of $path" }
emptyList()
}
}
}