mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Merge pull request #530 from owncloud/spaces/main
[SPACES] Main features
This commit is contained in:
commit
0e9f9c6391
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2020 ownCloud GmbH.
|
* Copyright (C) 2023 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -41,6 +41,7 @@ import java.util.concurrent.TimeUnit
|
|||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
* @author Abel García de Prada
|
* @author Abel García de Prada
|
||||||
|
* @author Juan Carlos Garrote Gascón
|
||||||
*
|
*
|
||||||
* @param remotePath Path to append to the URL owned by the client instance.
|
* @param remotePath Path to append to the URL owned by the client instance.
|
||||||
* @param isUserLoggedIn When `true`, the username won't be added at the end of the PROPFIND url since is not
|
* @param isUserLoggedIn When `true`, the username won't be added at the end of the PROPFIND url since is not
|
||||||
@ -48,21 +49,22 @@ import java.util.concurrent.TimeUnit
|
|||||||
*/
|
*/
|
||||||
class CheckPathExistenceRemoteOperation(
|
class CheckPathExistenceRemoteOperation(
|
||||||
val remotePath: String? = "",
|
val remotePath: String? = "",
|
||||||
val isUserLoggedIn: Boolean
|
val isUserLoggedIn: Boolean,
|
||||||
|
val spaceWebDavUrl: String? = null,
|
||||||
) : RemoteOperation<Boolean>() {
|
) : RemoteOperation<Boolean>() {
|
||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Boolean> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<Boolean> {
|
||||||
return try {
|
val baseStringUrl = spaceWebDavUrl ?: if (isUserLoggedIn) client.baseFilesWebDavUri.toString()
|
||||||
val stringUrl =
|
else client.userFilesWebDavUri.toString()
|
||||||
if (isUserLoggedIn) client.baseFilesWebDavUri.toString()
|
val stringUrl = baseStringUrl + WebdavUtils.encodePath(remotePath)
|
||||||
else client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath)
|
|
||||||
|
|
||||||
|
return try {
|
||||||
val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropset).apply {
|
val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropset).apply {
|
||||||
setReadTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
|
setReadTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
|
||||||
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
|
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
|
||||||
}
|
}
|
||||||
|
|
||||||
var status = client.executeHttpMethod(propFindMethod)
|
val status = client.executeHttpMethod(propFindMethod)
|
||||||
/* PROPFIND method
|
/* PROPFIND method
|
||||||
* 404 NOT FOUND: path doesn't exist,
|
* 404 NOT FOUND: path doesn't exist,
|
||||||
* 207 MULTI_STATUS: path exists.
|
* 207 MULTI_STATUS: path exists.
|
||||||
@ -77,7 +79,7 @@ class CheckPathExistenceRemoteOperation(
|
|||||||
val result = RemoteOperationResult<Boolean>(e)
|
val result = RemoteOperationResult<Boolean>(e)
|
||||||
Timber.e(
|
Timber.e(
|
||||||
e,
|
e,
|
||||||
"Existence check for ${client.userFilesWebDavUri}${WebdavUtils.encodePath(remotePath)} : ${result.logMessage}"
|
"Existence check for $stringUrl : ${result.logMessage}"
|
||||||
)
|
)
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* Copyright (C) 2023 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -44,25 +44,29 @@ import java.util.concurrent.TimeUnit
|
|||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* @author Christian Schabesberger
|
* @author Christian Schabesberger
|
||||||
* @author David González V.
|
* @author David González V.
|
||||||
|
* @author Juan Carlos Garrote Gascón
|
||||||
*
|
*
|
||||||
* @param srcRemotePath Remote path of the file/folder to copy.
|
* @param sourceRemotePath Remote path of the file/folder to copy.
|
||||||
* @param targetRemotePath Remote path desired for the file/folder to copy it.
|
* @param targetRemotePath Remote path desired for the file/folder to copy it.
|
||||||
*/
|
*/
|
||||||
class CopyRemoteFileOperation(
|
class CopyRemoteFileOperation(
|
||||||
private val srcRemotePath: String,
|
private val sourceRemotePath: String,
|
||||||
private val targetRemotePath: String,
|
private val targetRemotePath: String,
|
||||||
|
private val sourceSpaceWebDavUrl: String? = null,
|
||||||
|
private val targetSpaceWebDavUrl: String? = null,
|
||||||
) : RemoteOperation<String>() {
|
) : RemoteOperation<String>() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the rename operation.
|
* Performs the rename operation.
|
||||||
*
|
*
|
||||||
* @param client Client object to communicate with the remote ownCloud server.
|
* @param client Client object to communicate with the remote ownCloud server.
|
||||||
*/
|
*/
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<String> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<String> {
|
||||||
if (targetRemotePath == srcRemotePath) {
|
if (targetRemotePath == sourceRemotePath && sourceSpaceWebDavUrl == targetSpaceWebDavUrl) {
|
||||||
// nothing to do!
|
// nothing to do!
|
||||||
return RemoteOperationResult(ResultCode.OK)
|
return RemoteOperationResult(ResultCode.OK)
|
||||||
}
|
}
|
||||||
if (targetRemotePath.startsWith(srcRemotePath)) {
|
if (targetRemotePath.startsWith(sourceRemotePath) && sourceSpaceWebDavUrl == targetSpaceWebDavUrl) {
|
||||||
return RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT)
|
return RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +74,8 @@ class CopyRemoteFileOperation(
|
|||||||
var result: RemoteOperationResult<String>
|
var result: RemoteOperationResult<String>
|
||||||
try {
|
try {
|
||||||
val copyMethod = CopyMethod(
|
val copyMethod = CopyMethod(
|
||||||
URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(srcRemotePath)),
|
URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
|
||||||
client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(targetRemotePath),
|
(targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
|
||||||
).apply {
|
).apply {
|
||||||
setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS)
|
setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS)
|
||||||
setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
||||||
@ -95,10 +99,10 @@ class CopyRemoteFileOperation(
|
|||||||
client.exhaustResponse(copyMethod.getResponseBodyAsStream())
|
client.exhaustResponse(copyMethod.getResponseBodyAsStream())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Timber.i("Copy $srcRemotePath to $targetRemotePath: ${result.logMessage}")
|
Timber.i("Copy $sourceRemotePath to $targetRemotePath: ${result.logMessage}")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
result = RemoteOperationResult(e)
|
result = RemoteOperationResult(e)
|
||||||
Timber.e(e, "Copy $srcRemotePath to $targetRemotePath: ${result.logMessage}")
|
Timber.e(e, "Copy $sourceRemotePath to $targetRemotePath: ${result.logMessage}")
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,8 @@ import java.util.concurrent.TimeUnit
|
|||||||
class CreateRemoteFolderOperation(
|
class CreateRemoteFolderOperation(
|
||||||
val remotePath: String,
|
val remotePath: String,
|
||||||
private val createFullPath: Boolean,
|
private val createFullPath: Boolean,
|
||||||
private val isChunksFolder: Boolean = false
|
private val isChunksFolder: Boolean = false,
|
||||||
|
val spaceWebDavUrl: String? = null,
|
||||||
) : RemoteOperation<Unit>() {
|
) : RemoteOperation<Unit>() {
|
||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
||||||
@ -67,13 +68,13 @@ class CreateRemoteFolderOperation(
|
|||||||
var result: RemoteOperationResult<Unit>
|
var result: RemoteOperationResult<Unit>
|
||||||
try {
|
try {
|
||||||
val webDavUri = if (isChunksFolder) {
|
val webDavUri = if (isChunksFolder) {
|
||||||
client.uploadsWebDavUri
|
client.uploadsWebDavUri.toString()
|
||||||
} else {
|
} else {
|
||||||
client.userFilesWebDavUri
|
spaceWebDavUrl ?: client.userFilesWebDavUri.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
val mkCol = MkColMethod(
|
val mkCol = MkColMethod(
|
||||||
URL(webDavUri.toString() + WebdavUtils.encodePath(remotePath))
|
URL(webDavUri + WebdavUtils.encodePath(remotePath))
|
||||||
).apply {
|
).apply {
|
||||||
setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
|
setReadTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
|
||||||
setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
setConnectionTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
||||||
|
@ -36,7 +36,6 @@ import java.io.BufferedInputStream
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.HashSet
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +46,8 @@ import java.util.concurrent.atomic.AtomicBoolean
|
|||||||
*/
|
*/
|
||||||
class DownloadRemoteFileOperation(
|
class DownloadRemoteFileOperation(
|
||||||
private val remotePath: String,
|
private val remotePath: String,
|
||||||
localFolderPath: String
|
localFolderPath: String,
|
||||||
|
private val spaceWebDavUrl: String? = null,
|
||||||
) : RemoteOperation<Unit>() {
|
) : RemoteOperation<Unit>() {
|
||||||
|
|
||||||
private val cancellationRequested = AtomicBoolean(false)
|
private val cancellationRequested = AtomicBoolean(false)
|
||||||
@ -84,7 +84,8 @@ class DownloadRemoteFileOperation(
|
|||||||
var bis: BufferedInputStream? = null
|
var bis: BufferedInputStream? = null
|
||||||
var savedFile = false
|
var savedFile = false
|
||||||
|
|
||||||
val getMethod = GetMethod(URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath)))
|
val webDavUri = spaceWebDavUrl ?: client.userFilesWebDavUri.toString()
|
||||||
|
val getMethod = GetMethod(URL(webDavUri + WebdavUtils.encodePath(remotePath)))
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val status = client.executeHttpMethod(getMethod)
|
val status = client.executeHttpMethod(getMethod)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2021 ownCloud GmbH.
|
* Copyright (C) 2023 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -38,17 +38,22 @@ import java.util.concurrent.TimeUnit
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
* Remote operation moving a remote file or folder in the ownCloud server to a different folder
|
||||||
* in the same account.
|
* in the same account and space.
|
||||||
*
|
*
|
||||||
* Allows renaming the moving file/folder at the same time.
|
* Allows renaming the moving file/folder at the same time.
|
||||||
*
|
*
|
||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
* @author Abel García de Prada
|
* @author Abel García de Prada
|
||||||
|
* @author Juan Carlos Garrote Gascón
|
||||||
|
*
|
||||||
|
* @param sourceRemotePath Remote path of the file/folder to copy.
|
||||||
|
* @param targetRemotePath Remote path desired for the file/folder to copy it.
|
||||||
*/
|
*/
|
||||||
open class MoveRemoteFileOperation(
|
open class MoveRemoteFileOperation(
|
||||||
private val sourceRemotePath: String,
|
private val sourceRemotePath: String,
|
||||||
private val targetRemotePath: String,
|
private val targetRemotePath: String,
|
||||||
|
private val spaceWebDavUrl: String? = null,
|
||||||
) : RemoteOperation<Unit>() {
|
) : RemoteOperation<Unit>() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,8 +78,8 @@ open class MoveRemoteFileOperation(
|
|||||||
// so this uri has to be customizable
|
// so this uri has to be customizable
|
||||||
val srcWebDavUri = getSrcWebDavUriForClient(client)
|
val srcWebDavUri = getSrcWebDavUriForClient(client)
|
||||||
val moveMethod = MoveMethod(
|
val moveMethod = MoveMethod(
|
||||||
url = URL(srcWebDavUri.toString() + WebdavUtils.encodePath(sourceRemotePath)),
|
url = URL((spaceWebDavUrl ?: srcWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
|
||||||
destinationUrl = client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(targetRemotePath),
|
destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
|
||||||
).apply {
|
).apply {
|
||||||
addRequestHeaders(this)
|
addRequestHeaders(this)
|
||||||
setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS)
|
setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS)
|
||||||
|
@ -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 {
|
||||||
|
@ -48,7 +48,8 @@ import java.net.URL
|
|||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
*/
|
*/
|
||||||
class ReadRemoteFolderOperation(
|
class ReadRemoteFolderOperation(
|
||||||
val remotePath: String
|
val remotePath: String,
|
||||||
|
val spaceWebDavUrl: String? = null,
|
||||||
) : RemoteOperation<ArrayList<RemoteFile>>() {
|
) : RemoteOperation<ArrayList<RemoteFile>>() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,7 +62,7 @@ class ReadRemoteFolderOperation(
|
|||||||
PropertyRegistry.register(OCShareTypes.Factory())
|
PropertyRegistry.register(OCShareTypes.Factory())
|
||||||
|
|
||||||
val propfindMethod = PropfindMethod(
|
val propfindMethod = PropfindMethod(
|
||||||
URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath)),
|
getFinalWebDavUrl(),
|
||||||
DavConstants.DEPTH_1,
|
DavConstants.DEPTH_1,
|
||||||
DavUtils.allPropset
|
DavUtils.allPropset
|
||||||
)
|
)
|
||||||
@ -71,12 +72,11 @@ class ReadRemoteFolderOperation(
|
|||||||
if (isSuccess(status)) {
|
if (isSuccess(status)) {
|
||||||
val mFolderAndFiles = ArrayList<RemoteFile>()
|
val mFolderAndFiles = ArrayList<RemoteFile>()
|
||||||
|
|
||||||
// parse data from remote folder
|
|
||||||
// TODO: Remove that !!
|
|
||||||
val remoteFolder = RemoteFile.getRemoteFileFromDav(
|
val remoteFolder = RemoteFile.getRemoteFileFromDav(
|
||||||
davResource = propfindMethod.root!!,
|
davResource = propfindMethod.root!!,
|
||||||
userId = AccountUtils.getUserId(mAccount, mContext),
|
userId = AccountUtils.getUserId(mAccount, mContext),
|
||||||
userName = mAccount.name
|
userName = mAccount.name,
|
||||||
|
spaceWebDavUrl = spaceWebDavUrl,
|
||||||
)
|
)
|
||||||
mFolderAndFiles.add(remoteFolder)
|
mFolderAndFiles.add(remoteFolder)
|
||||||
|
|
||||||
@ -85,7 +85,8 @@ class ReadRemoteFolderOperation(
|
|||||||
val remoteFile = RemoteFile.getRemoteFileFromDav(
|
val remoteFile = RemoteFile.getRemoteFileFromDav(
|
||||||
davResource = resource,
|
davResource = resource,
|
||||||
userId = AccountUtils.getUserId(mAccount, mContext),
|
userId = AccountUtils.getUserId(mAccount, mContext),
|
||||||
userName = mAccount.name
|
userName = mAccount.name,
|
||||||
|
spaceWebDavUrl = spaceWebDavUrl,
|
||||||
)
|
)
|
||||||
mFolderAndFiles.add(remoteFile)
|
mFolderAndFiles.add(remoteFile)
|
||||||
}
|
}
|
||||||
@ -107,5 +108,11 @@ class ReadRemoteFolderOperation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getFinalWebDavUrl(): URL {
|
||||||
|
val baseWebDavUrl = spaceWebDavUrl ?: client.userFilesWebDavUri.toString()
|
||||||
|
|
||||||
|
return URL(baseWebDavUrl + WebdavUtils.encodePath(remotePath))
|
||||||
|
}
|
||||||
|
|
||||||
private fun isSuccess(status: Int): Boolean = status.isOneOf(HTTP_OK, HTTP_MULTI_STATUS)
|
private fun isSuccess(status: Int): Boolean = status.isOneOf(HTTP_OK, HTTP_MULTI_STATUS)
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ package com.owncloud.android.lib.resources.files
|
|||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
|
import androidx.annotation.VisibleForTesting
|
||||||
import at.bitfire.dav4jvm.PropStat
|
import at.bitfire.dav4jvm.PropStat
|
||||||
import at.bitfire.dav4jvm.Property
|
import at.bitfire.dav4jvm.Property
|
||||||
import at.bitfire.dav4jvm.Response
|
import at.bitfire.dav4jvm.Response
|
||||||
@ -100,8 +101,13 @@ data class RemoteFile(
|
|||||||
const val MIME_DIR = "DIR"
|
const val MIME_DIR = "DIR"
|
||||||
const val MIME_DIR_UNIX = "httpd/unix-directory"
|
const val MIME_DIR_UNIX = "httpd/unix-directory"
|
||||||
|
|
||||||
fun getRemoteFileFromDav(davResource: Response, userId: String, userName: String): RemoteFile {
|
fun getRemoteFileFromDav(
|
||||||
val remotePath = getRemotePathFromUrl(davResource.href, userId)
|
davResource: Response,
|
||||||
|
userId: String,
|
||||||
|
userName: String,
|
||||||
|
spaceWebDavUrl: String? = null
|
||||||
|
): RemoteFile {
|
||||||
|
val remotePath = getRemotePathFromUrl(davResource.href, userId, spaceWebDavUrl)
|
||||||
val remoteFile = RemoteFile(remotePath = remotePath, owner = userName)
|
val remoteFile = RemoteFile(remotePath = remotePath, owner = userName)
|
||||||
val properties = getPropertiesEvenIfPostProcessing(davResource)
|
val properties = getPropertiesEvenIfPostProcessing(davResource)
|
||||||
|
|
||||||
@ -164,15 +170,25 @@ data class RemoteFile(
|
|||||||
* Retrieves a relative path from a remote file url
|
* Retrieves a relative path from a remote file url
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Example: url:port/remote.php/dav/files/username/Documents/text.txt => /Documents/text.txt
|
* Example legacy:
|
||||||
|
* /remote.php/dav/files/username/Documents/text.txt => /Documents/text.txt
|
||||||
|
*
|
||||||
|
* Example spaces:
|
||||||
|
* /dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f38$05bca744-d89f-4e9c-a990-25a0d7f03fe9/Documents/text.txt => /Documents/text.txt
|
||||||
*
|
*
|
||||||
* @param url remote file url
|
* @param url remote file url
|
||||||
* @param userId file owner
|
* @param userId file owner
|
||||||
|
* @param spaceWebDavUrl custom web dav url for space
|
||||||
* @return remote relative path of the file
|
* @return remote relative path of the file
|
||||||
*/
|
*/
|
||||||
private fun getRemotePathFromUrl(url: HttpUrl, userId: String): String {
|
@VisibleForTesting
|
||||||
val davFilesPath = OwnCloudClient.WEBDAV_FILES_PATH_4_0 + userId
|
fun getRemotePathFromUrl(
|
||||||
val absoluteDavPath = Uri.decode(url.encodedPath)
|
url: HttpUrl,
|
||||||
|
userId: String,
|
||||||
|
spaceWebDavUrl: String? = null,
|
||||||
|
): String {
|
||||||
|
val davFilesPath = spaceWebDavUrl ?: (OwnCloudClient.WEBDAV_FILES_PATH_4_0 + userId)
|
||||||
|
val absoluteDavPath = if (spaceWebDavUrl != null) Uri.decode(url.toString()) else Uri.decode(url.encodedPath)
|
||||||
val pathToOc = absoluteDavPath.split(davFilesPath).first()
|
val pathToOc = absoluteDavPath.split(davFilesPath).first()
|
||||||
return absoluteDavPath.replace(pathToOc + davFilesPath, "")
|
return absoluteDavPath.replace(pathToOc + davFilesPath, "")
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
package com.owncloud.android.lib.resources.files
|
package com.owncloud.android.lib.resources.files
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient
|
import com.owncloud.android.lib.common.OwnCloudClient
|
||||||
import com.owncloud.android.lib.common.http.HttpConstants.HTTP_NO_CONTENT
|
import com.owncloud.android.lib.common.http.HttpConstants.HTTP_NO_CONTENT
|
||||||
import com.owncloud.android.lib.common.http.HttpConstants.HTTP_OK
|
import com.owncloud.android.lib.common.http.HttpConstants.HTTP_OK
|
||||||
@ -46,7 +45,8 @@ import java.net.URL
|
|||||||
* @author Abel García de Prada
|
* @author Abel García de Prada
|
||||||
*/
|
*/
|
||||||
open class RemoveRemoteFileOperation(
|
open class RemoveRemoteFileOperation(
|
||||||
private val remotePath: String
|
private val remotePath: String,
|
||||||
|
val spaceWebDavUrl: String? = null,
|
||||||
) : RemoteOperation<Unit>() {
|
) : RemoteOperation<Unit>() {
|
||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
|
||||||
@ -54,7 +54,7 @@ open class RemoveRemoteFileOperation(
|
|||||||
try {
|
try {
|
||||||
val srcWebDavUri = getSrcWebDavUriForClient(client)
|
val srcWebDavUri = getSrcWebDavUriForClient(client)
|
||||||
val deleteMethod = DeleteMethod(
|
val deleteMethod = DeleteMethod(
|
||||||
URL(srcWebDavUri.toString() + WebdavUtils.encodePath(remotePath))
|
URL(srcWebDavUri + WebdavUtils.encodePath(remotePath))
|
||||||
)
|
)
|
||||||
val status = client.executeHttpMethod(deleteMethod)
|
val status = client.executeHttpMethod(deleteMethod)
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ open class RemoveRemoteFileOperation(
|
|||||||
* For standard removals, we will use [OwnCloudClient.getUserFilesWebDavUri].
|
* For standard removals, we will use [OwnCloudClient.getUserFilesWebDavUri].
|
||||||
* In case we need a different source Uri, override this method.
|
* In case we need a different source Uri, override this method.
|
||||||
*/
|
*/
|
||||||
open fun getSrcWebDavUriForClient(client: OwnCloudClient): Uri = client.userFilesWebDavUri
|
open fun getSrcWebDavUriForClient(client: OwnCloudClient): String = spaceWebDavUrl ?: client.userFilesWebDavUri.toString()
|
||||||
|
|
||||||
private fun isSuccess(status: Int) = status.isOneOf(HTTP_OK, HTTP_NO_CONTENT)
|
private fun isSuccess(status: Int) = status.isOneOf(HTTP_OK, HTTP_NO_CONTENT)
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ class RenameRemoteFileOperation(
|
|||||||
private val oldRemotePath: String,
|
private val oldRemotePath: String,
|
||||||
private val newName: String,
|
private val newName: String,
|
||||||
isFolder: Boolean,
|
isFolder: Boolean,
|
||||||
|
val spaceWebDavUrl: String? = null,
|
||||||
) : RemoteOperation<Unit>() {
|
) : RemoteOperation<Unit>() {
|
||||||
|
|
||||||
private var newRemotePath: String
|
private var newRemotePath: String
|
||||||
@ -75,8 +76,8 @@ class RenameRemoteFileOperation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val moveMethod: MoveMethod = MoveMethod(
|
val moveMethod: MoveMethod = MoveMethod(
|
||||||
url = URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(oldRemotePath)),
|
url = URL((spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(oldRemotePath)),
|
||||||
destinationUrl = client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(newRemotePath),
|
destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(newRemotePath),
|
||||||
).apply {
|
).apply {
|
||||||
setReadTimeout(RENAME_READ_TIMEOUT, TimeUnit.MILLISECONDS)
|
setReadTimeout(RENAME_READ_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||||
setConnectionTimeout(RENAME_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
|
setConnectionTimeout(RENAME_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* Copyright (C) 2023 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -48,6 +48,7 @@ import java.util.concurrent.atomic.AtomicBoolean
|
|||||||
* @author masensio
|
* @author masensio
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
* @author Abel García de Prada
|
* @author Abel García de Prada
|
||||||
|
* @author Juan Carlos Garrote Gascón
|
||||||
*/
|
*/
|
||||||
open class UploadFileFromFileSystemOperation(
|
open class UploadFileFromFileSystemOperation(
|
||||||
val localPath: String,
|
val localPath: String,
|
||||||
@ -55,6 +56,7 @@ open class UploadFileFromFileSystemOperation(
|
|||||||
val mimeType: String,
|
val mimeType: String,
|
||||||
val lastModifiedTimestamp: String,
|
val lastModifiedTimestamp: String,
|
||||||
val requiredEtag: String?,
|
val requiredEtag: String?,
|
||||||
|
val spaceWebDavUrl: String? = null,
|
||||||
) : RemoteOperation<Unit>() {
|
) : RemoteOperation<Unit>() {
|
||||||
|
|
||||||
protected val cancellationRequested = AtomicBoolean(false)
|
protected val cancellationRequested = AtomicBoolean(false)
|
||||||
@ -97,7 +99,8 @@ open class UploadFileFromFileSystemOperation(
|
|||||||
synchronized(dataTransferListener) { it.addDatatransferProgressListeners(dataTransferListener) }
|
synchronized(dataTransferListener) { it.addDatatransferProgressListeners(dataTransferListener) }
|
||||||
}
|
}
|
||||||
|
|
||||||
putMethod = PutMethod(URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath)), fileRequestBody!!).apply {
|
val baseStringUrl = spaceWebDavUrl ?: client.userFilesWebDavUri.toString()
|
||||||
|
putMethod = PutMethod(URL(baseStringUrl + WebdavUtils.encodePath(remotePath)), fileRequestBody!!).apply {
|
||||||
retryOnConnectionFailure = false
|
retryOnConnectionFailure = false
|
||||||
if (!requiredEtag.isNullOrBlank()) {
|
if (!requiredEtag.isNullOrBlank()) {
|
||||||
addRequestHeader(HttpConstants.IF_MATCH_HEADER, requiredEtag)
|
addRequestHeader(HttpConstants.IF_MATCH_HEADER, requiredEtag)
|
||||||
|
@ -24,10 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.resources.files.chunks
|
package com.owncloud.android.lib.resources.files.chunks
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient
|
import com.owncloud.android.lib.common.OwnCloudClient
|
||||||
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation
|
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation
|
||||||
|
|
||||||
class RemoveRemoteChunksFolderOperation(remotePath: String) : RemoveRemoteFileOperation(remotePath) {
|
class RemoveRemoteChunksFolderOperation(remotePath: String) : RemoveRemoteFileOperation(remotePath) {
|
||||||
override fun getSrcWebDavUriForClient(client: OwnCloudClient): Uri = client.uploadsWebDavUri
|
override fun getSrcWebDavUriForClient(client: OwnCloudClient): String = client.uploadsWebDavUri.toString()
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2020 ownCloud GmbH.
|
* Copyright (C) 2023 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -32,18 +32,22 @@ interface FileService : Service {
|
|||||||
|
|
||||||
fun checkPathExistence(
|
fun checkPathExistence(
|
||||||
path: String,
|
path: String,
|
||||||
isUserLogged: Boolean
|
isUserLogged: Boolean,
|
||||||
|
spaceWebDavUrl: String? = null,
|
||||||
): RemoteOperationResult<Boolean>
|
): RemoteOperationResult<Boolean>
|
||||||
|
|
||||||
fun copyFile(
|
fun copyFile(
|
||||||
sourceRemotePath: String,
|
sourceRemotePath: String,
|
||||||
targetRemotePath: String,
|
targetRemotePath: String,
|
||||||
|
sourceSpaceWebDavUrl: String?,
|
||||||
|
targetSpaceWebDavUrl: String?,
|
||||||
): RemoteOperationResult<String>
|
): RemoteOperationResult<String>
|
||||||
|
|
||||||
fun createFolder(
|
fun createFolder(
|
||||||
remotePath: String,
|
remotePath: String,
|
||||||
createFullPath: Boolean,
|
createFullPath: Boolean,
|
||||||
isChunkFolder: Boolean = false
|
isChunkFolder: Boolean = false,
|
||||||
|
spaceWebDavUrl: String? = null,
|
||||||
): RemoteOperationResult<Unit>
|
): RemoteOperationResult<Unit>
|
||||||
|
|
||||||
fun downloadFile(
|
fun downloadFile(
|
||||||
@ -54,18 +58,22 @@ interface FileService : Service {
|
|||||||
fun moveFile(
|
fun moveFile(
|
||||||
sourceRemotePath: String,
|
sourceRemotePath: String,
|
||||||
targetRemotePath: String,
|
targetRemotePath: String,
|
||||||
|
spaceWebDavUrl: String?,
|
||||||
): RemoteOperationResult<Unit>
|
): RemoteOperationResult<Unit>
|
||||||
|
|
||||||
fun readFile(
|
fun readFile(
|
||||||
remotePath: String
|
remotePath: String,
|
||||||
|
spaceWebDavUrl: String? = null,
|
||||||
): RemoteOperationResult<RemoteFile>
|
): RemoteOperationResult<RemoteFile>
|
||||||
|
|
||||||
fun refreshFolder(
|
fun refreshFolder(
|
||||||
remotePath: String
|
remotePath: String,
|
||||||
|
spaceWebDavUrl: String? = null,
|
||||||
): RemoteOperationResult<ArrayList<RemoteFile>>
|
): RemoteOperationResult<ArrayList<RemoteFile>>
|
||||||
|
|
||||||
fun removeFile(
|
fun removeFile(
|
||||||
remotePath: String
|
remotePath: String,
|
||||||
|
spaceWebDavUrl: String? = null,
|
||||||
): RemoteOperationResult<Unit>
|
): RemoteOperationResult<Unit>
|
||||||
|
|
||||||
fun renameFile(
|
fun renameFile(
|
||||||
@ -73,5 +81,6 @@ interface FileService : Service {
|
|||||||
oldRemotePath: String,
|
oldRemotePath: String,
|
||||||
newName: String,
|
newName: String,
|
||||||
isFolder: Boolean,
|
isFolder: Boolean,
|
||||||
|
spaceWebDavUrl: String? = null,
|
||||||
): RemoteOperationResult<Unit>
|
): RemoteOperationResult<Unit>
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* Copyright (C) 2023 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -42,11 +42,13 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
|
|||||||
|
|
||||||
override fun checkPathExistence(
|
override fun checkPathExistence(
|
||||||
path: String,
|
path: String,
|
||||||
isUserLogged: Boolean
|
isUserLogged: Boolean,
|
||||||
|
spaceWebDavUrl: String?,
|
||||||
): RemoteOperationResult<Boolean> =
|
): RemoteOperationResult<Boolean> =
|
||||||
CheckPathExistenceRemoteOperation(
|
CheckPathExistenceRemoteOperation(
|
||||||
remotePath = path,
|
remotePath = path,
|
||||||
isUserLoggedIn = isUserLogged
|
isUserLoggedIn = isUserLogged,
|
||||||
|
spaceWebDavUrl = spaceWebDavUrl,
|
||||||
).execute(client)
|
).execute(client)
|
||||||
|
|
||||||
override fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String): RemoteOperationResult<String> =
|
override fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String): RemoteOperationResult<String> =
|
||||||
@ -54,22 +56,28 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
|
|||||||
|
|
||||||
override fun copyFile(
|
override fun copyFile(
|
||||||
sourceRemotePath: String,
|
sourceRemotePath: String,
|
||||||
targetRemotePath: String
|
targetRemotePath: String,
|
||||||
|
sourceSpaceWebDavUrl: String?,
|
||||||
|
targetSpaceWebDavUrl: String?,
|
||||||
): RemoteOperationResult<String> =
|
): RemoteOperationResult<String> =
|
||||||
CopyRemoteFileOperation(
|
CopyRemoteFileOperation(
|
||||||
srcRemotePath = sourceRemotePath,
|
sourceRemotePath = sourceRemotePath,
|
||||||
targetRemotePath = targetRemotePath
|
targetRemotePath = targetRemotePath,
|
||||||
|
sourceSpaceWebDavUrl = sourceSpaceWebDavUrl,
|
||||||
|
targetSpaceWebDavUrl = targetSpaceWebDavUrl,
|
||||||
).execute(client)
|
).execute(client)
|
||||||
|
|
||||||
override fun createFolder(
|
override fun createFolder(
|
||||||
remotePath: String,
|
remotePath: String,
|
||||||
createFullPath: Boolean,
|
createFullPath: Boolean,
|
||||||
isChunkFolder: Boolean
|
isChunkFolder: Boolean,
|
||||||
|
spaceWebDavUrl: String?,
|
||||||
): RemoteOperationResult<Unit> =
|
): RemoteOperationResult<Unit> =
|
||||||
CreateRemoteFolderOperation(
|
CreateRemoteFolderOperation(
|
||||||
remotePath = remotePath,
|
remotePath = remotePath,
|
||||||
createFullPath = createFullPath,
|
createFullPath = createFullPath,
|
||||||
isChunksFolder = isChunkFolder
|
isChunksFolder = isChunkFolder,
|
||||||
|
spaceWebDavUrl = spaceWebDavUrl,
|
||||||
).execute(client)
|
).execute(client)
|
||||||
|
|
||||||
override fun downloadFile(
|
override fun downloadFile(
|
||||||
@ -84,43 +92,53 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
|
|||||||
override fun moveFile(
|
override fun moveFile(
|
||||||
sourceRemotePath: String,
|
sourceRemotePath: String,
|
||||||
targetRemotePath: String,
|
targetRemotePath: String,
|
||||||
|
spaceWebDavUrl: String?,
|
||||||
): RemoteOperationResult<Unit> =
|
): RemoteOperationResult<Unit> =
|
||||||
MoveRemoteFileOperation(
|
MoveRemoteFileOperation(
|
||||||
sourceRemotePath = sourceRemotePath,
|
sourceRemotePath = sourceRemotePath,
|
||||||
targetRemotePath = targetRemotePath,
|
targetRemotePath = targetRemotePath,
|
||||||
|
spaceWebDavUrl = spaceWebDavUrl,
|
||||||
).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(
|
||||||
remotePath: String
|
remotePath: String,
|
||||||
|
spaceWebDavUrl: String?,
|
||||||
): RemoteOperationResult<ArrayList<RemoteFile>> =
|
): RemoteOperationResult<ArrayList<RemoteFile>> =
|
||||||
ReadRemoteFolderOperation(
|
ReadRemoteFolderOperation(
|
||||||
remotePath = remotePath
|
remotePath = remotePath,
|
||||||
|
spaceWebDavUrl = spaceWebDavUrl,
|
||||||
).execute(client)
|
).execute(client)
|
||||||
|
|
||||||
override fun removeFile(
|
override fun removeFile(
|
||||||
remotePath: String
|
remotePath: String,
|
||||||
|
spaceWebDavUrl: String?,
|
||||||
): RemoteOperationResult<Unit> =
|
): RemoteOperationResult<Unit> =
|
||||||
RemoveRemoteFileOperation(
|
RemoveRemoteFileOperation(
|
||||||
remotePath = remotePath
|
remotePath = remotePath,
|
||||||
|
spaceWebDavUrl = spaceWebDavUrl,
|
||||||
).execute(client)
|
).execute(client)
|
||||||
|
|
||||||
override fun renameFile(
|
override fun renameFile(
|
||||||
oldName: String,
|
oldName: String,
|
||||||
oldRemotePath: String,
|
oldRemotePath: String,
|
||||||
newName: String,
|
newName: String,
|
||||||
isFolder: Boolean
|
isFolder: Boolean,
|
||||||
|
spaceWebDavUrl: String?,
|
||||||
): RemoteOperationResult<Unit> =
|
): RemoteOperationResult<Unit> =
|
||||||
RenameRemoteFileOperation(
|
RenameRemoteFileOperation(
|
||||||
oldName = oldName,
|
oldName = oldName,
|
||||||
oldRemotePath = oldRemotePath,
|
oldRemotePath = oldRemotePath,
|
||||||
newName = newName,
|
newName = newName,
|
||||||
isFolder = isFolder
|
isFolder = isFolder,
|
||||||
|
spaceWebDavUrl = spaceWebDavUrl,
|
||||||
).execute(client)
|
).execute(client)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,99 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2022 ownCloud GmbH.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.owncloud.android.lib.resources.spaces
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudClient
|
||||||
|
import com.owncloud.android.lib.common.http.HttpConstants
|
||||||
|
import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperation
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
|
import com.owncloud.android.lib.resources.spaces.responses.SpaceResponse
|
||||||
|
import com.owncloud.android.lib.resources.spaces.responses.SpacesResponseWrapper
|
||||||
|
import com.squareup.moshi.JsonAdapter
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
|
import timber.log.Timber
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
|
class GetRemoteSpacesOperation : RemoteOperation<List<SpaceResponse>>() {
|
||||||
|
override fun run(client: OwnCloudClient): RemoteOperationResult<List<SpaceResponse>> {
|
||||||
|
val requestUri = buildRequestUri(client.baseUri)
|
||||||
|
|
||||||
|
val getMethod = GetMethod(URL(requestUri.toString()))
|
||||||
|
|
||||||
|
return try {
|
||||||
|
val status = client.executeHttpMethod(getMethod)
|
||||||
|
val response = getMethod.getResponseBodyAsString()
|
||||||
|
|
||||||
|
if (isSuccess(status)) {
|
||||||
|
onRequestSuccessful(response)
|
||||||
|
} else {
|
||||||
|
onResultUnsuccessful(getMethod, response, status)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Timber.e(e, "Exception while getting remote shares")
|
||||||
|
RemoteOperationResult(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildRequestUri(baseUri: Uri) =
|
||||||
|
baseUri.buildUpon()
|
||||||
|
.appendEncodedPath(GRAPH_API_PATH)
|
||||||
|
.appendEncodedPath(ENDPOINT_SPACES_LIST)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
private fun parseResponse(response: String): List<SpaceResponse> {
|
||||||
|
val moshi = Moshi.Builder().build()
|
||||||
|
val adapter: JsonAdapter<SpacesResponseWrapper> = moshi.adapter(SpacesResponseWrapper::class.java)
|
||||||
|
return adapter.fromJson(response)?.value ?: listOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onResultUnsuccessful(
|
||||||
|
method: GetMethod,
|
||||||
|
response: String?,
|
||||||
|
status: Int
|
||||||
|
): RemoteOperationResult<List<SpaceResponse>> {
|
||||||
|
Timber.e("Failed response while getting spaces for user")
|
||||||
|
if (response != null) {
|
||||||
|
Timber.e("*** status code: $status; response message: $response")
|
||||||
|
} else {
|
||||||
|
Timber.e("*** status code: $status")
|
||||||
|
}
|
||||||
|
return RemoteOperationResult(method)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onRequestSuccessful(response: String?): RemoteOperationResult<List<SpaceResponse>> {
|
||||||
|
val result = RemoteOperationResult<List<SpaceResponse>>(RemoteOperationResult.ResultCode.OK)
|
||||||
|
Timber.d("Successful response: $response")
|
||||||
|
result.data = response?.let { parseResponse(it) } ?: listOf()
|
||||||
|
Timber.d("*** Fetch of spaces completed and parsed to ${result.data}")
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val GRAPH_API_PATH = "graph/v1.0"
|
||||||
|
private const val ENDPOINT_SPACES_LIST = "me/drives"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2022 ownCloud GmbH.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.owncloud.android.lib.resources.spaces.responses
|
||||||
|
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class SpacesResponseWrapper(
|
||||||
|
val value: List<SpaceResponse>
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class SpaceResponse(
|
||||||
|
val description: String?,
|
||||||
|
val driveAlias: String,
|
||||||
|
val driveType: String,
|
||||||
|
val id: String,
|
||||||
|
val lastModifiedDateTime: String?,
|
||||||
|
val name: String,
|
||||||
|
val owner: OwnerResponse?,
|
||||||
|
val quota: QuotaResponse?,
|
||||||
|
val root: RootResponse,
|
||||||
|
val special: List<SpecialResponse>?,
|
||||||
|
val webUrl: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class OwnerResponse(
|
||||||
|
val user: UserResponse
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class QuotaResponse(
|
||||||
|
val remaining: Long?,
|
||||||
|
val state: String?,
|
||||||
|
val total: Long,
|
||||||
|
val used: Long?,
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class RootResponse(
|
||||||
|
val eTag: String?,
|
||||||
|
val id: String,
|
||||||
|
val permissions: List<PermissionResponse>?,
|
||||||
|
val webDavUrl: String,
|
||||||
|
val deleted: DeleteResponse?,
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class SpecialResponse(
|
||||||
|
val eTag: String,
|
||||||
|
val file: FileResponse,
|
||||||
|
val id: String,
|
||||||
|
val lastModifiedDateTime: String,
|
||||||
|
val name: String,
|
||||||
|
val size: Int,
|
||||||
|
val specialFolder: SpecialFolderResponse,
|
||||||
|
val webDavUrl: String
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class UserResponse(
|
||||||
|
val id: String
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class FileResponse(
|
||||||
|
val mimeType: String
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class IdentityPermissionResponse(
|
||||||
|
val id: String,
|
||||||
|
val displayName: String?,
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class GrantedToIdentitiesResponse(
|
||||||
|
val user: IdentityPermissionResponse?,
|
||||||
|
val group: IdentityPermissionResponse?,
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class DeleteResponse(
|
||||||
|
val state: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class PermissionResponse(
|
||||||
|
val grantedTo: List<GrantedToIdentitiesResponse>?,
|
||||||
|
val grantedToIdentities: List<GrantedToIdentitiesResponse>?,
|
||||||
|
val roles: List<String>,
|
||||||
|
) {
|
||||||
|
/**
|
||||||
|
* Supports api renaming from grantedTo to grantedToIdentities on v1.0.1
|
||||||
|
* https://github.com/owncloud/libre-graph-api/releases/tag/v1.0.1
|
||||||
|
*/
|
||||||
|
fun getGrantedToIdentitiesResponse(): List<GrantedToIdentitiesResponse> {
|
||||||
|
return grantedToIdentities ?: grantedTo ?: throw IllegalArgumentException("Permissions not granted to anyone")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class SpecialFolderResponse(
|
||||||
|
val name: String
|
||||||
|
)
|
@ -0,0 +1,34 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2022 ownCloud GmbH.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.owncloud.android.lib.resources.spaces.services
|
||||||
|
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudClient
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
|
import com.owncloud.android.lib.resources.spaces.GetRemoteSpacesOperation
|
||||||
|
import com.owncloud.android.lib.resources.spaces.responses.SpaceResponse
|
||||||
|
|
||||||
|
class OCSpacesService(override val client: OwnCloudClient) : SpacesService {
|
||||||
|
override fun getSpaces(): RemoteOperationResult<List<SpaceResponse>> {
|
||||||
|
return GetRemoteSpacesOperation().execute(client)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2022 ownCloud GmbH.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.owncloud.android.lib.resources.spaces.services
|
||||||
|
|
||||||
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
|
import com.owncloud.android.lib.resources.Service
|
||||||
|
import com.owncloud.android.lib.resources.spaces.responses.SpaceResponse
|
||||||
|
|
||||||
|
interface SpacesService : Service {
|
||||||
|
fun getSpaces(): RemoteOperationResult<List<SpaceResponse>>
|
||||||
|
}
|
@ -45,7 +45,7 @@ import java.net.URL
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Capabilities from the server
|
* Get the Capabilities from the server
|
||||||
* Save in Result.getData in a RemoteCapability object
|
* Save Result.getData in a RemoteCapability object
|
||||||
*
|
*
|
||||||
* @author masensio
|
* @author masensio
|
||||||
* @author David González Verdugo
|
* @author David González Verdugo
|
||||||
|
@ -1,29 +1,33 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/**
|
||||||
* @author masensio
|
* ownCloud Android Library is available under MIT license
|
||||||
* @author David González Verdugo
|
|
||||||
* @author Abel García de Prada
|
|
||||||
* Copyright (C) 2020 ownCloud GmbH.
|
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* @author masensio
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* @author David González Verdugo
|
||||||
* in the Software without restriction, including without limitation the rights
|
* @author Abel García de Prada
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* @author Juan Carlos Garrote Gascón
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* Copyright (C) 2022 ownCloud GmbH.
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
* in the Software without restriction, including without limitation the rights
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* furnished to do so, subject to the following conditions:
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources.status
|
package com.owncloud.android.lib.resources.status
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +37,7 @@ data class RemoteCapability(
|
|||||||
var accountName: String = "",
|
var accountName: String = "",
|
||||||
|
|
||||||
// Server version
|
// Server version
|
||||||
var versionMayor: Int = 0,
|
var versionMajor: Int = 0,
|
||||||
var versionMinor: Int = 0,
|
var versionMinor: Int = 0,
|
||||||
var versionMicro: Int = 0,
|
var versionMicro: Int = 0,
|
||||||
var versionString: String = "",
|
var versionString: String = "",
|
||||||
@ -68,7 +72,10 @@ data class RemoteCapability(
|
|||||||
var filesUndelete: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
var filesUndelete: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
||||||
var filesVersioning: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
var filesVersioning: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
||||||
val filesPrivateLinks: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
val filesPrivateLinks: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN,
|
||||||
val filesAppProviders: List<RemoteOCISProvider>?,
|
val filesAppProviders: List<RemoteAppProviders>?,
|
||||||
|
|
||||||
|
// Spaces
|
||||||
|
val spaces: RemoteSpaces?,
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* Enum for Boolean Type in capabilities, with values:
|
* Enum for Boolean Type in capabilities, with values:
|
||||||
@ -101,7 +108,7 @@ data class RemoteCapability(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class RemoteOCISProvider(
|
data class RemoteAppProviders(
|
||||||
val enabled: Boolean,
|
val enabled: Boolean,
|
||||||
val version: String,
|
val version: String,
|
||||||
val appsUrl: String?,
|
val appsUrl: String?,
|
||||||
@ -109,4 +116,10 @@ data class RemoteCapability(
|
|||||||
val openWebUrl: String?,
|
val openWebUrl: String?,
|
||||||
val newUrl: String?,
|
val newUrl: String?,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class RemoteSpaces(
|
||||||
|
val enabled: Boolean,
|
||||||
|
val projects: Boolean,
|
||||||
|
val shareJail: Boolean,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,35 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/**
|
||||||
* @author Abel García de Prada
|
* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2020 ownCloud GmbH.
|
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* @author Abel García de Prada
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* @author Juan Carlos Garrote Gascón
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* Copyright (C) 2022 ownCloud GmbH.
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
* in the Software without restriction, including without limitation the rights
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* furnished to do so, subject to the following conditions:
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.owncloud.android.lib.resources.status.responses
|
package com.owncloud.android.lib.resources.status.responses
|
||||||
|
|
||||||
import com.owncloud.android.lib.resources.status.RemoteCapability
|
import com.owncloud.android.lib.resources.status.RemoteCapability
|
||||||
import com.owncloud.android.lib.resources.status.RemoteCapability.CapabilityBooleanType
|
import com.owncloud.android.lib.resources.status.RemoteCapability.*
|
||||||
import com.owncloud.android.lib.resources.status.RemoteCapability.RemoteOCISProvider
|
|
||||||
import com.squareup.moshi.Json
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
@ -37,7 +40,7 @@ data class CapabilityResponse(
|
|||||||
val capabilities: Capabilities?
|
val capabilities: Capabilities?
|
||||||
) {
|
) {
|
||||||
fun toRemoteCapability(): RemoteCapability = RemoteCapability(
|
fun toRemoteCapability(): RemoteCapability = RemoteCapability(
|
||||||
versionMayor = serverVersion?.major ?: 0,
|
versionMajor = serverVersion?.major ?: 0,
|
||||||
versionMinor = serverVersion?.minor ?: 0,
|
versionMinor = serverVersion?.minor ?: 0,
|
||||||
versionMicro = serverVersion?.micro ?: 0,
|
versionMicro = serverVersion?.micro ?: 0,
|
||||||
versionString = serverVersion?.string ?: "",
|
versionString = serverVersion?.string ?: "",
|
||||||
@ -70,10 +73,11 @@ data class CapabilityResponse(
|
|||||||
filesUndelete = CapabilityBooleanType.fromBooleanValue(capabilities?.fileCapabilities?.undelete),
|
filesUndelete = CapabilityBooleanType.fromBooleanValue(capabilities?.fileCapabilities?.undelete),
|
||||||
filesVersioning = CapabilityBooleanType.fromBooleanValue(capabilities?.fileCapabilities?.versioning),
|
filesVersioning = CapabilityBooleanType.fromBooleanValue(capabilities?.fileCapabilities?.versioning),
|
||||||
filesPrivateLinks = capabilities?.fileCapabilities?.privateLinks?.let { CapabilityBooleanType.fromBooleanValue(it) } ?: CapabilityBooleanType.UNKNOWN,
|
filesPrivateLinks = capabilities?.fileCapabilities?.privateLinks?.let { CapabilityBooleanType.fromBooleanValue(it) } ?: CapabilityBooleanType.UNKNOWN,
|
||||||
filesAppProviders = capabilities?.fileCapabilities?.appProviders?.map { it.toOCISProvider() },
|
filesAppProviders = capabilities?.fileCapabilities?.appProviders?.map { it.toAppProviders() },
|
||||||
filesSharingFederationIncoming = CapabilityBooleanType.fromBooleanValue(capabilities?.fileSharingCapabilities?.fileSharingFederation?.incoming),
|
filesSharingFederationIncoming = CapabilityBooleanType.fromBooleanValue(capabilities?.fileSharingCapabilities?.fileSharingFederation?.incoming),
|
||||||
filesSharingFederationOutgoing = CapabilityBooleanType.fromBooleanValue(capabilities?.fileSharingCapabilities?.fileSharingFederation?.outgoing),
|
filesSharingFederationOutgoing = CapabilityBooleanType.fromBooleanValue(capabilities?.fileSharingCapabilities?.fileSharingFederation?.outgoing),
|
||||||
filesSharingUserProfilePicture = CapabilityBooleanType.fromBooleanValue(capabilities?.fileSharingCapabilities?.fileSharingUser?.profilePicture),
|
filesSharingUserProfilePicture = CapabilityBooleanType.fromBooleanValue(capabilities?.fileSharingCapabilities?.fileSharingUser?.profilePicture),
|
||||||
|
spaces = capabilities?.spacesCapabilities?.toSpaces(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +90,9 @@ data class Capabilities(
|
|||||||
@Json(name = "files")
|
@Json(name = "files")
|
||||||
val fileCapabilities: FileCapabilities?,
|
val fileCapabilities: FileCapabilities?,
|
||||||
@Json(name = "dav")
|
@Json(name = "dav")
|
||||||
val davCapabilities: DavCapabilities?
|
val davCapabilities: DavCapabilities?,
|
||||||
|
@Json(name = "spaces")
|
||||||
|
val spacesCapabilities: SpacesCapabilities?,
|
||||||
)
|
)
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
@ -182,7 +188,7 @@ data class AppProvider(
|
|||||||
@Json(name = "new_url")
|
@Json(name = "new_url")
|
||||||
val newUrl: String?,
|
val newUrl: String?,
|
||||||
) {
|
) {
|
||||||
fun toOCISProvider() = RemoteOCISProvider(enabled, version, appsUrl, openUrl, openWebUrl, newUrl)
|
fun toAppProviders() = RemoteAppProviders(enabled, version, appsUrl, openUrl, openWebUrl, newUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
@ -190,6 +196,16 @@ data class DavCapabilities(
|
|||||||
val chunking: String?
|
val chunking: String?
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class SpacesCapabilities(
|
||||||
|
val enabled: Boolean,
|
||||||
|
val projects: Boolean,
|
||||||
|
@Json(name = "share_jail")
|
||||||
|
val shareJail: Boolean,
|
||||||
|
) {
|
||||||
|
fun toSpaces() = RemoteSpaces(enabled, projects, shareJail)
|
||||||
|
}
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class ServerVersion(
|
data class ServerVersion(
|
||||||
var major: Int?,
|
var major: Int?,
|
||||||
|
@ -31,16 +31,16 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
|
|||||||
import com.owncloud.android.lib.common.http.methods.nonwebdav.HttpMethod
|
import com.owncloud.android.lib.common.http.methods.nonwebdav.HttpMethod
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperation
|
import com.owncloud.android.lib.common.operations.RemoteOperation
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
import com.owncloud.android.lib.resources.webfinger.responses.WebfingerJrdResponse
|
import com.owncloud.android.lib.resources.webfinger.responses.WebFingerResponse
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
class GetOCInstanceViaWebfingerOperation(
|
class GetInstancesViaWebFingerOperation(
|
||||||
private val lockupServerDomain: String,
|
private val lockupServerDomain: String,
|
||||||
private val rel: String,
|
private val rel: String,
|
||||||
private val resource: String,
|
private val resource: String,
|
||||||
) : RemoteOperation<String>() {
|
) : RemoteOperation<List<String>>() {
|
||||||
|
|
||||||
private fun buildRequestUri() =
|
private fun buildRequestUri() =
|
||||||
Uri.parse(lockupServerDomain).buildUpon()
|
Uri.parse(lockupServerDomain).buildUpon()
|
||||||
@ -51,9 +51,9 @@ class GetOCInstanceViaWebfingerOperation(
|
|||||||
|
|
||||||
private fun isSuccess(status: Int): Boolean = status == HttpConstants.HTTP_OK
|
private fun isSuccess(status: Int): Boolean = status == HttpConstants.HTTP_OK
|
||||||
|
|
||||||
private fun parseResponse(response: String): WebfingerJrdResponse {
|
private fun parseResponse(response: String): WebFingerResponse {
|
||||||
val moshi = Moshi.Builder().build()
|
val moshi = Moshi.Builder().build()
|
||||||
val adapter = moshi.adapter(WebfingerJrdResponse::class.java)
|
val adapter = moshi.adapter(WebFingerResponse::class.java)
|
||||||
return adapter.fromJson(response)!!
|
return adapter.fromJson(response)!!
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,30 +61,25 @@ class GetOCInstanceViaWebfingerOperation(
|
|||||||
method: HttpMethod,
|
method: HttpMethod,
|
||||||
response: String?,
|
response: String?,
|
||||||
status: Int
|
status: Int
|
||||||
): RemoteOperationResult<String> {
|
): RemoteOperationResult<List<String>> {
|
||||||
Timber.e("Failed requesting webfinger info")
|
Timber.e("Failed requesting WebFinger info")
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
Timber.e("*** status code: $status; response message: $response")
|
Timber.e("*** status code: $status; response message: $response")
|
||||||
} else {
|
} else {
|
||||||
Timber.e("*** status code: $status")
|
Timber.e("*** status code: $status")
|
||||||
}
|
}
|
||||||
return RemoteOperationResult<String>(method)
|
return RemoteOperationResult<List<String>>(method)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onRequestSuccessful(rawResponse: String): RemoteOperationResult<String> {
|
private fun onRequestSuccessful(rawResponse: String): RemoteOperationResult<List<String>> {
|
||||||
val response = parseResponse(rawResponse)
|
val response = parseResponse(rawResponse)
|
||||||
for (i in response.links) {
|
Timber.d("Successful WebFinger request: $response")
|
||||||
if (i.rel == rel) {
|
val operationResult = RemoteOperationResult<List<String>>(RemoteOperationResult.ResultCode.OK)
|
||||||
val operationResult = RemoteOperationResult<String>(RemoteOperationResult.ResultCode.OK)
|
operationResult.data = response.links.map { it.href }
|
||||||
operationResult.data = i.href
|
return operationResult
|
||||||
return operationResult
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Timber.e("Could not find ownCloud relevant information in webfinger response: $rawResponse")
|
|
||||||
throw java.lang.Exception("Could not find ownCloud relevant information in webfinger response")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<String> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<List<String>> {
|
||||||
val requestUri = buildRequestUri()
|
val requestUri = buildRequestUri()
|
||||||
val getMethod = GetMethod(URL(requestUri.toString()))
|
val getMethod = GetMethod(URL(requestUri.toString()))
|
||||||
return try {
|
return try {
|
||||||
@ -97,8 +92,8 @@ class GetOCInstanceViaWebfingerOperation(
|
|||||||
onResultUnsuccessful(getMethod, response, status)
|
onResultUnsuccessful(getMethod, response, status)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e, "Requesting webfinger info failed")
|
Timber.e(e, "Requesting WebFinger info failed")
|
||||||
RemoteOperationResult<String>(e)
|
RemoteOperationResult<List<String>>(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,13 +27,13 @@ package com.owncloud.android.lib.resources.webfinger.responses
|
|||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class WebfingerJrdResponse(
|
data class WebFingerResponse(
|
||||||
val subject: String,
|
val subject: String,
|
||||||
val links: List<LinkItem>
|
val links: List<LinkItem>
|
||||||
)
|
)
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class LinkItem(
|
data class LinkItem(
|
||||||
|
val rel: String,
|
||||||
val href: String,
|
val href: String,
|
||||||
val rel: String
|
|
||||||
)
|
)
|
@ -20,10 +20,11 @@ package com.owncloud.android.lib.resources.webfinger.services
|
|||||||
import com.owncloud.android.lib.common.OwnCloudClient
|
import com.owncloud.android.lib.common.OwnCloudClient
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
|
|
||||||
interface WebfingerService {
|
interface WebFingerService {
|
||||||
fun getInstanceFromWebfinger(
|
fun getInstancesFromWebFinger(
|
||||||
lookupServer: String,
|
lookupServer: String,
|
||||||
username: String,
|
resource: String,
|
||||||
|
rel: String,
|
||||||
client: OwnCloudClient,
|
client: OwnCloudClient,
|
||||||
): RemoteOperationResult<String>
|
): RemoteOperationResult<List<String>>
|
||||||
}
|
}
|
@ -19,20 +19,16 @@ package com.owncloud.android.lib.resources.webfinger.services.implementation
|
|||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient
|
import com.owncloud.android.lib.common.OwnCloudClient
|
||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||||
import com.owncloud.android.lib.resources.webfinger.GetOCInstanceViaWebfingerOperation
|
import com.owncloud.android.lib.resources.webfinger.GetInstancesViaWebFingerOperation
|
||||||
import com.owncloud.android.lib.resources.webfinger.services.WebfingerService
|
import com.owncloud.android.lib.resources.webfinger.services.WebFingerService
|
||||||
|
|
||||||
class OCWebfingerService : WebfingerService {
|
class OCWebFingerService : WebFingerService {
|
||||||
|
|
||||||
override fun getInstanceFromWebfinger(
|
override fun getInstancesFromWebFinger(
|
||||||
lookupServer: String,
|
lookupServer: String,
|
||||||
username: String,
|
resource: String,
|
||||||
|
rel: String,
|
||||||
client: OwnCloudClient,
|
client: OwnCloudClient,
|
||||||
): RemoteOperationResult<String> =
|
): RemoteOperationResult<List<String>> =
|
||||||
GetOCInstanceViaWebfingerOperation(lookupServer, OWNCLOUD_REL, username).execute(client)
|
GetInstancesViaWebFingerOperation(lookupServer, rel, resource).execute(client)
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val OWNCLOUD_REL = "http://webfinger.owncloud/rel/server-instance"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
/* ownCloud Android Library is available under MIT license
|
||||||
|
* Copyright (C) 2023 ownCloud GmbH.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.owncloud.android.lib
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import com.owncloud.android.lib.resources.files.RemoteFile
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
import org.robolectric.annotation.Config
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
@Config(sdk = [Build.VERSION_CODES.O], manifest = Config.NONE)
|
||||||
|
class RemoteFileTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getRemotePathFromUrl_legacyWebDav() {
|
||||||
|
val httpUrlToTest = "https://server.url/remote.php/dav/files/username/Documents/text.txt".toHttpUrl()
|
||||||
|
val expectedRemotePath = "/Documents/text.txt"
|
||||||
|
|
||||||
|
val actualRemotePath = RemoteFile.Companion.getRemotePathFromUrl(httpUrlToTest, "username")
|
||||||
|
assertEquals(expectedRemotePath, actualRemotePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun getRemotePathFromUrl_spacesWebDav() {
|
||||||
|
val spaceWebDavUrl = "https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f38$05bca744-d89f-4e9c-a990-25a0d7f03fe9"
|
||||||
|
|
||||||
|
val httpUrlToTest =
|
||||||
|
"https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f38$05bca744-d89f-4e9c-a990-25a0d7f03fe9/Documents/text.txt".toHttpUrl()
|
||||||
|
val expectedRemotePath = "/Documents/text.txt"
|
||||||
|
|
||||||
|
val actualRemotePath = RemoteFile.Companion.getRemotePathFromUrl(httpUrlToTest, "username", spaceWebDavUrl)
|
||||||
|
assertEquals(expectedRemotePath, actualRemotePath)
|
||||||
|
}
|
||||||
|
}
|
@ -8,15 +8,15 @@ import org.junit.Before
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class WebfingerResponseTest {
|
class WebFingerResponseTest {
|
||||||
lateinit var adapter: JsonAdapter<WebfingerJrdResponse>
|
lateinit var adapter: JsonAdapter<WebFingerResponse>
|
||||||
|
|
||||||
private fun loadResponses(fileName: String) = adapter.fromJson(File(fileName).readText())
|
private fun loadResponses(fileName: String) = adapter.fromJson(File(fileName).readText())
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun prepare() {
|
fun prepare() {
|
||||||
val moshi = Moshi.Builder().build()
|
val moshi = Moshi.Builder().build()
|
||||||
adapter = moshi.adapter(WebfingerJrdResponse::class.java)
|
adapter = moshi.adapter(WebFingerResponse::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
Loading…
x
Reference in New Issue
Block a user