diff --git a/internal/store/meeting_note_file_test.go b/internal/store/meeting_note_file_test.go index 53ffc9b..29e03ff 100644 --- a/internal/store/meeting_note_file_test.go +++ b/internal/store/meeting_note_file_test.go @@ -3,16 +3,34 @@ package store import "testing" func TestNormalizeMeetingNoteFileMetadataUsesUploadMetadata(t *testing.T) { + gotName, gotMime, gotSize, gotETag := normalizeMeetingNoteFileMetadata(MeetingNoteFileInput{ + FileID: "lxzvtUzicEo", + }, fileUploadMetadata{ + MIMEType: "application/pdf", + FileSize: 12345, + FileETag: "etag-1", + Location: "uploads/wontuse", + OriginalName: "会议纪要.pdf", + }, "lxzvtUzicEo") + if gotName != "会议纪要.pdf" { + t.Fatalf("name=%q, want original upload name", gotName) + } + if gotMime != "application/pdf" || gotSize != 12345 || gotETag != "etag-1" { + t.Fatalf("metadata mime=%q size=%d etag=%q", gotMime, gotSize, gotETag) + } +} + +func TestNormalizeMeetingNoteFileMetadataFallsBackToLocation(t *testing.T) { gotName, gotMime, gotSize, gotETag := normalizeMeetingNoteFileMetadata(MeetingNoteFileInput{ FileID: "lxzvtUzicEo", }, fileUploadMetadata{ MIMEType: "application/pdf", FileSize: 12345, FileETag: "etag-1", - Location: "uploads/wontuse", + Location: "uploads/lxzvtUzicEo.pdf", }, "lxzvtUzicEo") if gotName != "lxzvtUzicEo.pdf" { - t.Fatalf("name=%q, want lxzvtUzicEo.pdf", gotName) + t.Fatalf("name=%q, want location file name", gotName) } if gotMime != "application/pdf" || gotSize != 12345 || gotETag != "etag-1" { t.Fatalf("metadata mime=%q size=%d etag=%q", gotMime, gotSize, gotETag) diff --git a/internal/store/mysql.go b/internal/store/mysql.go index ea3aa48..914a62e 100644 --- a/internal/store/mysql.go +++ b/internal/store/mysql.go @@ -597,6 +597,9 @@ func (s *Store) CreateMeetingNoteFile(ctx context.Context, userID int64, meeting FROM im_meeting_note_files WHERE tenant_id=? AND meeting_id=? AND uploader_id=? AND idempotency_key=? LIMIT 1`, s.tenant(), meetingID, userID, idempotencyKey); getErr != nil { return nil, getErr } + if getErr := s.hydrateMeetingNoteFileUploader(ctx, &existing); getErr != nil { + return nil, getErr + } return &existing, nil } if err != nil { @@ -607,6 +610,9 @@ func (s *Store) CreateMeetingNoteFile(ctx context.Context, userID int64, meeting FROM im_meeting_note_files WHERE tenant_id=? AND note_file_id=? LIMIT 1`, s.tenant(), noteFileID); err != nil { return nil, err } + if err := s.hydrateMeetingNoteFileUploader(ctx, &created); err != nil { + return nil, err + } return &created, nil } @@ -634,10 +640,11 @@ func (s *Store) ReplaceMeetingNoteFile(ctx context.Context, userID int64, meetin } type fileUploadMetadata struct { - MIMEType string `db:"mimetype"` - FileSize int64 `db:"size"` - FileETag string `db:"etag"` - Location string `db:"location"` + MIMEType string `db:"mimetype"` + FileSize int64 `db:"size"` + FileETag string `db:"etag"` + Location string `db:"location"` + OriginalName string `db:"original_name"` } func (s *Store) fileUploadMetadata(ctx context.Context, fileID string) fileUploadMetadata { @@ -648,13 +655,13 @@ func (s *Store) fileUploadMetadata(ctx context.Context, fileID string) fileUploa return meta } if decodedID > 0 { - err := s.db.GetContext(ctx, &meta, `SELECT IFNULL(mimetype,'') AS mimetype,IFNULL(size,0) AS size,IFNULL(etag,'') AS etag,IFNULL(location,'') AS location FROM im_fileuploads WHERE tenant_id=? AND id=? LIMIT 1`, s.tenant(), decodedID) + err := s.db.GetContext(ctx, &meta, `SELECT IFNULL(mimetype,'') AS mimetype,IFNULL(size,0) AS size,IFNULL(etag,'') AS etag,IFNULL(location,'') AS location,IFNULL(original_name,'') AS original_name FROM im_fileuploads WHERE tenant_id=? AND id=? LIMIT 1`, s.tenant(), decodedID) if err == nil { return meta } } for _, candidate := range locationCandidates { - err := s.db.GetContext(ctx, &meta, `SELECT IFNULL(mimetype,'') AS mimetype,IFNULL(size,0) AS size,IFNULL(etag,'') AS etag,IFNULL(location,'') AS location + err := s.db.GetContext(ctx, &meta, `SELECT IFNULL(mimetype,'') AS mimetype,IFNULL(size,0) AS size,IFNULL(etag,'') AS etag,IFNULL(location,'') AS location,IFNULL(original_name,'') AS original_name FROM im_fileuploads WHERE tenant_id=? AND (location=? OR location LIKE ?) ORDER BY createdat DESC LIMIT 1`, s.tenant(), candidate, "%/"+candidate) if err == nil { return meta @@ -752,7 +759,7 @@ func normalizeMeetingNoteFileMetadata(input MeetingNoteFileInput, meta fileUploa fileSize = meta.FileSize } fileETag := firstNonEmpty(input.FileETag, meta.FileETag) - fileName := normalizeMeetingNoteFileName(firstNonEmpty(input.FileName, fileNameFromLocation(meta.Location), fallbackFileName(fileID, mimeType)), fileID) + fileName := normalizeMeetingNoteFileName(firstNonEmpty(input.FileName, meta.OriginalName, fileNameFromLocation(meta.Location), fallbackFileName(fileID, mimeType)), fileID) return fileName, strings.TrimSpace(mimeType), fileSize, strings.TrimSpace(fileETag) }