From e4097555ea461a1c2bd21ef4a0ee112df6749366 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Mon, 6 Jun 2022 02:05:32 -0400 Subject: [PATCH 01/15] release 0.17.0: setup com.vanniktech.maven.publish plugin --- gradle.properties | 20 ++++++++++++++++++++ ipfs-api/build.gradle.kts | 14 +++++++++++--- settings.gradle.kts | 1 + 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index b8d590b..f9e7d5f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,23 @@ kotlin.code.style=official kotlin.native.binary.memoryModel=experimental + + +# Publishing : Required +GROUP=io.github.luca992 +VERSION_NAME=0.17.0 +POM_ARTIFACT_ID=ipfs-api + +# Publishing : Optional +POM_NAME=ipfs-api +POM_INCEPTION_YEAR=2022 +POM_URL=https://github.com/luca992/ipfs-api-kotlin +POM_SCM_URL=https://github.com/luca992/ipfs-api-kotlin +POM_SCM_CONNECTION=scm:git:git://github.com/luca992/ipfs-api-kotlin.git +POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/luca992/ipfs-api-kotlin.git +POM_LICENCE_NAME=The MIT License +POM_LICENCE_URL=http://opensource.org/licenses/MIT +POM_LICENCE_DIST=repo +POM_DEVELOPER_ID=luca992 +POM_DEVELOPER_NAME=Luca Spinazzola +POM_DEVELOPER_URL=https://github.com/luca992/ \ No newline at end of file diff --git a/ipfs-api/build.gradle.kts b/ipfs-api/build.gradle.kts index dc1e806..ffe97bd 100644 --- a/ipfs-api/build.gradle.kts +++ b/ipfs-api/build.gradle.kts @@ -3,11 +3,11 @@ plugins { kotlin("plugin.serialization") id("jacoco") id("com.github.ben-manes.versions") - id("maven-publish") + id("com.vanniktech.maven.publish") } -group = "com.github.ligi" -version = "0.16" +group = project.property("GROUP") as String +version = project.property("VERSION_NAME") as String repositories { @@ -107,4 +107,12 @@ tasks.withType { kotlinOptions { jvmTarget = "11" } +} + +plugins.withId("com.vanniktech.maven.publish.base") { + configure { + publishToMavenCentral(com.vanniktech.maven.publish.SonatypeHost.S01) + signAllPublications() + pomFromGradleProperties() + } } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index a825a67..1258aeb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,6 +11,7 @@ pluginManagement { kotlin("jvm") version "1.6.21" kotlin("plugin.serialization") version "1.6.21" id("com.github.ben-manes.versions") version "0.42.0" + id("com.vanniktech.maven.publish") version "0.19.0" } } From d6372c6f5ae1a94e1be003503ba22243d186d67d Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Mon, 6 Jun 2022 02:09:40 -0400 Subject: [PATCH 02/15] add missing description --- gradle.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle.properties b/gradle.properties index f9e7d5f..6f6c41d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,6 +10,7 @@ POM_ARTIFACT_ID=ipfs-api # Publishing : Optional POM_NAME=ipfs-api +POM_DESCRIPTION=IPFS API for kotlin to access a IPFS node via http POM_INCEPTION_YEAR=2022 POM_URL=https://github.com/luca992/ipfs-api-kotlin POM_SCM_URL=https://github.com/luca992/ipfs-api-kotlin From a4052277bfe5c5e4c3cbb93db2d1337c0c26fa85 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Thu, 7 Jul 2022 14:47:06 -0400 Subject: [PATCH 03/15] version bump --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6f6c41d..2986cdf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.native.binary.memoryModel=experimental # Publishing : Required GROUP=io.github.luca992 -VERSION_NAME=0.17.0 +VERSION_NAME=0.18.0 POM_ARTIFACT_ID=ipfs-api # Publishing : Optional From c423aafeb8691a053995b39e7cd08f4424748df9 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Thu, 7 Jul 2022 14:53:26 -0400 Subject: [PATCH 04/15] resolve warning --- .../kotlin/io/ipfs/kotlin/commands/Name.kt | 4 +- kotlin-js-store/yarn.lock | 104 ++++++++---------- 2 files changed, 48 insertions(+), 60 deletions(-) diff --git a/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Name.kt b/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Name.kt index 7fcc998..ed25ba9 100644 --- a/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Name.kt +++ b/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Name.kt @@ -20,10 +20,10 @@ class Name(val ipfs: IPFSConnection) { } suspend fun resolve(hash: String): String? { - val resultString = ipfs.callCmd("name/resolve/$hash").let { it.bodyAsText() } + val resultString = ipfs.callCmd("name/resolve/$hash").bodyAsText() return when { - resultString == null -> null + resultString.isBlank() -> null resultString.contains("Path") -> Json.decodeFromString(resultString).Path else -> { ipfs.setErrorByJSON(resultString) diff --git a/kotlin-js-store/yarn.lock b/kotlin-js-store/yarn.lock index bf8d3ce..44494f1 100644 --- a/kotlin-js-store/yarn.lock +++ b/kotlin-js-store/yarn.lock @@ -62,6 +62,13 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + braces@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" @@ -92,10 +99,10 @@ chalk@^4.1.0: ansi-styles "^4.1.0" supports-color "^7.1.0" -chokidar@3.5.2: - version "3.5.2" - resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75" - integrity sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ== +chokidar@3.5.3: + version "3.5.3" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" + integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== dependencies: anymatch "~3.1.2" braces "~3.0.2" @@ -133,10 +140,10 @@ concat-map@0.0.1: resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= -debug@4.3.2: - version "4.3.2" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b" - integrity sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw== +debug@4.3.4: + version "4.3.4" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" + integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== dependencies: ms "2.1.2" @@ -225,10 +232,10 @@ glob-parent@~5.1.2: dependencies: is-glob "^4.0.1" -glob@7.1.7: - version "7.1.7" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90" - integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ== +glob@7.2.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023" + integrity sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q== dependencies: fs.realpath "^1.0.0" inflight "^1.0.4" @@ -242,11 +249,6 @@ google-protobuf@3.12.2: resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.12.2.tgz#50ce9f9b6281235724eb243d6a83e969a2176e53" integrity sha512-4CZhpuRr1d6HjlyrxoXoocoGFnRYgKULgMtikMddA9ztRyYR59Aondv2FioyxWVamRo0rF2XpYawkTCBEQOSkA== -growl@1.10.5: - version "1.10.5" - resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e" - integrity sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA== - has-flag@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" @@ -309,11 +311,6 @@ is-unicode-supported@^0.1.0: resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7" integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw== -isexe@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" - integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= - js-yaml@4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" @@ -336,12 +333,12 @@ log-symbols@4.1.0: chalk "^4.1.0" is-unicode-supported "^0.1.0" -minimatch@3.0.4: - version "3.0.4" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" - integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== +minimatch@5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.0.1.tgz#fb9022f7528125187c92bd9e9b6366be1cf3415b" + integrity sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g== dependencies: - brace-expansion "^1.1.7" + brace-expansion "^2.0.1" minimatch@^3.0.4: version "3.1.2" @@ -350,32 +347,30 @@ minimatch@^3.0.4: dependencies: brace-expansion "^1.1.7" -mocha@9.1.2: - version "9.1.2" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-9.1.2.tgz#93f53175b0f0dc4014bd2d612218fccfcf3534d3" - integrity sha512-ta3LtJ+63RIBP03VBjMGtSqbe6cWXRejF9SyM9Zyli1CKZJZ+vfCTj3oW24V7wAphMJdpOFLoMI3hjJ1LWbs0w== +mocha@10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.0.0.tgz#205447d8993ec755335c4b13deba3d3a13c4def9" + integrity sha512-0Wl+elVUD43Y0BqPZBzZt8Tnkw9CMUdNYnUsTfOM1vuhJVZL+kiesFYsqwBkEEuEixaiPe5ZQdqDgX2jddhmoA== dependencies: "@ungap/promise-all-settled" "1.1.2" ansi-colors "4.1.1" browser-stdout "1.3.1" - chokidar "3.5.2" - debug "4.3.2" + chokidar "3.5.3" + debug "4.3.4" diff "5.0.0" escape-string-regexp "4.0.0" find-up "5.0.0" - glob "7.1.7" - growl "1.10.5" + glob "7.2.0" he "1.2.0" js-yaml "4.1.0" log-symbols "4.1.0" - minimatch "3.0.4" + minimatch "5.0.1" ms "2.1.3" - nanoid "3.1.25" + nanoid "3.3.3" serialize-javascript "6.0.0" strip-json-comments "3.1.1" supports-color "8.1.1" - which "2.0.2" - workerpool "6.1.5" + workerpool "6.2.1" yargs "16.2.0" yargs-parser "20.2.4" yargs-unparser "2.0.0" @@ -390,10 +385,10 @@ ms@2.1.3: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== -nanoid@3.1.25: - version "3.1.25" - resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.25.tgz#09ca32747c0e543f0e1814b7d3793477f9c8e152" - integrity sha512-rdwtIXaXCLFAQbnfqDRnI6jaRHp9fTcYBjtFKE8eezcZ7LuLjhUaQGNeMXf1HmRoCH32CLz6XwX0TtxEOS/A3Q== +nanoid@3.3.3: + version "3.3.3" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.3.tgz#fd8e8b7aa761fe807dba2d1b98fb7241bb724a25" + integrity sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w== node-fetch@2.6.7: version "2.6.7" @@ -474,10 +469,10 @@ serialize-javascript@6.0.0: dependencies: randombytes "^2.1.0" -source-map-support@0.5.20: - version "0.5.20" - resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.20.tgz#12166089f8f5e5e8c56926b377633392dd2cb6c9" - integrity sha512-n1lZZ8Ve4ksRqizaBQgxXDgKwttHDhyfQjA6YZZn8+AroHbsIz+JjwxQDxbp+7y5OYCI8t1Yk7etjD9CRd2hIw== +source-map-support@0.5.21: + version "0.5.21" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f" + integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w== dependencies: buffer-from "^1.0.0" source-map "^0.6.0" @@ -552,17 +547,10 @@ whatwg-url@^5.0.0: tr46 "~0.0.3" webidl-conversions "^3.0.0" -which@2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" - integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== - dependencies: - isexe "^2.0.0" - -workerpool@6.1.5: - version "6.1.5" - resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.1.5.tgz#0f7cf076b6215fd7e1da903ff6f22ddd1886b581" - integrity sha512-XdKkCK0Zqc6w3iTxLckiuJ81tiD/o5rBE/m+nXpRCB+/Sq4DqkfXZ/x0jW02DG1tGsfUGXbTJyZDP+eu67haSw== +workerpool@6.2.1: + version "6.2.1" + resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343" + integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw== wrap-ansi@^7.0.0: version "7.0.0" From b917623c0a2f9facb92840854f8f20d2fa32064d Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Thu, 7 Jul 2022 16:12:20 -0400 Subject: [PATCH 05/15] calculate progress percentage of upload and add --- gradle.properties | 2 +- .../kotlin/io/ipfs/kotlin/commands/Add.kt | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2986cdf..8bda490 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.native.binary.memoryModel=experimental # Publishing : Required GROUP=io.github.luca992 -VERSION_NAME=0.18.0 +VERSION_NAME=0.18.1 POM_ARTIFACT_ID=ipfs-api # Publishing : Optional diff --git a/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt b/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt index 0d5b15e..3cdd913 100644 --- a/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt +++ b/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt @@ -14,8 +14,12 @@ import kotlinx.serialization.json.Json import okio.BufferedSource import okio.Path -data class UploadProgress(val bytesSent: Long, val byteSize: Long) -data class AddProgress(var bytesProcessed: Long, val byteSize: Long) +data class UploadProgress(val bytesSent: Long, val byteSize: Long) { + val percentage = (bytesSent.toDouble() / byteSize.toDouble()) * 100.0 +} +data class AddProgress(var bytesProcessed: Long, val byteSize: Long) { + val percentage = (bytesProcessed.toDouble() / byteSize.toDouble()) * 100.0 +} typealias UploadAndAddProgressListener = ((UploadProgress?, AddProgress?) -> Unit) @@ -30,8 +34,8 @@ class Add(val ipfs: IPFSConnection) { file: Path, name: String = "file", filename: String = name, - progressCallback: UploadAndAddProgressListener? = null - ) = addGeneric(progressCallback) { + progressListener: UploadAndAddProgressListener? = null + ) = addGeneric(progressListener) { println(ipfs.config.fileSystem.openReadOnly(file).size()) addFile(file, name, filename) }.last() @@ -43,8 +47,8 @@ class Add(val ipfs: IPFSConnection) { source: BufferedSource, name: String = "file", filename: String = name, - progressCallback: UploadAndAddProgressListener? = null - ) = addGeneric(progressCallback) { + progressListener: UploadAndAddProgressListener? = null + ) = addGeneric(progressListener) { val encodedFileName = filename.encodeURLParameter() val headersBuilder = HeadersBuilder() headersBuilder.append(HttpHeaders.ContentDisposition, "filename=\"$encodedFileName\"") @@ -104,16 +108,16 @@ class Add(val ipfs: IPFSConnection) { } private suspend fun addGeneric( - progressCallback: UploadAndAddProgressListener?, + progressListener: UploadAndAddProgressListener?, withBuilder: FormBuilder.() -> Unit ): List { val request = MultiPartFormDataContent(formData(withBuilder)) - val progress = progressCallback != null + val progress = progressListener != null val result: List = ipfs.config.ktorClient.preparePost("${ipfs.config.base_url}add?progress=$progress") { onUpload { bytesSentTotal, contentLength -> val uploadProgress = UploadProgress(bytesSentTotal, contentLength) - progressCallback?.invoke(uploadProgress, null) + progressListener?.invoke(uploadProgress, null) } setBody(request) }.execute { httpResponse -> @@ -131,7 +135,7 @@ class Add(val ipfs: IPFSConnection) { ipfsAddProgress?.bytesProcessed = progressNamedResponse.size!!.toLong() addResults.add(progressNamedResponse) } - progressCallback?.invoke(null, ipfsAddProgress) + progressListener?.invoke(null, ipfsAddProgress) } return@execute addResults From 9acac5c22330a54c7d44a424197ead41b91c59c6 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Thu, 21 Jul 2022 13:13:57 -0400 Subject: [PATCH 06/15] Add.file: change source from BufferedSource to ByteArray. BufferedSource.readByteArray clears the source buffer. Which was not my intention --- .../src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt b/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt index 3cdd913..81f0963 100644 --- a/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt +++ b/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt @@ -36,15 +36,14 @@ class Add(val ipfs: IPFSConnection) { filename: String = name, progressListener: UploadAndAddProgressListener? = null ) = addGeneric(progressListener) { - println(ipfs.config.fileSystem.openReadOnly(file).size()) addFile(file, name, filename) }.last() /*** - * Accepts a single file's BufferedSource and returns the named hash. + * Accepts a single file's ByteArray and returns the named hash. **/ suspend fun file( - source: BufferedSource, + source: ByteArray, name: String = "file", filename: String = name, progressListener: UploadAndAddProgressListener? = null @@ -54,7 +53,7 @@ class Add(val ipfs: IPFSConnection) { headersBuilder.append(HttpHeaders.ContentDisposition, "filename=\"$encodedFileName\"") headersBuilder.append("Content-Transfer-Encoding", "binary") headersBuilder.append(HttpHeaders.ContentType, ContentType.Application.OctetStream) - append(name, source.readByteArray(), headersBuilder.build()) + append(name, source, headersBuilder.build()) }.last() From fa3cbcae10242165c29503603962de78ac9e4836 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Thu, 21 Jul 2022 13:14:10 -0400 Subject: [PATCH 07/15] version bump --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 8bda490..53b978d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.native.binary.memoryModel=experimental # Publishing : Required GROUP=io.github.luca992 -VERSION_NAME=0.18.1 +VERSION_NAME=0.19.0 POM_ARTIFACT_ID=ipfs-api # Publishing : Optional From 1f5f1631f1e86cd450542f120388dd1b0d11b75b Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Sat, 23 Jul 2022 19:05:07 -0400 Subject: [PATCH 08/15] fix add progress callback --- .../kotlin/io/ipfs/kotlin/commands/Add.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt b/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt index 81f0963..0db04a8 100644 --- a/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt +++ b/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/commands/Add.kt @@ -17,7 +17,7 @@ import okio.Path data class UploadProgress(val bytesSent: Long, val byteSize: Long) { val percentage = (bytesSent.toDouble() / byteSize.toDouble()) * 100.0 } -data class AddProgress(var bytesProcessed: Long, val byteSize: Long) { +data class AddProgress(val bytesProcessed: Long, val byteSize: Long) { val percentage = (bytesProcessed.toDouble() / byteSize.toDouble()) * 100.0 } @@ -121,18 +121,20 @@ class Add(val ipfs: IPFSConnection) { setBody(request) }.execute { httpResponse -> // todo: figure out how to calculate the total size returned by ipfs before add completion. This isn't really correct to set byteSize with content length. Ipfs returns a slightly larger final number - val ipfsAddProgress = - httpResponse.call.request.content.contentLength?.let { AddProgress(0, it) } + val contentLength = + httpResponse.call.request.content.contentLength val addResults = mutableListOf() val channel = httpResponse.bodyAsChannel() while (!channel.isClosedForRead) { val progressNamedResponse: NamedResponse? = channel.readUTF8Line()?.let { Json.decodeFromString(it) } - if (progressNamedResponse?.bytes != null) { - ipfsAddProgress?.bytesProcessed = progressNamedResponse.bytes + val ipfsAddProgress = if (progressNamedResponse?.bytes != null) { + contentLength?.let { AddProgress(progressNamedResponse.bytes, it) } } else if (progressNamedResponse?.hash != null) { - ipfsAddProgress?.bytesProcessed = progressNamedResponse.size!!.toLong() addResults.add(progressNamedResponse) + contentLength?.let { AddProgress(progressNamedResponse.size!!.toLong(), it) } + } else { + null } progressListener?.invoke(null, ipfsAddProgress) } From f782bf1549ee93269fd18990c4cc3b53a3501b06 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Sat, 23 Jul 2022 19:05:30 -0400 Subject: [PATCH 09/15] version bump --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 53b978d..2668680 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.native.binary.memoryModel=experimental # Publishing : Required GROUP=io.github.luca992 -VERSION_NAME=0.19.0 +VERSION_NAME=0.19.1 POM_ARTIFACT_ID=ipfs-api # Publishing : Optional From a2d1650fe8d59876aa706a1247d2a78c6f8b8825 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Fri, 5 Aug 2022 23:44:13 -0400 Subject: [PATCH 10/15] version bump --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 2668680..a6ec54d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.native.binary.memoryModel=experimental # Publishing : Required GROUP=io.github.luca992 -VERSION_NAME=0.19.1 +VERSION_NAME=0.19.2 POM_ARTIFACT_ID=ipfs-api # Publishing : Optional From e89ed1e01f6e9770a5ebcf5a4d46dc7401fa7bb3 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Sat, 13 Aug 2022 02:06:51 -0400 Subject: [PATCH 11/15] version bump --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index a6ec54d..f2bcc26 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.native.binary.memoryModel=experimental # Publishing : Required GROUP=io.github.luca992 -VERSION_NAME=0.19.2 +VERSION_NAME=0.20.0 POM_ARTIFACT_ID=ipfs-api # Publishing : Optional From a3ca10b84bd390004167365de9eb6cb8326a480b Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Sat, 13 Aug 2022 18:28:23 -0400 Subject: [PATCH 12/15] workaround for SocketTimeoutException https://youtrack.jetbrains.com/issue/KTOR-3840/OkHttp-Socket-timeouts-without-timeout-configured --- .../commonMain/kotlin/io/ipfs/kotlin/defaults/Defaults.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/defaults/Defaults.kt b/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/defaults/Defaults.kt index e05a9a5..5e39fdc 100644 --- a/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/defaults/Defaults.kt +++ b/ipfs-api/src/commonMain/kotlin/io/ipfs/kotlin/defaults/Defaults.kt @@ -1,6 +1,7 @@ package io.ipfs.kotlin.defaults import io.ktor.client.* +import io.ktor.client.plugins.* import io.ktor.client.plugins.contentnegotiation.* import io.ktor.serialization.kotlinx.json.* import kotlinx.serialization.json.Json @@ -13,8 +14,12 @@ internal fun createKTOR() = HttpClient { ignoreUnknownKeys = true }) } + install(HttpTimeout) { + // this socketTimeout can occur w/ okhttp engine when posting larger file + socketTimeoutMillis = 600_000 // 10 minutes + } } -expect internal fun createFileSystem() : FileSystem +expect internal fun createFileSystem(): FileSystem From 9d6ac72b9f5ddbeee75f7cbe49b44d2a45e23332 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Sat, 13 Aug 2022 18:30:03 -0400 Subject: [PATCH 13/15] version bump --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f2bcc26..9a5576a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.native.binary.memoryModel=experimental # Publishing : Required GROUP=io.github.luca992 -VERSION_NAME=0.20.0 +VERSION_NAME=0.20.1 POM_ARTIFACT_ID=ipfs-api # Publishing : Optional From e42d9b767cd080da502b1eb33a65f1be1a3e19ad Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Sat, 13 Aug 2022 19:02:28 -0400 Subject: [PATCH 14/15] update ktor and com.vanniktech.maven.publish --- buildSrc/src/main/kotlin/Versions.kt | 2 +- settings.gradle.kts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index fe5b10e..ca69032 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -5,6 +5,6 @@ object Versions { const val jupiter = "5.6.2" const val okhttp = "4.10.0" const val coroutines = "1.6.4" - const val ktor = "2.0.3" + const val ktor = "2.1.0" const val okio = "3.2.0" } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index b30ca81..21a74ee 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,7 +11,7 @@ pluginManagement { kotlin("jvm") version "1.7.10" kotlin("plugin.serialization") version "1.7.10" id("com.github.ben-manes.versions") version "0.42.0" - id("com.vanniktech.maven.publish") version "0.19.0" + id("com.vanniktech.maven.publish") version "0.21.0" } } From 089984a24e06e5ab108bf09d2b686e8328bef5fe Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Sat, 13 Aug 2022 19:02:34 -0400 Subject: [PATCH 15/15] version bump --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 9a5576a..82de7c3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.native.binary.memoryModel=experimental # Publishing : Required GROUP=io.github.luca992 -VERSION_NAME=0.20.1 +VERSION_NAME=0.20.2 POM_ARTIFACT_ID=ipfs-api # Publishing : Optional