Skip to content

Commit 6f5bfbb

Browse files
committed
feat(e2ee): add deletion functions
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 264573e commit 6f5bfbb

3 files changed

Lines changed: 156 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.owncloud.android.lib.resources.e2ee
9+
10+
import com.nextcloud.common.NextcloudClient
11+
import com.nextcloud.operations.DeleteMethod
12+
import com.owncloud.android.lib.common.operations.RemoteOperation
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import org.apache.commons.httpclient.HttpStatus
16+
17+
class DeleteEncryptedFilesRemoteOperation : RemoteOperation<Unit>() {
18+
19+
@Deprecated("Deprecated in Java")
20+
@Suppress("Detekt.TooGenericExceptionCaught", "DEPRECATION")
21+
override fun run(client: NextcloudClient): RemoteOperationResult<Unit> {
22+
val method =
23+
DeleteMethod(uri = client.baseUri.toString() + ENCRYPTED_FILES_URL, useOcsApiRequestHeader = true)
24+
25+
return try {
26+
val status = client.execute(method)
27+
28+
if (status == HttpStatus.SC_OK) {
29+
RemoteOperationResult<Unit>(true, method)
30+
} else {
31+
RemoteOperationResult<Unit>(false, method).also {
32+
Log_OC.e(
33+
TAG,
34+
"Deleting encrypted files failed: ${method.getResponseBodyAsString()}",
35+
it.exception
36+
)
37+
}
38+
}
39+
} catch (e: Exception) {
40+
RemoteOperationResult<Unit>(e).also {
41+
Log_OC.e(TAG, "Deleting encrypted files failed: ${it.logMessage}", it.exception)
42+
}
43+
} finally {
44+
method.releaseConnection()
45+
}
46+
}
47+
48+
companion object {
49+
private val TAG = DeleteEncryptedFilesRemoteOperation::class.java.simpleName
50+
private const val ENCRYPTED_FILES_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/encrypted-files"
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.owncloud.android.lib.resources.e2ee
9+
10+
import com.nextcloud.common.NextcloudClient
11+
import com.nextcloud.operations.DeleteMethod
12+
import com.owncloud.android.lib.common.operations.RemoteOperation
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import org.apache.commons.httpclient.HttpStatus
16+
17+
class DeletePrivateKeyRemoteOperation : RemoteOperation<Unit>() {
18+
19+
@Deprecated("Deprecated in Java")
20+
@Suppress("Detekt.TooGenericExceptionCaught", "DEPRECATION")
21+
override fun run(client: NextcloudClient): RemoteOperationResult<Unit> {
22+
val method =
23+
DeleteMethod(uri = client.baseUri.toString() + PRIVATE_KEY_URL, useOcsApiRequestHeader = true)
24+
25+
return try {
26+
val status = client.execute(method)
27+
28+
if (status == HttpStatus.SC_OK) {
29+
RemoteOperationResult<Unit>(true, method)
30+
} else {
31+
RemoteOperationResult<Unit>(false, method).also {
32+
Log_OC.e(
33+
TAG,
34+
"Deleting private key failed: ${method.getResponseBodyAsString()}",
35+
it.exception
36+
)
37+
}
38+
}
39+
} catch (e: Exception) {
40+
RemoteOperationResult<Unit>(e).also {
41+
Log_OC.e(TAG, "Deleting private key failed: ${it.logMessage}", it.exception)
42+
}
43+
} finally {
44+
method.releaseConnection()
45+
}
46+
}
47+
48+
companion object {
49+
private val TAG = DeletePrivateKeyRemoteOperation::class.java.simpleName
50+
private const val PRIVATE_KEY_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/private-key"
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.owncloud.android.lib.resources.e2ee
9+
10+
import com.nextcloud.common.NextcloudClient
11+
import com.nextcloud.operations.DeleteMethod
12+
import com.owncloud.android.lib.common.operations.RemoteOperation
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import org.apache.commons.httpclient.HttpStatus
16+
17+
class DeletePublicKeyRemoteOperation : RemoteOperation<Unit>() {
18+
19+
@Deprecated("Deprecated in Java")
20+
@Suppress("Detekt.TooGenericExceptionCaught", "DEPRECATION")
21+
override fun run(client: NextcloudClient): RemoteOperationResult<Unit> {
22+
val method =
23+
DeleteMethod(uri = client.baseUri.toString() + PUBLIC_KEY_URL, useOcsApiRequestHeader = true)
24+
25+
return try {
26+
val status = client.execute(method)
27+
28+
if (status == HttpStatus.SC_OK) {
29+
RemoteOperationResult<Unit>(true, method)
30+
} else {
31+
RemoteOperationResult<Unit>(false, method).also {
32+
Log_OC.e(
33+
TAG,
34+
"Deleting public key failed: ${method.getResponseBodyAsString()}",
35+
it.exception
36+
)
37+
}
38+
}
39+
} catch (e: Exception) {
40+
RemoteOperationResult<Unit>(e).also {
41+
Log_OC.e(TAG, "Deleting public key failed: ${it.logMessage}", it.exception)
42+
}
43+
} finally {
44+
method.releaseConnection()
45+
}
46+
}
47+
48+
companion object {
49+
private val TAG = DeletePublicKeyRemoteOperation::class.java.simpleName
50+
private const val PUBLIC_KEY_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/public-key"
51+
}
52+
}

0 commit comments

Comments
 (0)