mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-06 14:03:45 +01:00
Merge pull request #1244 from vector-im/feature/media_path
Fix download and upload media path
This commit is contained in:
commit
7961423556
@ -7,7 +7,6 @@ Features ✨:
|
|||||||
- Cross-Signing | Verify new session from existing session (#1134)
|
- Cross-Signing | Verify new session from existing session (#1134)
|
||||||
- Cross-Signing | Bootstraping cross signing with 4S from mobile (#985)
|
- Cross-Signing | Bootstraping cross signing with 4S from mobile (#985)
|
||||||
|
|
||||||
|
|
||||||
Improvements 🙌:
|
Improvements 🙌:
|
||||||
- Verification DM / Handle concurrent .start after .ready (#794)
|
- Verification DM / Handle concurrent .start after .ready (#794)
|
||||||
- Reimplementation of multiple attachment picker
|
- Reimplementation of multiple attachment picker
|
||||||
@ -34,6 +33,7 @@ Bugfix 🐛:
|
|||||||
- Fix crash when trying to download file without internet connection (#1229)
|
- Fix crash when trying to download file without internet connection (#1229)
|
||||||
- Local echo are not updated in timeline (for failed & encrypted states)
|
- Local echo are not updated in timeline (for failed & encrypted states)
|
||||||
- Render image event even if thumbnail_info does not have mimetype defined (#1209)
|
- Render image event even if thumbnail_info does not have mimetype defined (#1209)
|
||||||
|
- Fix issue with media path (#1227)
|
||||||
|
|
||||||
Translations 🗣:
|
Translations 🗣:
|
||||||
-
|
-
|
||||||
|
@ -26,6 +26,11 @@ interface ContentUrlResolver {
|
|||||||
SCALE("scale")
|
SCALE("scale")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL to use to upload content
|
||||||
|
*/
|
||||||
|
val uploadUrl: String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the actual URL for accessing the full-size image of a Matrix media content URI.
|
* Get the actual URL for accessing the full-size image of a Matrix media content URI.
|
||||||
*
|
*
|
||||||
|
@ -18,46 +18,46 @@ package im.vector.matrix.android.internal.session.content
|
|||||||
|
|
||||||
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
||||||
import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
||||||
|
import im.vector.matrix.android.internal.network.NetworkConstants
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val MATRIX_CONTENT_URI_SCHEME = "mxc://"
|
private const val MATRIX_CONTENT_URI_SCHEME = "mxc://"
|
||||||
private const val URI_PREFIX_CONTENT_API = "_matrix/media/v1/"
|
|
||||||
|
|
||||||
internal class DefaultContentUrlResolver @Inject constructor(private val homeServerConnectionConfig: HomeServerConnectionConfig) : ContentUrlResolver {
|
internal class DefaultContentUrlResolver @Inject constructor(homeServerConnectionConfig: HomeServerConnectionConfig) : ContentUrlResolver {
|
||||||
|
|
||||||
companion object {
|
private val baseUrl = homeServerConnectionConfig.homeServerUri.toString()
|
||||||
fun getUploadUrl(homeServerConnectionConfig: HomeServerConnectionConfig): String {
|
private val sep = if (baseUrl.endsWith("/")) "" else "/"
|
||||||
val baseUrl = homeServerConnectionConfig.homeServerUri.toString()
|
|
||||||
val sep = if (baseUrl.endsWith("/")) "" else "/"
|
|
||||||
|
|
||||||
return baseUrl + sep + URI_PREFIX_CONTENT_API + "upload"
|
override val uploadUrl = baseUrl + sep + NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "upload"
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun resolveFullSize(contentUrl: String?): String? {
|
override fun resolveFullSize(contentUrl: String?): String? {
|
||||||
if (contentUrl?.isValidMatrixContentUrl() == true) {
|
return contentUrl
|
||||||
val baseUrl = homeServerConnectionConfig.homeServerUri.toString()
|
// do not allow non-mxc content URLs
|
||||||
val prefix = URI_PREFIX_CONTENT_API + "download/"
|
?.takeIf { it.isValidMatrixContentUrl() }
|
||||||
return resolve(baseUrl, contentUrl, prefix)
|
?.let {
|
||||||
}
|
resolve(
|
||||||
return null
|
contentUrl = it,
|
||||||
|
prefix = NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "download/"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resolveThumbnail(contentUrl: String?, width: Int, height: Int, method: ContentUrlResolver.ThumbnailMethod): String? {
|
override fun resolveThumbnail(contentUrl: String?, width: Int, height: Int, method: ContentUrlResolver.ThumbnailMethod): String? {
|
||||||
if (contentUrl?.isValidMatrixContentUrl() == true) {
|
return contentUrl
|
||||||
val baseUrl = homeServerConnectionConfig.homeServerUri.toString()
|
// do not allow non-mxc content URLs
|
||||||
val prefix = URI_PREFIX_CONTENT_API + "thumbnail/"
|
?.takeIf { it.isValidMatrixContentUrl() }
|
||||||
val params = "?width=$width&height=$height&method=${method.value}"
|
?.let {
|
||||||
return resolve(baseUrl, contentUrl, prefix, params)
|
resolve(
|
||||||
}
|
contentUrl = it,
|
||||||
// do not allow non-mxc content URLs
|
prefix = NetworkConstants.URI_API_MEDIA_PREFIX_PATH_R0 + "thumbnail/",
|
||||||
return null
|
params = "?width=$width&height=$height&method=${method.value}"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resolve(baseUrl: String,
|
private fun resolve(contentUrl: String,
|
||||||
contentUrl: String,
|
|
||||||
prefix: String,
|
prefix: String,
|
||||||
params: String? = null): String? {
|
params: String = ""): String? {
|
||||||
var serverAndMediaId = contentUrl.removePrefix(MATRIX_CONTENT_URI_SCHEME)
|
var serverAndMediaId = contentUrl.removePrefix(MATRIX_CONTENT_URI_SCHEME)
|
||||||
val fragmentOffset = serverAndMediaId.indexOf("#")
|
val fragmentOffset = serverAndMediaId.indexOf("#")
|
||||||
var fragment = ""
|
var fragment = ""
|
||||||
@ -66,9 +66,7 @@ internal class DefaultContentUrlResolver @Inject constructor(private val homeSer
|
|||||||
serverAndMediaId = serverAndMediaId.substring(0, fragmentOffset)
|
serverAndMediaId = serverAndMediaId.substring(0, fragmentOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
val sep = if (baseUrl.endsWith("/")) "" else "/"
|
return baseUrl + sep + prefix + serverAndMediaId + params + fragment
|
||||||
|
|
||||||
return baseUrl + sep + prefix + serverAndMediaId + (params ?: "") + fragment
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.isValidMatrixContentUrl(): Boolean {
|
private fun String.isValidMatrixContentUrl(): Boolean {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package im.vector.matrix.android.internal.session.content
|
package im.vector.matrix.android.internal.session.content
|
||||||
|
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
||||||
import im.vector.matrix.android.internal.di.Authenticated
|
import im.vector.matrix.android.internal.di.Authenticated
|
||||||
import im.vector.matrix.android.internal.network.ProgressRequestBody
|
import im.vector.matrix.android.internal.network.ProgressRequestBody
|
||||||
import im.vector.matrix.android.internal.network.awaitResponse
|
import im.vector.matrix.android.internal.network.awaitResponse
|
||||||
@ -37,10 +37,10 @@ import javax.inject.Inject
|
|||||||
internal class FileUploader @Inject constructor(@Authenticated
|
internal class FileUploader @Inject constructor(@Authenticated
|
||||||
private val okHttpClient: OkHttpClient,
|
private val okHttpClient: OkHttpClient,
|
||||||
private val eventBus: EventBus,
|
private val eventBus: EventBus,
|
||||||
sessionParams: SessionParams,
|
contentUrlResolver: ContentUrlResolver,
|
||||||
moshi: Moshi) {
|
moshi: Moshi) {
|
||||||
|
|
||||||
private val uploadUrl = DefaultContentUrlResolver.getUploadUrl(sessionParams.homeServerConnectionConfig)
|
private val uploadUrl = contentUrlResolver.uploadUrl
|
||||||
private val responseAdapter = moshi.adapter(ContentUploadResponse::class.java)
|
private val responseAdapter = moshi.adapter(ContentUploadResponse::class.java)
|
||||||
|
|
||||||
suspend fun uploadFile(file: File,
|
suspend fun uploadFile(file: File,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user