mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-06-30 19:15:50 +01:00
Use CDN number instead of parsing identifier for attachment remote id.
This commit is contained in:
+1
-1
@@ -138,7 +138,7 @@ class ConversationItemPreviewer {
|
||||
private fun attachment(): SignalServiceAttachmentPointer {
|
||||
return SignalServiceAttachmentPointer(
|
||||
Cdn.CDN_3.cdnNumber,
|
||||
SignalServiceAttachmentRemoteId.from(""),
|
||||
SignalServiceAttachmentRemoteId.from("", Cdn.CDN_3.cdnNumber),
|
||||
"image/webp",
|
||||
null,
|
||||
Optional.empty(),
|
||||
|
||||
@@ -146,7 +146,7 @@ object TestMessages {
|
||||
private fun imageAttachment(): SignalServiceAttachmentPointer {
|
||||
return SignalServiceAttachmentPointer(
|
||||
Cdn.S3.cdnNumber,
|
||||
SignalServiceAttachmentRemoteId.from(""),
|
||||
SignalServiceAttachmentRemoteId.from("", Cdn.S3.cdnNumber),
|
||||
"image/webp",
|
||||
null,
|
||||
Optional.empty(),
|
||||
@@ -170,7 +170,7 @@ object TestMessages {
|
||||
private fun voiceAttachment(): SignalServiceAttachmentPointer {
|
||||
return SignalServiceAttachmentPointer(
|
||||
Cdn.S3.cdnNumber,
|
||||
SignalServiceAttachmentRemoteId.from(""),
|
||||
SignalServiceAttachmentRemoteId.from("", Cdn.S3.cdnNumber),
|
||||
"audio/aac",
|
||||
null,
|
||||
Optional.empty(),
|
||||
|
||||
@@ -31,7 +31,7 @@ fun Attachment.toAttachmentPointer(context: Context): AttachmentPointer? {
|
||||
}
|
||||
|
||||
try {
|
||||
val remoteId = SignalServiceAttachmentRemoteId.from(attachment.remoteLocation!!)
|
||||
val remoteId = SignalServiceAttachmentRemoteId.from(attachment.remoteLocation!!, attachment.cdn.cdnNumber)
|
||||
|
||||
var attachmentWidth = attachment.width
|
||||
var attachmentHeight = attachment.height
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ fun DatabaseAttachment.createArchiveAttachmentPointer(useArchiveCdn: Boolean): S
|
||||
throw InvalidAttachmentException("empty content id")
|
||||
}
|
||||
|
||||
SignalServiceAttachmentRemoteId.from(remoteLocation) to cdn.cdnNumber
|
||||
SignalServiceAttachmentRemoteId.from(remoteLocation, cdn.cdnNumber) to cdn.cdnNumber
|
||||
}
|
||||
|
||||
val key = Base64.decode(remoteKey)
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ fun FilePointer?.toLocalAttachment(
|
||||
AttachmentType.TRANSIT -> {
|
||||
val signalAttachmentPointer = SignalServiceAttachmentPointer(
|
||||
cdnNumber = locatorInfo.transitCdnNumber ?: Cdn.CDN_0.cdnNumber,
|
||||
remoteId = SignalServiceAttachmentRemoteId.from(locatorInfo.transitCdnKey!!),
|
||||
remoteId = SignalServiceAttachmentRemoteId.from(locatorInfo.transitCdnKey!!, locatorInfo.transitCdnNumber ?: Cdn.CDN_0.cdnNumber),
|
||||
contentType = contentType,
|
||||
key = locatorInfo.key.toByteArray(),
|
||||
size = Optional.ofNullable(locatorInfo.size),
|
||||
|
||||
@@ -399,8 +399,8 @@ class AttachmentDownloadJob private constructor(
|
||||
}
|
||||
|
||||
return try {
|
||||
val remoteId = SignalServiceAttachmentRemoteId.from(attachment.remoteLocation)
|
||||
val cdnNumber = attachment.cdn.cdnNumber
|
||||
val remoteId = SignalServiceAttachmentRemoteId.from(attachment.remoteLocation, cdnNumber)
|
||||
|
||||
val key = Base64.decode(attachment.remoteKey)
|
||||
|
||||
|
||||
@@ -282,7 +282,7 @@ abstract class PushSendJob protected constructor(parameters: Parameters) : BaseJ
|
||||
}
|
||||
|
||||
try {
|
||||
val remoteId = SignalServiceAttachmentRemoteId.from(attachment.remoteLocation!!)
|
||||
val remoteId = SignalServiceAttachmentRemoteId.from(attachment.remoteLocation!!, attachment.cdn.cdnNumber)
|
||||
val key = Base64.decode(attachment.remoteKey!!)
|
||||
|
||||
var width = attachment.width
|
||||
|
||||
+1
-1
@@ -215,7 +215,7 @@ private fun Attachment.toAttachmentPointerProto(): Either<DataMessageError, Atta
|
||||
raise(DataMessageError.MissingAttachmentRemoteFields)
|
||||
}
|
||||
|
||||
val remoteIdResolved: SignalServiceAttachmentRemoteId = SignalServiceAttachmentRemoteId.from(remoteLocation)
|
||||
val remoteIdResolved: SignalServiceAttachmentRemoteId = SignalServiceAttachmentRemoteId.from(remoteLocation, cdn.cdnNumber)
|
||||
|
||||
val keyBytes: ByteArray = try {
|
||||
Base64.decode(remoteKey)
|
||||
|
||||
+9
-6
@@ -30,6 +30,9 @@ sealed interface SignalServiceAttachmentRemoteId {
|
||||
|
||||
companion object {
|
||||
|
||||
/** The lowest CDN number that uses opaque string keys rather than numeric ids */
|
||||
private const val FIRST_KEY_BASED_CDN = 3
|
||||
|
||||
@JvmStatic
|
||||
@Throws(InvalidMessageStructureException::class)
|
||||
fun from(attachmentPointer: AttachmentPointer): SignalServiceAttachmentRemoteId {
|
||||
@@ -42,13 +45,13 @@ sealed interface SignalServiceAttachmentRemoteId {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Guesses that strings which contain values parseable to `long` should use an id-based
|
||||
* CDN path. Otherwise, use key-based CDN path.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun from(string: String): SignalServiceAttachmentRemoteId {
|
||||
return string.toLongOrNull()?.let { V2(it) } ?: V4(string)
|
||||
fun from(string: String, cdnNumber: Int): SignalServiceAttachmentRemoteId {
|
||||
return if (cdnNumber >= FIRST_KEY_BASED_CDN) {
|
||||
V4(string)
|
||||
} else {
|
||||
string.toLongOrNull()?.let { V2(it) } ?: V4(string)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user