Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(java): android: hash token and video id for workmanager API #98

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) }
}
Loading