Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit cb73d53

Browse files
abelgardepJuancaG05
authored andcommitted
Allow support to read specific file from a space
1 parent 8e4f243 commit cb73d53

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ import java.util.concurrent.TimeUnit
4646
* @author David González Verdugo
4747
*/
4848

49-
class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFile>() {
49+
class ReadRemoteFileOperation(
50+
val remotePath: String,
51+
val spaceWebDavUrl: String? = null,
52+
) : RemoteOperation<RemoteFile>() {
5053

5154
/**
5255
* Performs the read operation.
@@ -57,7 +60,7 @@ class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFi
5760
override fun run(client: OwnCloudClient): RemoteOperationResult<RemoteFile> {
5861
try {
5962
val propFind = PropfindMethod(
60-
url = URL("${client.userFilesWebDavUri}${WebdavUtils.encodePath(remotePath)}"),
63+
url = getFinalWebDavUrl(),
6164
depth = DEPTH_0,
6265
propertiesToRequest = DavUtils.allPropset
6366
).apply {
@@ -69,10 +72,11 @@ class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFi
6972
Timber.i("Read remote file $remotePath with status ${propFind.statusCode}")
7073

7174
return if (isSuccess(status)) {
72-
// TODO: Remove that !!
7375
val remoteFile = RemoteFile.getRemoteFileFromDav(
74-
propFind.root!!,
75-
AccountUtils.getUserId(mAccount, mContext), mAccount.name
76+
davResource = propFind.root!!,
77+
userId = AccountUtils.getUserId(mAccount, mContext),
78+
userName = mAccount.name,
79+
spaceWebDavUrl = spaceWebDavUrl,
7680
)
7781

7882
RemoteOperationResult<RemoteFile>(RemoteOperationResult.ResultCode.OK).apply {
@@ -88,6 +92,12 @@ class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFi
8892
}
8993
}
9094

95+
private fun getFinalWebDavUrl(): URL {
96+
val baseWebDavUrl = spaceWebDavUrl ?: client.userFilesWebDavUri.toString()
97+
98+
return URL(baseWebDavUrl + WebdavUtils.encodePath(remotePath))
99+
}
100+
91101
private fun isSuccess(status: Int) = status.isOneOf(HTTP_MULTI_STATUS, HTTP_OK)
92102

93103
companion object {

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ interface FileService : Service {
5757
): RemoteOperationResult<Unit>
5858

5959
fun readFile(
60-
remotePath: String
60+
remotePath: String,
61+
spaceWebDavUrl: String? = null,
6162
): RemoteOperationResult<RemoteFile>
6263

6364
fun refreshFolder(

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
9191
).execute(client)
9292

9393
override fun readFile(
94-
remotePath: String
94+
remotePath: String,
95+
spaceWebDavUrl: String?,
9596
): RemoteOperationResult<RemoteFile> =
9697
ReadRemoteFileOperation(
97-
remotePath = remotePath
98+
remotePath = remotePath,
99+
spaceWebDavUrl = spaceWebDavUrl,
98100
).execute(client)
99101

100102
override fun refreshFolder(

0 commit comments

Comments
 (0)