Skip to content

Commit

Permalink
Merge pull request #98 from apivideo/bugfix/java_android_work_tags
Browse files Browse the repository at this point in the history
fix(java): android: hash token and video id for workmanager API
  • Loading branch information
bot-api-video authored Sep 25, 2024
2 parents 79f0b62 + b2ef5b3 commit 8bdf2aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.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) }
}

0 comments on commit 8bdf2aa

Please sign in to comment.