fixes in FileKeyValueRepo

This commit is contained in:
InsanusMokrassar 2023-02-03 10:23:52 +06:00
parent f0987614c6
commit 225c06550a

View File

@ -32,11 +32,18 @@ class FileReadKeyValueRepo(
val count = count() val count = count()
val resultPagination = if (reversed) pagination.reverse(count) else pagination val resultPagination = if (reversed) pagination.reverse(count) else pagination
val filesList = folder.list() val filesList = folder.list()
val filesPaths = filesList.copyOfRange(resultPagination.firstIndex, resultPagination.lastIndexExclusive.coerceAtMost(filesList.size)) ?: return emptyPaginationResult() val files: Array<String> = if (resultPagination.firstIndex < count) {
val filesPaths = filesList.copyOfRange(resultPagination.firstIndex, resultPagination.lastIndexExclusive.coerceAtMost(filesList.size))
if (reversed) { if (reversed) {
filesPaths.reverse() filesPaths.reversedArray()
} else {
filesPaths
} }
return filesPaths.map { File(folder, it) }.createPaginationResult( } else {
emptyArray<String>()
}
return files.map { File(folder, it) }.createPaginationResult(
resultPagination, resultPagination,
count count
) )
@ -46,11 +53,20 @@ class FileReadKeyValueRepo(
val count = count() val count = count()
val resultPagination = if (reversed) pagination.reverse(count) else pagination val resultPagination = if (reversed) pagination.reverse(count) else pagination
val filesList = folder.list() val filesList = folder.list()
val filesPaths = filesList.copyOfRange(resultPagination.firstIndex, resultPagination.lastIndexExclusive.coerceAtMost(filesList.size)) ?: return emptyPaginationResult()
val files: Array<String> = if (resultPagination.firstIndex < count) {
val filesPaths = filesList.copyOfRange(resultPagination.firstIndex, resultPagination.lastIndexExclusive.coerceAtMost(filesList.size))
if (reversed) { if (reversed) {
filesPaths.reverse() filesPaths.reversedArray()
} else {
filesPaths
} }
return filesPaths.toList().createPaginationResult( } else {
emptyArray<String>()
}
return files.toList().createPaginationResult(
resultPagination, resultPagination,
count count
) )