Skip to content

Commit

Permalink
fix(java): android: hash token and video id for workmanager API
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee authored Sep 25, 2024
1 parent 9559f04 commit 6539d91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/video/api/client/api/work/UploadWorkerHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.work.WorkManager
import video.api.client.api.upload.IProgressiveUploadSession
import video.api.client.api.work.UploadWorkerHelper.upload
import video.api.client.api.work.stores.ProgressiveUploadSessionStore
import video.api.client.api.work.utils.md5
import video.api.client.api.work.workers.ProgressiveUploadWorker
import video.api.client.api.work.workers.UploadWorker
import java.io.File
Expand Down Expand Up @@ -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()})"
}

/**
Expand All @@ -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="
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/video/api/uploader/api/work/utils/Hash.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package video.api.client.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) }
}

0 comments on commit 6539d91

Please sign in to comment.