mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 07:56:19 +00:00
Allow support to read specific file from a space
This commit is contained in:
parent
8e4f243031
commit
cb73d537e4
@ -46,7 +46,10 @@ import java.util.concurrent.TimeUnit
|
||||
* @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.
|
||||
@ -57,7 +60,7 @@ class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFi
|
||||
override fun run(client: OwnCloudClient): RemoteOperationResult<RemoteFile> {
|
||||
try {
|
||||
val propFind = PropfindMethod(
|
||||
url = URL("${client.userFilesWebDavUri}${WebdavUtils.encodePath(remotePath)}"),
|
||||
url = getFinalWebDavUrl(),
|
||||
depth = DEPTH_0,
|
||||
propertiesToRequest = DavUtils.allPropset
|
||||
).apply {
|
||||
@ -69,10 +72,11 @@ class ReadRemoteFileOperation(val remotePath: String) : RemoteOperation<RemoteFi
|
||||
Timber.i("Read remote file $remotePath with status ${propFind.statusCode}")
|
||||
|
||||
return if (isSuccess(status)) {
|
||||
// TODO: Remove that !!
|
||||
val remoteFile = RemoteFile.getRemoteFileFromDav(
|
||||
propFind.root!!,
|
||||
AccountUtils.getUserId(mAccount, mContext), mAccount.name
|
||||
davResource = propFind.root!!,
|
||||
userId = AccountUtils.getUserId(mAccount, mContext),
|
||||
userName = mAccount.name,
|
||||
spaceWebDavUrl = spaceWebDavUrl,
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
companion object {
|
||||
|
@ -57,7 +57,8 @@ interface FileService : Service {
|
||||
): RemoteOperationResult<Unit>
|
||||
|
||||
fun readFile(
|
||||
remotePath: String
|
||||
remotePath: String,
|
||||
spaceWebDavUrl: String? = null,
|
||||
): RemoteOperationResult<RemoteFile>
|
||||
|
||||
fun refreshFolder(
|
||||
|
@ -91,10 +91,12 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
|
||||
).execute(client)
|
||||
|
||||
override fun readFile(
|
||||
remotePath: String
|
||||
remotePath: String,
|
||||
spaceWebDavUrl: String?,
|
||||
): RemoteOperationResult<RemoteFile> =
|
||||
ReadRemoteFileOperation(
|
||||
remotePath = remotePath
|
||||
remotePath = remotePath,
|
||||
spaceWebDavUrl = spaceWebDavUrl,
|
||||
).execute(client)
|
||||
|
||||
override fun refreshFolder(
|
||||
|
Loading…
x
Reference in New Issue
Block a user