diff --git a/build.gradle.kts b/build.gradle.kts index 0073ce9..b9a27ab 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "1.6.10" + kotlin("jvm") version "1.8.22" application } @@ -13,15 +13,11 @@ repositories { maven("https://maven.pkg.jetbrains.space/public/p/space/maven") } -val ktorVersion = "1.6.4" - dependencies { - implementation("io.ktor:ktor-client-core:$ktorVersion") - implementation("io.ktor:ktor-client-cio:$ktorVersion") - implementation("io.ktor:ktor-client-auth:$ktorVersion") - implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.4") - implementation("org.jetbrains:space-sdk-jvm:98244-beta") - implementation("ch.qos.logback:logback-classic:1.2.10") + implementation("org.jetbrains:space-sdk-jvm:159302-beta") + implementation("io.ktor:ktor-client-cio-jvm:2.3.1") + implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.5") + implementation("ch.qos.logback:logback-classic:1.4.8") testImplementation(kotlin("test")) } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aa991fc..fae0804 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/main.kt b/src/main/kotlin/main.kt index 08dc731..c638508 100644 --- a/src/main/kotlin/main.kt +++ b/src/main/kotlin/main.kt @@ -14,6 +14,7 @@ import space.jetbrains.api.runtime.types.FolderIdentifier import space.jetbrains.api.runtime.types.ProjectIdentifier import java.nio.file.Files import java.nio.file.Path +import kotlin.io.path.Path suspend fun main(args: Array) { val parser = ArgParser("space-document-extractor") @@ -47,7 +48,7 @@ suspend fun main(args: Array) { parser.parse(args) - val target: Path = path?.let { Path.of(path) } ?: Path.of("output/$project") + val target: Path = path?.let { Path(it) } ?: Path.of("output/$project") Files.createDirectories(target) diff --git a/src/main/kotlin/process.kt b/src/main/kotlin/process.kt index def3c1f..2b8fcb0 100644 --- a/src/main/kotlin/process.kt +++ b/src/main/kotlin/process.kt @@ -4,6 +4,7 @@ import io.ktor.client.request.header import io.ktor.client.request.request import io.ktor.client.request.url import io.ktor.client.statement.HttpResponse +import io.ktor.client.statement.bodyAsChannel import io.ktor.client.statement.readBytes import io.ktor.http.HttpHeaders import io.ktor.http.HttpMethod @@ -33,7 +34,7 @@ internal suspend fun SpaceClient.extractImage( imageFileName: String, ) { logger.info("Downloading image file $imageFileName to $parent") - val response = ktorClient.request { + val response = ktorClient.request { url("${server.serverUrl}/d/$imageId") method = HttpMethod.Get header(HttpHeaders.Authorization, "Bearer ${token().accessToken}") @@ -53,14 +54,14 @@ internal suspend fun SpaceClient.extractFile( ) { //https://mipt-npm.jetbrains.space/drive/files/3qe9i43qtPq2 logger.info("Downloading document file $documentFileName to $parent") - val response = ktorClient.request { + val response = ktorClient.request { url("${server.serverUrl}/drive/files/$documentId") method = HttpMethod.Get header(HttpHeaders.Authorization, "Bearer ${token().accessToken}") } val file = parent.resolve(documentFileName) file.outputStream().use { - response.content.copyTo(it) + response.bodyAsChannel().copyTo(it) } }