create a new folder

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2025-02-25 23:58:39 +01:00 committed by Marcel Hibbe
parent bb581d0862
commit ef4d83a691
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
4 changed files with 73 additions and 55 deletions

View File

@ -151,7 +151,7 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
} else { } else {
Log.d(TAG, "starting normal upload (not chunked) of $fileName") Log.d(TAG, "starting normal upload (not chunked) of $fileName")
FileUploader(okHttpClient, context, currentUser, roomToken, ncApi) FileUploader(okHttpClient, context, currentUser, roomToken, ncApi, file!!)
.upload(sourceFileUri, fileName, remotePath, metaData) .upload(sourceFileUri, fileName, remotePath, metaData)
.blockingFirst() .blockingFirst()
} }

View File

@ -27,6 +27,7 @@ import okhttp3.OkHttpClient
import okhttp3.Protocol import okhttp3.Protocol
import okhttp3.RequestBody import okhttp3.RequestBody
import okhttp3.Response import okhttp3.Response
import java.io.File
import java.io.IOException import java.io.IOException
import java.io.InputStream import java.io.InputStream
@ -35,11 +36,14 @@ class FileUploader(
val context: Context, val context: Context,
val currentUser: User, val currentUser: User,
val roomToken: String, val roomToken: String,
val ncApi: NcApi val ncApi: NcApi,
val file: File
) { ) {
private var okHttpClientNoRedirects: OkHttpClient? = null private var okHttpClientNoRedirects: OkHttpClient? = null
private var uploadFolderUri: String = "" private var uploadFolderUri: String = ""
private var uploadFileUri:String = ""
init { init {
initHttpClient(okHttpClient, currentUser) initHttpClient(okHttpClient, currentUser)
} }
@ -63,17 +67,21 @@ class FileUploader(
true true
} else { } else {
if (response.code() == 404 || response.code() == 409) { if (response.code() == 404 || response.code() == 409) {
uploadFolderUri = ApiUtils.getUrlForFileUpload( uploadFileUri = ApiUtils.getUrlForFile(
currentUser.baseUrl!!, currentUser.userId!!, currentUser.baseUrl!!, currentUser.userId!!,
remotePath
) )
uploadFolderUri = uploadFileUri + "/" + FileUtils.md5Sum(file)
val davResource = DavResource( val davResource = DavResource(
okHttpClientNoRedirects!!, okHttpClientNoRedirects!!,
uploadFolderUri.toHttpUrlOrNull()!! uploadFolderUri.toHttpUrlOrNull()!!
) )
createFolder(davResource) createFolder(davResource)
retryUpload(sourceFileUri, remotePath, fileName, metaData) val value = retryUpload(sourceFileUri, remotePath, fileName, metaData)
true value
} else { } else {
false false
} }
@ -100,9 +108,9 @@ class FileUploader(
private fun initHttpClient(okHttpClient: OkHttpClient, currentUser: User) { private fun initHttpClient(okHttpClient: OkHttpClient, currentUser: User) {
val okHttpClientBuilder: OkHttpClient.Builder = okHttpClient.newBuilder() val okHttpClientBuilder: OkHttpClient.Builder = okHttpClient.newBuilder()
okHttpClientBuilder.followRedirects(true) okHttpClientBuilder.followRedirects(false)
okHttpClientBuilder.followSslRedirects(true) okHttpClientBuilder.followSslRedirects(false)
okHttpClientBuilder.protocols(listOf(Protocol.HTTP_1_1, Protocol.HTTP_2)) okHttpClientBuilder.protocols(listOf(Protocol.HTTP_1_1))
okHttpClientBuilder.authenticator( okHttpClientBuilder.authenticator(
RestModule.HttpAuthenticator( RestModule.HttpAuthenticator(
ApiUtils.getCredentials( ApiUtils.getCredentials(
@ -137,26 +145,32 @@ class FileUploader(
private fun retryUpload( private fun retryUpload(
sourceFileUri: Uri, sourceFileUri: Uri,
uploadUrl: String, remotePath: String,
fileName: String, fileName: String,
metaData: String? metaData: String?
): Observable<Boolean> { ): Boolean {
return ncApi.uploadFile( return try {
ApiUtils.getCredentials(currentUser.username, currentUser.token), ncApi.uploadFile(
uploadUrl, ApiUtils.getCredentials(currentUser.username, currentUser.token),
createRequestBody(sourceFileUri) ApiUtils.getUrlForFileUpload(currentUser.baseUrl!!, currentUser.userId!!, remotePath),
) createRequestBody(sourceFileUri)
.subscribeOn(Schedulers.io()) )
.observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io())
.map { retryResponse -> .observeOn(AndroidSchedulers.mainThread())
if (retryResponse.isSuccessful) { .map { retryResponse ->
ShareOperationWorker.shareFile(roomToken, currentUser, uploadUrl, metaData) if (retryResponse.isSuccessful) {
FileUtils.copyFileToCache(context, sourceFileUri, fileName) ShareOperationWorker.shareFile(roomToken, currentUser, remotePath, metaData)
true FileUtils.copyFileToCache(context, sourceFileUri, fileName)
} else { true
false } else {
false
}
} }
} .blockingFirst()
} catch (e: Exception) {
Log.e(TAG, "Retry upload failed", e)
false
}
} }
companion object { companion object {

View File

@ -459,6 +459,10 @@ object ApiUtils {
return "$baseUrl/remote.php/dav/files/$user/$remotePath" return "$baseUrl/remote.php/dav/files/$user/$remotePath"
} }
fun getUrlForFile(baseUrl: String, user: String): String {
return "$baseUrl/remote.php/dav/files/$user"
}
fun getUrlForTempAvatar(baseUrl: String): String { fun getUrlForTempAvatar(baseUrl: String): String {
return "$baseUrl$OCS_API_VERSION/apps/spreed/temp-user-avatar" return "$baseUrl$OCS_API_VERSION/apps/spreed/temp-user-avatar"
} }

View File

@ -90,6 +90,35 @@
</RelativeLayout> </RelativeLayout>
<LinearLayout
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/notification_settings_view"
layout="@layout/item_notification_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_quarter_margin" />
<include
android:id="@+id/webinar_info_view"
layout="@layout/item_webinar_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_quarter_margin" />
<include
android:id="@+id/guest_access_view"
layout="@layout/item_guest_access_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_quarter_margin" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/conversation_description" android:id="@+id/conversation_description"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -139,35 +168,6 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/notification_settings_view"
layout="@layout/item_notification_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_quarter_margin" />
<include
android:id="@+id/webinar_info_view"
layout="@layout/item_webinar_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_quarter_margin" />
<include
android:id="@+id/guest_access_view"
layout="@layout/item_guest_access_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/standard_quarter_margin" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/shared_items" android:id="@+id/shared_items"
android:layout_width="match_parent" android:layout_width="match_parent"