Skip to content

Commit

Permalink
feat: Automatically lookup the DB for an authorEmailToken when instan…
Browse files Browse the repository at this point in the history
…tiating NewUploadSession
  • Loading branch information
LunarX committed Dec 18, 2024
1 parent a3f731b commit 77f206b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ class SwissTransferInjection(
}

/** A manager used to orchestrate Uploads operations. */
val uploadManager by lazy { UploadManager(uploadController, uploadRepository, transferManager, emailLanguageUtils) }
val uploadManager by lazy {
UploadManager(
uploadController,
uploadRepository,
transferManager,
emailLanguageUtils,
emailTokensManager,
)
}

/** An utils to help use shared routes */
val sharedApiUrlCreator by lazy { SharedApiUrlCreator(environment, transferController, uploadController) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package com.infomaniak.multiplatform_swisstransfer.managers

import com.infomaniak.multiplatform_swisstransfer.common.exceptions.RealmException
import com.infomaniak.multiplatform_swisstransfer.common.exceptions.UnknownException
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadFileSession
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadSession
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferStatus
import com.infomaniak.multiplatform_swisstransfer.common.models.*
import com.infomaniak.multiplatform_swisstransfer.data.NewUploadSession
import com.infomaniak.multiplatform_swisstransfer.database.controllers.UploadController
import com.infomaniak.multiplatform_swisstransfer.exceptions.NotFoundException
Expand Down Expand Up @@ -56,6 +56,7 @@ class UploadManager(
private val uploadRepository: UploadRepository,
private val transferManager: TransferManager,
private val emailLanguageUtils: EmailLanguageUtils,
private val emailTokensManager: EmailTokensManager,
) {

val lastUploadFlow get() = uploadController.getLastUploadFlow().flowOn(Dispatchers.IO)
Expand Down Expand Up @@ -108,6 +109,27 @@ class UploadManager(
uploadController.insertAndGet(newUploadSession)
}

suspend fun generateNewUploadSession(
duration: ValidityPeriod,
authorEmail: String,
password: String,
message: String,
numberOfDownload: DownloadLimit,
language: EmailLanguage,
recipientsEmails: Set<String>,
files: List<UploadFileSession>,
): NewUploadSession = NewUploadSession(
duration = duration,
authorEmail = authorEmail,
authorEmailToken = emailTokensManager.getTokenForEmail(authorEmail),
password = password,
message = message,
numberOfDownload = numberOfDownload,
language = language,
recipientsEmails = recipientsEmails,
files = files,
)

/**
* Initializes an upload session and update it in database with the remote data.
*
Expand Down

0 comments on commit 77f206b

Please sign in to comment.