mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-28 20:29:53 +00:00
desktop, android: use timestamp as file name for videos (#5539)
* desktop, android: hide file name on video uploads * indirection * never makeup extensions * param instead of fn * format * replaced comment --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
This commit is contained in:
parent
9cf2b5a1e4
commit
5bd8dc1f71
2 changed files with 19 additions and 5 deletions
|
@ -610,7 +610,7 @@ fun ComposeView(
|
||||||
if (remoteHost == null) saveAnimImage(it.uri)
|
if (remoteHost == null) saveAnimImage(it.uri)
|
||||||
else CryptoFile.desktopPlain(it.uri)
|
else CryptoFile.desktopPlain(it.uri)
|
||||||
is UploadContent.Video ->
|
is UploadContent.Video ->
|
||||||
if (remoteHost == null) saveFileFromUri(it.uri)
|
if (remoteHost == null) saveFileFromUri(it.uri, hiddenFileNamePrefix = "video")
|
||||||
else CryptoFile.desktopPlain(it.uri)
|
else CryptoFile.desktopPlain(it.uri)
|
||||||
}
|
}
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
|
|
|
@ -247,13 +247,26 @@ fun saveAnimImage(uri: URI): CryptoFile? {
|
||||||
|
|
||||||
expect suspend fun saveTempImageUncompressed(image: ImageBitmap, asPng: Boolean): File?
|
expect suspend fun saveTempImageUncompressed(image: ImageBitmap, asPng: Boolean): File?
|
||||||
|
|
||||||
fun saveFileFromUri(uri: URI, withAlertOnException: Boolean = true): CryptoFile? {
|
fun saveFileFromUri(
|
||||||
|
uri: URI,
|
||||||
|
withAlertOnException: Boolean = true,
|
||||||
|
hiddenFileNamePrefix: String? = null
|
||||||
|
): CryptoFile? {
|
||||||
return try {
|
return try {
|
||||||
val encrypted = chatController.appPrefs.privacyEncryptLocalFiles.get()
|
val encrypted = chatController.appPrefs.privacyEncryptLocalFiles.get()
|
||||||
val inputStream = uri.inputStream()
|
val inputStream = uri.inputStream()
|
||||||
val fileToSave = getFileName(uri)
|
val fileToSave = getFileName(uri)
|
||||||
return if (inputStream != null && fileToSave != null) {
|
return if (inputStream != null && fileToSave != null) {
|
||||||
val destFileName = uniqueCombine(fileToSave, File(getAppFilePath("")))
|
val destFileName = if (hiddenFileNamePrefix == null) {
|
||||||
|
uniqueCombine(fileToSave, File(getAppFilePath("")))
|
||||||
|
} else {
|
||||||
|
val ext = when {
|
||||||
|
// remove everything but extension
|
||||||
|
fileToSave.contains(".") -> fileToSave.substringAfterLast(".")
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
generateNewFileName(hiddenFileNamePrefix, ext, File(getAppFilePath("")))
|
||||||
|
}
|
||||||
val destFile = File(getAppFilePath(destFileName))
|
val destFile = File(getAppFilePath(destFileName))
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
createTmpFileAndDelete { tmpFile ->
|
createTmpFileAndDelete { tmpFile ->
|
||||||
|
@ -353,11 +366,12 @@ fun <T> createTmpFileAndDelete(dir: File = tmpDir, onCreated: (File) -> T): T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateNewFileName(prefix: String, ext: String, dir: File): String {
|
fun generateNewFileName(prefix: String, ext: String?, dir: File): String {
|
||||||
val sdf = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US)
|
val sdf = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US)
|
||||||
sdf.timeZone = TimeZone.getTimeZone("GMT")
|
sdf.timeZone = TimeZone.getTimeZone("GMT")
|
||||||
val timestamp = sdf.format(Date())
|
val timestamp = sdf.format(Date())
|
||||||
return uniqueCombine("${prefix}_$timestamp.$ext", dir)
|
val extension = if (ext != null) ".$ext" else ""
|
||||||
|
return uniqueCombine("${prefix}_$timestamp$extension", dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uniqueCombine(fileName: String, dir: File): String {
|
fun uniqueCombine(fileName: String, dir: File): String {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue