mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-06-12 05:30:48 +02:00
[API] Fix downloading attachments with different name. Handle UTF encoded download names.
This commit is contained in:
@ -35,6 +35,7 @@ class OneDriveDownloadAttachment(
|
||||
.callback(object : TextCallbackHandler() {
|
||||
override fun onSuccess(text: String, response: Response) {
|
||||
val location = response.headers().get("Location")
|
||||
// https://onedrive.live.com/redir?resid=D75496A2EB87531C!706&authkey=!ABjZeh3pHMqj11Q
|
||||
if (location?.contains("onedrive.live.com/redir?resid=") != true) {
|
||||
onError(ApiError(TAG, ERROR_ONEDRIVE_DOWNLOAD)
|
||||
.withApiResponse(text)
|
||||
@ -43,7 +44,8 @@ class OneDriveDownloadAttachment(
|
||||
}
|
||||
val url = location
|
||||
.replace("onedrive.live.com/redir?resid=", "storage.live.com/items/")
|
||||
.replace("&", "?")
|
||||
.replace("?", "&")
|
||||
.replaceFirst("&", "?")
|
||||
downloadFile(url)
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,20 @@ class AttachmentsView @JvmOverloads constructor(
|
||||
try {
|
||||
val attachmentFileName = Utils.getStringFromFile(attachmentDataFile)
|
||||
val attachmentFile = File(attachmentFileName)
|
||||
attachmentFile.exists()
|
||||
// get the correct file name and update
|
||||
if (attachmentFile.exists()) {
|
||||
|
||||
// get the download url before updating file name
|
||||
val fileUrl = item.name.substringAfter(":", missingDelimiterValue = "")
|
||||
// update file name with the downloaded one
|
||||
item.name = attachmentFile.name
|
||||
// save the download url back
|
||||
if (fileUrl != "")
|
||||
item.name += ":$fileUrl"
|
||||
|
||||
true
|
||||
}
|
||||
else false
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
false
|
||||
@ -141,7 +154,7 @@ class AttachmentsView @JvmOverloads constructor(
|
||||
attachment.isDownloaded = true
|
||||
|
||||
// get the download url before updating file name
|
||||
val fileUrl = attachment.name.substringBefore(":", missingDelimiterValue = "")
|
||||
val fileUrl = attachment.name.substringAfter(":", missingDelimiterValue = "")
|
||||
// update file name with the downloaded one
|
||||
attachment.name = File(event.fileName).name
|
||||
// save the download url back
|
||||
|
Reference in New Issue
Block a user