Fix group file metadata and access
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
@@ -67,6 +68,9 @@ func enqueueKafkaFileAttachmentsBind(ctx context.Context, tenantID types.TenantI
|
||||
SeqID: msg.SeqId,
|
||||
UserID: types.ParseUid(msg.From).UserId(),
|
||||
FileType: lifecycleFileTypeFromMessageHead(msg.Head),
|
||||
FileName: lifecycleContentString(msg.Content, "name", "file_name"),
|
||||
MIMEType: lifecycleContentString(msg.Content, "mime", "mime_type"),
|
||||
FileSize: lifecycleContentInt64(msg.Content, "size", "file_size"),
|
||||
OccurredAt: msg.CreatedAt,
|
||||
}
|
||||
return enqueueKafkaFileLifecycle(ctx, tenantID, kafkaFileLifecycleAttachmentsBind, fmt.Sprintf("%s:%d", msg.Topic, msg.SeqId), payload)
|
||||
@@ -141,7 +145,10 @@ func executeKafkaFileAttachmentsBind(tenantID types.TenantID, payload kafkaFileL
|
||||
SourceTopic: payload.Topic,
|
||||
SourceSeq: payload.SeqID,
|
||||
UploaderID: uploader,
|
||||
FileName: payload.FileName,
|
||||
MIMEType: payload.MIMEType,
|
||||
FileType: lifecycleFileType(payload.FileType),
|
||||
FileSize: payload.FileSize,
|
||||
IdempotencyKey: fmt.Sprintf("%s:%d:%s", payload.Topic, payload.SeqID, fid.String()),
|
||||
})
|
||||
if err != nil && !errors.Is(err, types.ErrDuplicate) {
|
||||
@@ -183,6 +190,58 @@ func lifecycleHeaderString(head types.KVMap, key string) string {
|
||||
return strings.TrimSpace(str)
|
||||
}
|
||||
|
||||
func lifecycleContentString(content any, keys ...string) string {
|
||||
values, ok := lifecycleContentMap(content)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
for _, key := range keys {
|
||||
if value, ok := values[key]; ok {
|
||||
if str, ok := value.(string); ok {
|
||||
if str = strings.TrimSpace(str); str != "" {
|
||||
return str
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func lifecycleContentInt64(content any, keys ...string) int64 {
|
||||
values, ok := lifecycleContentMap(content)
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
for _, key := range keys {
|
||||
if value, ok := values[key]; ok {
|
||||
switch typed := value.(type) {
|
||||
case int:
|
||||
return int64(typed)
|
||||
case int64:
|
||||
return typed
|
||||
case float64:
|
||||
return int64(typed)
|
||||
case json.Number:
|
||||
if parsed, err := typed.Int64(); err == nil {
|
||||
return parsed
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func lifecycleContentMap(content any) (map[string]any, bool) {
|
||||
switch typed := content.(type) {
|
||||
case map[string]any:
|
||||
return typed, true
|
||||
case types.KVMap:
|
||||
return map[string]any(typed), true
|
||||
default:
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
|
||||
func lifecycleCanonicalMessageType(raw string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(raw)) {
|
||||
case "audio":
|
||||
|
||||
Reference in New Issue
Block a user