From b2ef5b3ee35c13d927a73b6d0d83c223b0fe234e Mon Sep 17 00:00:00 2001 From: ThibaultBee Date: Wed, 25 Sep 2024 11:38:44 +0000 Subject: [PATCH] fix(java): android: hash token and video id for workmanager API --- .../api/uploader/api/work/UploadWorkerHelper.kt | 5 +++-- .../java/video/api/uploader/api/work/utils/Hash.kt | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/main/java/video/api/uploader/api/work/utils/Hash.kt diff --git a/src/main/java/video/api/uploader/api/work/UploadWorkerHelper.kt b/src/main/java/video/api/uploader/api/work/UploadWorkerHelper.kt index b912330..5cf99f4 100644 --- a/src/main/java/video/api/uploader/api/work/UploadWorkerHelper.kt +++ b/src/main/java/video/api/uploader/api/work/UploadWorkerHelper.kt @@ -8,6 +8,7 @@ import androidx.work.WorkManager import video.api.uploader.api.upload.IProgressiveUploadSession import video.api.uploader.api.work.UploadWorkerHelper.upload import video.api.uploader.api.work.stores.ProgressiveUploadSessionStore +import video.api.uploader.api.work.utils.md5 import video.api.uploader.api.work.workers.ProgressiveUploadWorker import video.api.uploader.api.work.workers.UploadWorker import java.io.File @@ -418,7 +419,7 @@ object UploadWorkerHelper { * @return The tag */ fun getTagForVideoId(videoId: String): String { - return "($PREFIX_VIDEO_ID$videoId)" + return "($PREFIX_VIDEO_ID${videoId.md5()})" } /** @@ -428,7 +429,7 @@ object UploadWorkerHelper { * @return The tag */ fun getTagForUploadToken(token: String): String { - return "($PREFIX_TOKEN$token)" + return "($PREFIX_TOKEN${token.md5()})" } private const val PREFIX_VIDEO_ID = "videoId=" diff --git a/src/main/java/video/api/uploader/api/work/utils/Hash.kt b/src/main/java/video/api/uploader/api/work/utils/Hash.kt new file mode 100644 index 0000000..4443822 --- /dev/null +++ b/src/main/java/video/api/uploader/api/work/utils/Hash.kt @@ -0,0 +1,14 @@ +package video.api.uploader.api.work.utils + +import java.security.MessageDigest + +fun String.md5(): String { + return hashString(this, "MD5") +} + +private fun hashString(input: String, algorithm: String): String { + return MessageDigest + .getInstance(algorithm) + .digest(input.toByteArray()) + .fold("") { str, it -> str + "%02x".format(it) } +} \ No newline at end of file