1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Allow support to read specific file from a space

This commit is contained in:
Abel García de Prada 2023-01-17 18:55:35 +01:00 committed by Juan Carlos Garrote
parent 8e4f243031
commit cb73d537e4
3 changed files with 21 additions and 8 deletions

View File

@ -46,7 +46,10 @@ import java.util.concurrent.TimeUnit
* @author David González Verdugo * @author David González Verdugo
*/ */
class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFile>() { class ReadRemoteFileOperation(
val remotePath: String,
val spaceWebDavUrl: String? = null,
) : RemoteOperation<RemoteFile>() {
/** /**
* Performs the read operation. * Performs the read operation.
@ -57,7 +60,7 @@ class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFi
override fun run(client: OwnCloudClient): RemoteOperationResult<RemoteFile> { override fun run(client: OwnCloudClient): RemoteOperationResult<RemoteFile> {
try { try {
val propFind = PropfindMethod( val propFind = PropfindMethod(
url = URL("${client.userFilesWebDavUri}${WebdavUtils.encodePath(remotePath)}"), url = getFinalWebDavUrl(),
depth = DEPTH_0, depth = DEPTH_0,
propertiesToRequest = DavUtils.allPropset propertiesToRequest = DavUtils.allPropset
).apply { ).apply {
@ -69,10 +72,11 @@ class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFi
Timber.i("Read remote file $remotePath with status ${propFind.statusCode}") Timber.i("Read remote file $remotePath with status ${propFind.statusCode}")
return if (isSuccess(status)) { return if (isSuccess(status)) {
// TODO: Remove that !!
val remoteFile = RemoteFile.getRemoteFileFromDav( val remoteFile = RemoteFile.getRemoteFileFromDav(
propFind.root!!, davResource = propFind.root!!,
AccountUtils.getUserId(mAccount, mContext), mAccount.name userId = AccountUtils.getUserId(mAccount, mContext),
userName = mAccount.name,
spaceWebDavUrl = spaceWebDavUrl,
) )
RemoteOperationResult<RemoteFile>(RemoteOperationResult.ResultCode.OK).apply { RemoteOperationResult<RemoteFile>(RemoteOperationResult.ResultCode.OK).apply {
@ -88,6 +92,12 @@ class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFi
} }
} }
private fun getFinalWebDavUrl(): URL {
val baseWebDavUrl = spaceWebDavUrl ?: client.userFilesWebDavUri.toString()
return URL(baseWebDavUrl + WebdavUtils.encodePath(remotePath))
}
private fun isSuccess(status: Int) = status.isOneOf(HTTP_MULTI_STATUS, HTTP_OK) private fun isSuccess(status: Int) = status.isOneOf(HTTP_MULTI_STATUS, HTTP_OK)
companion object { companion object {

View File

@ -57,7 +57,8 @@ interface FileService : Service {
): RemoteOperationResult<Unit> ): RemoteOperationResult<Unit>
fun readFile( fun readFile(
remotePath: String remotePath: String,
spaceWebDavUrl: String? = null,
): RemoteOperationResult<RemoteFile> ): RemoteOperationResult<RemoteFile>
fun refreshFolder( fun refreshFolder(

View File

@ -91,10 +91,12 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
).execute(client) ).execute(client)
override fun readFile( override fun readFile(
remotePath: String remotePath: String,
spaceWebDavUrl: String?,
): RemoteOperationResult<RemoteFile> = ): RemoteOperationResult<RemoteFile> =
ReadRemoteFileOperation( ReadRemoteFileOperation(
remotePath = remotePath remotePath = remotePath,
spaceWebDavUrl = spaceWebDavUrl,
).execute(client) ).execute(client)
override fun refreshFolder( override fun refreshFolder(