asset_uploads.proto 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. syntax = "proto3";
  2. package chatto.api.v1;
  3. import "buf/validate/validate.proto";
  4. import "chatto/api/v1/attachments.proto";
  5. import "google/protobuf/timestamp.proto";
  6. // Upload lifecycle state for a room-scoped attachment upload.
  7. enum AssetUploadStatus {
  8. // The upload status was not specified.
  9. ASSET_UPLOAD_STATUS_UNSPECIFIED = 0;
  10. // The upload accepts more chunks.
  11. ASSET_UPLOAD_STATUS_OPEN = 1;
  12. // The upload has been completed and produced an attachment asset.
  13. ASSET_UPLOAD_STATUS_COMPLETED = 2;
  14. // The upload was cancelled or expired.
  15. ASSET_UPLOAD_STATUS_CANCELLED = 3;
  16. }
  17. // Current server-side state for one room-scoped attachment upload.
  18. message AssetUpload {
  19. // Upload session ID.
  20. string upload_id = 1;
  21. // Room the resulting attachment asset will belong to.
  22. string room_id = 2;
  23. // Current upload status.
  24. AssetUploadStatus status = 3;
  25. // Number of bytes committed so far.
  26. int64 committed_offset = 4;
  27. // Total declared file size in bytes.
  28. int64 size = 5;
  29. // Maximum accepted chunk size in bytes.
  30. int32 max_chunk_size = 6;
  31. // SHA-256 digest of the complete file, lowercase hexadecimal.
  32. string sha256 = 7;
  33. // Upload expiry. Clients should create a new upload after this time.
  34. google.protobuf.Timestamp expires_at = 8;
  35. // Asset ID after completion.
  36. string asset_id = 9;
  37. }
  38. // Request to start a room-scoped attachment upload.
  39. message CreateUploadRequest {
  40. reserved 6, 7;
  41. reserved "thread_root_event_id", "also_send_to_channel";
  42. // Required room ID.
  43. string room_id = 1 [(buf.validate.field).string.min_len = 1];
  44. // Original filename supplied by the client.
  45. string filename = 2 [(buf.validate.field).string.min_len = 1];
  46. // MIME content type. Empty values are treated as application/octet-stream.
  47. string content_type = 3;
  48. // Required total file size in bytes.
  49. int64 size = 4 [(buf.validate.field).int64.gte = 0];
  50. // Required SHA-256 digest of the complete file, lowercase hexadecimal.
  51. string sha256 = 5 [(buf.validate.field).string = {
  52. pattern: "^[a-f0-9]{64}$"
  53. }];
  54. }
  55. // Response after creating an upload.
  56. message CreateUploadResponse {
  57. // Created upload session.
  58. AssetUpload upload = 1;
  59. }
  60. // Request to append one chunk to an upload.
  61. message UploadChunkRequest {
  62. // Required upload session ID.
  63. string upload_id = 1 [(buf.validate.field).string.min_len = 1];
  64. // Byte offset where this chunk starts.
  65. int64 offset = 2 [(buf.validate.field).int64.gte = 0];
  66. // Chunk bytes. The server enforces a per-RPC size limit.
  67. bytes content = 3 [(buf.validate.field).bytes.min_len = 1];
  68. // SHA-256 digest of this chunk, lowercase hexadecimal.
  69. string chunk_sha256 = 4 [(buf.validate.field).string = {
  70. pattern: "^[a-f0-9]{64}$"
  71. }];
  72. }
  73. // Response after committing an upload chunk.
  74. message UploadChunkResponse {
  75. // Updated upload session.
  76. AssetUpload upload = 1;
  77. }
  78. // Request to fetch upload state.
  79. message GetUploadRequest {
  80. // Required upload session ID.
  81. string upload_id = 1 [(buf.validate.field).string.min_len = 1];
  82. }
  83. // Response containing upload state.
  84. message GetUploadResponse {
  85. // Current upload session.
  86. AssetUpload upload = 1;
  87. }
  88. // Request to complete an upload and create its attachment asset.
  89. message CompleteUploadRequest {
  90. // Required upload session ID.
  91. string upload_id = 1 [(buf.validate.field).string.min_len = 1];
  92. }
  93. // Response after an upload completes.
  94. message CompleteUploadResponse {
  95. // Completed upload session.
  96. AssetUpload upload = 1;
  97. // Attachment asset produced by this upload.
  98. Asset asset = 2;
  99. }
  100. // Request to cancel an upload.
  101. message CancelUploadRequest {
  102. // Required upload session ID.
  103. string upload_id = 1 [(buf.validate.field).string.min_len = 1];
  104. }
  105. // Response after cancelling an upload.
  106. message CancelUploadResponse {
  107. // Updated upload session.
  108. AssetUpload upload = 1;
  109. }
  110. // Creates room-scoped attachment assets through chunked ConnectRPC uploads.
  111. service AssetUploadService {
  112. // Starts a room-scoped attachment upload for the authenticated user.
  113. rpc CreateUpload(CreateUploadRequest) returns (CreateUploadResponse);
  114. // Appends one chunk at the upload's current committed offset.
  115. rpc UploadChunk(UploadChunkRequest) returns (UploadChunkResponse);
  116. // Reads current upload state for retry or resume.
  117. rpc GetUpload(GetUploadRequest) returns (GetUploadResponse);
  118. // Verifies the completed upload and creates the attachment asset.
  119. rpc CompleteUpload(CompleteUploadRequest) returns (CompleteUploadResponse);
  120. // Cancels an incomplete upload and releases temporary storage.
  121. rpc CancelUpload(CancelUploadRequest) returns (CancelUploadResponse);
  122. }