File name fix

This commit is contained in:
Alexander Nozik 2023-09-03 20:48:29 +03:00
parent 46e3fb966c
commit 209a6db5fc

View File

@ -56,6 +56,7 @@ internal suspend fun SpaceClient.extractFile(
}
private val imageRegex = """!\[(?<alt>.*)]\(/d/(?<id>.*)\?f=0( "(?<name>.*)")?\)""".toRegex()
private val fileNameRegex = "\\W+".toRegex()
/**
* Download single Space document
@ -90,7 +91,8 @@ internal suspend fun SpaceClient.downloadDocument(
val id = it.groups["id"]?.value ?: error("Unexpected reference format: ${it.value}")
val alt = it.groups["alt"]?.value?.ifBlank { null }
val name = it.groups["name"]?.value?.ifBlank { null }
val imageName = name?.let { "$id-$name" } ?: alt?.let { "$id-$alt" } ?: id
val imageName = (name?.let { "$id-$name" } ?: alt?.let { "$id-$alt" } ?: id)
.replace(fileNameRegex, "_")
val imageFile = imageDirectory.resolve(imageName)
logger.info("Downloading image $id as $imageFile")
launch(Dispatchers.IO) {
@ -131,6 +133,7 @@ internal suspend fun SpaceClient.downloadDocumentFolder(
documents.data.forEach {
val document = projects.documents.getDocument(projectId, it.id) {
body()
bodyType()
title()
id()
}
@ -146,6 +149,7 @@ internal suspend fun SpaceClient.downloadDocumentFolder(
)
) {
body()
bodyType()
title()
id()
}