Add error reporting to /v1/devices/transfer_archive

This commit is contained in:
ravi-signal
2024-11-25 14:41:51 -06:00
committed by GitHub
parent 3ba7ba4f92
commit 49d6a5e32d
8 changed files with 145 additions and 28 deletions

View File

@@ -8,6 +8,7 @@ package org.whispersystems.textsecuregcm.entities;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import org.whispersystems.textsecuregcm.util.ValidBase64URLString;
public record RemoteAttachment(
@@ -17,6 +18,6 @@ public record RemoteAttachment(
@NotBlank
@ValidBase64URLString
@Schema(description = "The attachment key")
String key) {
}
@Size(max = 64)
@Schema(description = "The attachment key", maxLength = 64)
String key) implements TransferArchiveResult {}

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.entities;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
@Schema(description = "Indicates an attachment failed to upload")
public record RemoteAttachmentError(
@Schema(description = "The type of error encountered")
@Valid @NotNull ErrorType error)
implements TransferArchiveResult {
public enum ErrorType {
RELINK_REQUESTED,
CONTINUE_WITHOUT_UPLOAD;
}
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.entities;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import io.swagger.v3.oas.annotations.media.Schema;
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
@JsonSubTypes({
@JsonSubTypes.Type(value = RemoteAttachment.class, name = "success"),
@JsonSubTypes.Type(value = RemoteAttachmentError.class, name = "error"),
})
@Schema(description = """
The location of the transfer archive if the archive was successfully uploaded, otherwise a error indicating that
the upload has failed and the destination device should stop waiting
""", oneOf = {RemoteAttachmentError.class, RemoteAttachment.class})
public sealed interface TransferArchiveResult permits RemoteAttachment, RemoteAttachmentError {}

View File

@@ -9,19 +9,20 @@ import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import org.whispersystems.textsecuregcm.storage.Device;
public record TransferArchiveUploadedRequest(@Min(1)
@Max(Device.MAXIMUM_DEVICE_ID)
@Schema(description = "The ID of the device for which the transfer archive has been prepared")
byte destinationDeviceId,
public record TransferArchiveUploadedRequest(
@Min(1)
@Max(Device.MAXIMUM_DEVICE_ID)
@Schema(description = "The ID of the device for which the transfer archive has been prepared")
byte destinationDeviceId,
@Positive
@Schema(description = "The timestamp, in milliseconds since the epoch, at which the destination device was created")
long destinationDeviceCreated,
@Positive
@Schema(description = "The timestamp, in milliseconds since the epoch, at which the destination device was created")
long destinationDeviceCreated,
@Schema(description = "The location of the transfer archive")
@Valid
RemoteAttachment transferArchive) {
}
@NotNull
@Valid
TransferArchiveResult transferArchive) {}