Skip to content

Commit

Permalink
add timestamp to liveness image filename (#14)
Browse files Browse the repository at this point in the history
* add timestamp to liveness image filename

* Update Util.kt

* Update UtilTest.kt
  • Loading branch information
mldangelo authored Feb 1, 2023
1 parent 84c70b0 commit bb906d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ui/src/main/java/com/smileidentity/ui/core/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ internal fun postProcessImageFile(
* format "si_${imageType}_<random number>.jpg"
*/
internal fun createSmileTempFile(imageType: String): File {
return File.createTempFile("si_${imageType}_", ".jpg").apply {
return File.createTempFile("si_${imageType}_${System.currentTimeMillis()}_", ".jpg").apply {
// Deletes file when the *VM* is exited (*not* when the app is closed)
deleteOnExit()
}
Expand Down
21 changes: 21 additions & 0 deletions ui/src/test/java/com/smileidentity/ui/core/UtilTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.smileidentity.ui.core

import org.junit.Assert.assertTrue
import org.junit.Test

class UtilTest {

@Test
fun `should add timestamp to filename`() {
val file = createLivenessFile()
// name is si_liveness_{timestamp}_{random_indentifier}.jpg
val stringTokens = file.name.split("_")
val timestamp = stringTokens[stringTokens.size - 2]
val timestampLong = timestamp.toLong()
assertTrue(
timestampLong in (
System.currentTimeMillis() - 1000
)..(System.currentTimeMillis()),
)
}
}

0 comments on commit bb906d5

Please sign in to comment.