@@ -21,20 +21,24 @@ common::Result<InitUploadResponse> AttachmentService::InitUpload(const common::U
2121 std::int64_t file_size,
2222 const std::string& mime_hint) {
2323 if (file_size <= 0 ) {
24- return std::unexpected (common::Error{common::ErrorCode::kInvalidArgument , " File size must be positive" });
24+ return std::unexpected (
25+ common::Error{.code = common::ErrorCode::kInvalidArgument , .message = " File size must be positive" });
2526 }
2627 if (file_size > static_cast <std::int64_t >(config_.max_upload_size_bytes )) {
27- return std::unexpected (common::Error{common::ErrorCode::kQuotaExceeded , " File exceeds maximum upload size" });
28+ return std::unexpected (
29+ common::Error{.code = common::ErrorCode::kQuotaExceeded , .message = " File exceeds maximum upload size" });
2830 }
2931
3032 auto used = attachments_.GetStorageUsedByUser (user_id);
3133 if (used + file_size > static_cast <std::int64_t >(config_.max_storage_per_user_bytes )) {
32- return std::unexpected (common::Error{common::ErrorCode::kQuotaExceeded , " User storage quota exceeded" });
34+ return std::unexpected (
35+ common::Error{.code = common::ErrorCode::kQuotaExceeded , .message = " User storage quota exceeded" });
3336 }
3437
3538 bool is_member = conversations_.IsUserInConversation (conversation_id, user_id);
3639 if (!is_member) {
37- return std::unexpected (common::Error{common::ErrorCode::kForbidden , " User is not a member of this conversation" });
40+ return std::unexpected (
41+ common::Error{.code = common::ErrorCode::kForbidden , .message = " User is not a member of this conversation" });
3842 }
3943
4044 auto now = Now ();
@@ -58,31 +62,32 @@ common::Result<InitUploadResponse> AttachmentService::InitUpload(const common::U
5862 return std::unexpected (result.error ());
5963 }
6064
61- return InitUploadResponse{attachment_id, blob_path.string ()};
65+ return InitUploadResponse{. attachment_id = attachment_id, . blob_path = blob_path.string ()};
6266}
6367
6468common::VoidResult AttachmentService::WriteChunk (const common::AttachmentId& attachment_id,
6569 std::int64_t offset,
6670 const std::string& data) {
6771 auto meta = attachments_.GetAttachmentMeta (attachment_id);
6872 if (!meta) {
69- return std::unexpected (common::Error{common::ErrorCode::kNotFound , " Attachment not found" });
73+ return std::unexpected (common::Error{. code = common::ErrorCode::kNotFound , . message = " Attachment not found" });
7074 }
7175 if (meta->upload_complete ) {
72- return std::unexpected (common::Error{common::ErrorCode::kInvalidArgument , " Upload already complete" });
76+ return std::unexpected (
77+ common::Error{.code = common::ErrorCode::kInvalidArgument , .message = " Upload already complete" });
7378 }
7479
7580 std::ofstream file (meta->blob_path , std::ios::binary | std::ios::in | std::ios::out);
7681 if (!file.is_open ()) {
7782 file.open (meta->blob_path , std::ios::binary | std::ios::out);
7883 }
7984 if (!file.is_open ()) {
80- return std::unexpected (common::Error{common::ErrorCode::kInternal , " Cannot open blob file" });
85+ return std::unexpected (common::Error{. code = common::ErrorCode::kInternal , . message = " Cannot open blob file" });
8186 }
8287 file.seekp (offset);
8388 file.write (data.data (), static_cast <std::streamsize>(data.size ()));
8489 if (!file.good ()) {
85- return std::unexpected (common::Error{common::ErrorCode::kInternal , " Failed to write chunk" });
90+ return std::unexpected (common::Error{. code = common::ErrorCode::kInternal , . message = " Failed to write chunk" });
8691 }
8792 return {};
8893}
@@ -91,14 +96,16 @@ common::VoidResult AttachmentService::FinalizeUpload(const common::AttachmentId&
9196 const std::string& ciphertext_hash) {
9297 auto meta = attachments_.GetAttachmentMeta (attachment_id);
9398 if (!meta) {
94- return std::unexpected (common::Error{common::ErrorCode::kNotFound , " Attachment not found" });
99+ return std::unexpected (common::Error{. code = common::ErrorCode::kNotFound , . message = " Attachment not found" });
95100 }
96101 if (meta->upload_complete ) {
97- return std::unexpected (common::Error{common::ErrorCode::kInvalidArgument , " Upload already finalized" });
102+ return std::unexpected (
103+ common::Error{.code = common::ErrorCode::kInvalidArgument , .message = " Upload already finalized" });
98104 }
99105
100106 if (!std::filesystem::exists (meta->blob_path )) {
101- return std::unexpected (common::Error{common::ErrorCode::kInternal , " Blob file not found on disk" });
107+ return std::unexpected (
108+ common::Error{.code = common::ErrorCode::kInternal , .message = " Blob file not found on disk" });
102109 }
103110
104111 return attachments_.MarkUploadComplete (attachment_id, ciphertext_hash);
@@ -108,15 +115,17 @@ common::Result<std::filesystem::path> AttachmentService::GetAttachment(const com
108115 const common::UserId& user_id) {
109116 auto meta = attachments_.GetAttachmentMeta (attachment_id);
110117 if (!meta) {
111- return std::unexpected (common::Error{common::ErrorCode::kNotFound , " Attachment not found" });
118+ return std::unexpected (common::Error{. code = common::ErrorCode::kNotFound , . message = " Attachment not found" });
112119 }
113120 if (!meta->upload_complete ) {
114- return std::unexpected (common::Error{common::ErrorCode::kNotFound , " Attachment upload not complete" });
121+ return std::unexpected (
122+ common::Error{.code = common::ErrorCode::kNotFound , .message = " Attachment upload not complete" });
115123 }
116124
117125 bool is_member = conversations_.IsUserInConversation (meta->conversation_id , user_id);
118126 if (!is_member) {
119- return std::unexpected (common::Error{common::ErrorCode::kForbidden , " Not authorized to access this attachment" });
127+ return std::unexpected (
128+ common::Error{.code = common::ErrorCode::kForbidden , .message = " Not authorized to access this attachment" });
120129 }
121130
122131 return std::filesystem::path (meta->blob_path );
0 commit comments