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); path = path.replace(`${pathSeparator}${pathSeparator}`, pathSeparator);
if (node.parent === null) { if (node.parent === null) {
if (hostOSType === OperatingSystemType.WINDOWS) return path ? path : node.name if (hostOSType === OperatingSystemType.WINDOWS) return path;
return path ? `${node.name}${pathSeparator}${path}` : node.name; return `${pathSeparator}${path}`;
} }
const parentNode = flattenedFileTree.find(n => n.id === node.parent); const parentNode = flattenedFileTree.find(n => n.id === node.parent);
@@ -21,27 +21,23 @@ class FilesystemService {
*/ */
fun listContents(path: String?): List<FileDto> { fun listContents(path: String?): List<FileDto> {
if (path == null || path.isEmpty()) { if (path == null || path.isEmpty()) {
return FileSystems.getDefault().rootDirectories val roots = FileSystems.getDefault().rootDirectories.toList()
.map {
FileDto( if (roots.size > 1) return roots.map {
it.root.toString(), FileDto(
if (it.isDirectory()) FileType.DIRECTORY else FileType.FILE, it.root.toString(),
it.hashCode() 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) var path = FilenameUtils.separatorsToSystem(path)
if (path.startsWith("\\")) path = path.substring(1)
return try { return safeReadDirectoryContents(path)
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()
}
} }
/** /**
@@ -64,4 +60,15 @@ class FilesystemService {
else -> OperatingSystemType.UNKNOWN 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()
}
}
} }