Skip to content

Commit

Permalink
feat: Support copy-free upload (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirambd authored Mar 4, 2025
2 parents 9a56bff + 29b4182 commit 5f6c5e6
Show file tree
Hide file tree
Showing 16 changed files with 534 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Infomaniak SwissTransfer - Multiplatform
* Copyright (C) 2025 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload

data class FileToUploadMetadata(
val name: String,
val size: Long,
val mimeType: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Infomaniak SwissTransfer - Multiplatform
* Copyright (C) 2025 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload

data class UploadDestination(
val container: UploadContainer,
val uploadHost: String,
val filesUuid: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Infomaniak SwissTransfer - Multiplatform
* Copyright (C) 2025 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload

import com.infomaniak.multiplatform_swisstransfer.common.models.DownloadLimit
import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage
import com.infomaniak.multiplatform_swisstransfer.common.models.ValidityPeriod

class UploadSessionRequest(
val validityPeriod: ValidityPeriod,
val authorEmail: String,
val password: String,
val message: String,
val sizeOfUpload: Long,
val downloadCountLimit: DownloadLimit,
val filesCount: Int,
val languageCode: EmailLanguage,
val filesMetadata: List<FileToUploadMetadata>,
val recipientsEmails: Set<String>,
)
21 changes: 11 additions & 10 deletions STCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ centralized access point to orchestrate transfer operations.

### Table of Public Properties and Methods

| Type | Name | Description |
|----------|---------------------|-------------------------------------------------------|
| Property | userAgent | Customize client api userAgent. |
| Property | appSettingsManager | A manager used to orchestrate AppSettings operations. |
| Property | transferManager | A manager used to orchestrate Transfers operations. |
| Property | fileManager | A manager used to orchestrate Files operations. |
| Property | accountManager | A manager used to orchestrate Accounts operations. |
| Property | uploadManager | A manager used to orchestrate Uploads operations. |
| Property | emailTokensManager | A manager used to orchestrate EmailTokens operations. |
| Property | sharedApiUrlCreator | An utils to help use shared routes |
| Type | Name | Description |
|----------|-----------------------|----------------------------------------------------------------------------|
| Property | userAgent | Customize client api userAgent. |
| Property | appSettingsManager | A manager used to orchestrate AppSettings operations. |
| Property | transferManager | A manager used to orchestrate Transfers operations. |
| Property | fileManager | A manager used to orchestrate Files operations. |
| Property | accountManager | A manager used to orchestrate Accounts operations. |
| Property | inMemoryUploadManager | A manager used to perform Uploads operations, without session persistence. |
| Property | uploadManager | A manager used to orchestrate Uploads operations. |
| Property | emailTokensManager | A manager used to orchestrate EmailTokens operations. |
| Property | sharedApiUrlCreator | An utils to help use shared routes |

### Details of Properties and Methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,18 @@ class SharedApiUrlCreator internal constructor(
}

@Throws(RealmException::class)
fun uploadChunkUrl(uploadUUID: String, fileUUID: String, chunkIndex: Int, isLastChunk: Boolean): String? {
fun uploadChunkUrl(uploadUUID: String, fileUUID: String, chunkIndex: Int, isLastChunk: Boolean, isRetry: Boolean): String? {
val upload = uploadController.getUploadByUUID(uploadUUID) ?: return null
val containerUUID = upload.remoteContainer?.uuid ?: return null
val uploadHost = upload.remoteUploadHost ?: return null
return SharedApiRoutes.uploadChunk(uploadHost, containerUUID, fileUUID, chunkIndex, isLastChunk)
return SharedApiRoutes.uploadChunk(
uploadHost = uploadHost,
containerUUID = containerUUID,
fileUUID = fileUUID,
chunkIndex = chunkIndex,
isLastChunk = isLastChunk,
isRetry = isRetry
)
}

private val Transfer.notEmptyPassword get() = password?.takeIf { it.isNotEmpty() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.infomaniak.multiplatform_swisstransfer.utils.EmailLanguageUtils
* @property transferManager A manager used to orchestrate transfer operations.
* @property appSettingsManager A manager used to orchestrate AppSettings operations.
* @property accountManager A manager used to orchestrate Accounts operations.
* @property inMemoryUploadManager A manager used to perform Uploads operations, without session persistence.
* @property uploadManager A manager used to orchestrate Uploads operations.
* @property emailTokensManager A manager used to orchestrate EmailTokens operations.
* @property sharedApiUrlCreator An utils to help use shared routes.
Expand Down Expand Up @@ -98,6 +99,17 @@ class SwissTransferInjection(
)
}

/** A manager used to perform Uploads operations, without session persistence. */
val inMemoryUploadManager by lazy {
InMemoryUploadManager(
uploadController,
uploadRepository,
transferManager,
emailLanguageUtils,
emailTokensManager,
)
}

/** An utils to help use shared routes */
val sharedApiUrlCreator by lazy {
SharedApiUrlCreator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,40 @@ import com.infomaniak.multiplatform_swisstransfer.common.models.ValidityPeriod
data class NewUploadSession(
override val duration: ValidityPeriod,
override val authorEmail: String,
override val authorEmailToken: String?,
override val authorEmailToken: String? = null,
override val password: String,
override val message: String,
override val numberOfDownload: DownloadLimit,
override val language: EmailLanguage,
override val recipientsEmails: Set<String>,
override val files: List<UploadFileSession>,
override val uuid: String = "",
override val remoteContainer: UploadContainer?,
override val remoteUploadHost: String?,
) : UploadSession {
override val uuid: String = ""
override val remoteContainer: UploadContainer? = null
override val remoteUploadHost: String? = null

constructor(
duration: ValidityPeriod,
authorEmail: String,
authorEmailToken: String?,
password: String,
message: String,
numberOfDownload: DownloadLimit,
language: EmailLanguage,
recipientsEmails: Set<String>,
files: List<UploadFileSession>,
) : this (
duration = duration,
authorEmail = authorEmail,
authorEmailToken = authorEmailToken,
password = password,
message = message,
numberOfDownload = numberOfDownload,
language = language,
recipientsEmails = recipientsEmails,
files = files,
uuid = "",
remoteContainer = null,
remoteUploadHost = null
)
}
Loading

0 comments on commit 5f6c5e6

Please sign in to comment.