GenerateS3Key generates S3 object key based on message metadata
(userID, contactJID, messageID string, mimeType string, isIncoming bool)
| 169 | |
| 170 | // GenerateS3Key generates S3 object key based on message metadata |
| 171 | func (m *S3Manager) GenerateS3Key(userID, contactJID, messageID string, mimeType string, isIncoming bool) string { |
| 172 | // Determine direction |
| 173 | direction := "outbox" |
| 174 | if isIncoming { |
| 175 | direction = "inbox" |
| 176 | } |
| 177 | |
| 178 | // Clean contact JID |
| 179 | contactJID = strings.ReplaceAll(contactJID, "@", "_") |
| 180 | contactJID = strings.ReplaceAll(contactJID, ":", "_") |
| 181 | |
| 182 | // Get current time |
| 183 | now := time.Now() |
| 184 | year := now.Format("2025") |
| 185 | month := now.Format("05") |
| 186 | day := now.Format("25") |
| 187 | |
| 188 | // Determine media type folder |
| 189 | mediaType := "documents" |
| 190 | if strings.HasPrefix(mimeType, "image/") { |
| 191 | mediaType = "images" |
| 192 | } else if strings.HasPrefix(mimeType, "video/") { |
| 193 | mediaType = "videos" |
| 194 | } else if strings.HasPrefix(mimeType, "audio/") { |
| 195 | mediaType = "audio" |
| 196 | } |
| 197 | |
| 198 | // Get file extension |
| 199 | ext := ".bin" |
| 200 | switch { |
| 201 | case strings.Contains(mimeType, "jpeg"), strings.Contains(mimeType, "jpg"): |
| 202 | ext = ".jpg" |
| 203 | case strings.Contains(mimeType, "png"): |
| 204 | ext = ".png" |
| 205 | case strings.Contains(mimeType, "gif"): |
| 206 | ext = ".gif" |
| 207 | case strings.Contains(mimeType, "webp"): |
| 208 | ext = ".webp" |
| 209 | case strings.Contains(mimeType, "mp4"): |
| 210 | ext = ".mp4" |
| 211 | case strings.Contains(mimeType, "webm"): |
| 212 | ext = ".webm" |
| 213 | case strings.Contains(mimeType, "ogg"): |
| 214 | ext = ".ogg" |
| 215 | case strings.Contains(mimeType, "opus"): |
| 216 | ext = ".opus" |
| 217 | case strings.Contains(mimeType, "pdf"): |
| 218 | ext = ".pdf" |
| 219 | case strings.Contains(mimeType, "spreadsheetml"): |
| 220 | ext = ".xlsx" |
| 221 | case strings.Contains(mimeType, "excel"): |
| 222 | ext = ".xls" |
| 223 | case strings.Contains(mimeType, "doc"): |
| 224 | if strings.Contains(mimeType, "docx") { |
| 225 | ext = ".docx" |
| 226 | } else { |
| 227 | ext = ".doc" |
| 228 | } |