-
Notifications
You must be signed in to change notification settings - Fork 58
fix: prevent downloaded media filename collisions #2353
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,25 +8,29 @@ public object MediaFileNamePolicy { | |
| statusKey: String, | ||
| userHandle: String, | ||
| media: UiMedia, | ||
| ): String { | ||
| val key = sanitizeFileName(statusKey) | ||
| val handle = sanitizeFileName(userHandle) | ||
| val extension = extensionFromUrl(url = media.url, fallbackExtension = media.fallbackExtension) | ||
| return "${key}_$handle.$extension" | ||
| } | ||
| mediaIndex: Int, | ||
|
Comment on lines
10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the iOS workflow in Useful? React with 👍 / 👎. |
||
| ): String = | ||
| statusMediaBaseFileName( | ||
| statusKey = statusKey, | ||
| userHandle = userHandle, | ||
| media = media, | ||
| ).withIndexSuffix( | ||
| index = mediaIndex.coerceAtLeast(0) + 1, | ||
| width = 2, | ||
| ) | ||
|
|
||
| public fun statusMediaFileNames( | ||
| statusKey: String, | ||
| userHandle: String, | ||
| medias: List<UiMedia>, | ||
| ): Map<String, UiMedia> { | ||
| val key = sanitizeFileName(statusKey) | ||
| val handle = sanitizeFileName(userHandle) | ||
| return indexedMediaFileNames(medias) { media -> | ||
| val extension = extensionFromUrl(url = media.url, fallbackExtension = media.fallbackExtension) | ||
| "${key}_$handle.$extension" | ||
| ): Map<String, UiMedia> = | ||
| indexedMediaFileNames(medias) { media -> | ||
| statusMediaBaseFileName( | ||
| statusKey = statusKey, | ||
| userHandle = userHandle, | ||
| media = media, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| public fun rawMediaFileName(media: UiMedia): String { | ||
| val path = media.url.cleanUrlPath() | ||
|
|
@@ -146,6 +150,17 @@ public object MediaFileNamePolicy { | |
| return lastDotIndex > 0 && lastDotIndex < name.length - 1 | ||
| } | ||
|
|
||
| private fun statusMediaBaseFileName( | ||
| statusKey: String, | ||
| userHandle: String, | ||
| media: UiMedia, | ||
| ): String { | ||
| val key = sanitizeFileName(statusKey) | ||
| val handle = sanitizeFileName(userHandle) | ||
| val extension = extensionFromUrl(url = media.url, fallbackExtension = media.fallbackExtension) | ||
| return "${key}_$handle.$extension" | ||
| } | ||
|
|
||
| private fun indexedMediaFileNames( | ||
| medias: List<UiMedia>, | ||
| fileName: (UiMedia) -> String, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a status contains multiple audio entries with the same URL,
firstIndexreturns the first position for every entry, so iOS save-all gives them all the same_01filename and can overwrite or conflate separate exports (the entries may still differ by headers or metadata). The same URL-only lookup appears inMediaViewerScreen.swift; pass the enumerated/selected position instead of recovering it from a non-unique URL.Useful? React with 👍 / 👎.