fix: preserve meeting note file metadata
This commit is contained in:
@@ -3,16 +3,34 @@ package store
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestNormalizeMeetingNoteFileMetadataUsesUploadMetadata(t *testing.T) {
|
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{
|
gotName, gotMime, gotSize, gotETag := normalizeMeetingNoteFileMetadata(MeetingNoteFileInput{
|
||||||
FileID: "lxzvtUzicEo",
|
FileID: "lxzvtUzicEo",
|
||||||
}, fileUploadMetadata{
|
}, fileUploadMetadata{
|
||||||
MIMEType: "application/pdf",
|
MIMEType: "application/pdf",
|
||||||
FileSize: 12345,
|
FileSize: 12345,
|
||||||
FileETag: "etag-1",
|
FileETag: "etag-1",
|
||||||
Location: "uploads/wontuse",
|
Location: "uploads/lxzvtUzicEo.pdf",
|
||||||
}, "lxzvtUzicEo")
|
}, "lxzvtUzicEo")
|
||||||
if gotName != "lxzvtUzicEo.pdf" {
|
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" {
|
if gotMime != "application/pdf" || gotSize != 12345 || gotETag != "etag-1" {
|
||||||
t.Fatalf("metadata mime=%q size=%d etag=%q", gotMime, gotSize, gotETag)
|
t.Fatalf("metadata mime=%q size=%d etag=%q", gotMime, gotSize, gotETag)
|
||||||
|
|||||||
+14
-7
@@ -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 {
|
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
|
return nil, getErr
|
||||||
}
|
}
|
||||||
|
if getErr := s.hydrateMeetingNoteFileUploader(ctx, &existing); getErr != nil {
|
||||||
|
return nil, getErr
|
||||||
|
}
|
||||||
return &existing, nil
|
return &existing, nil
|
||||||
}
|
}
|
||||||
if err != 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 {
|
FROM im_meeting_note_files WHERE tenant_id=? AND note_file_id=? LIMIT 1`, s.tenant(), noteFileID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if err := s.hydrateMeetingNoteFileUploader(ctx, &created); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &created, nil
|
return &created, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -634,10 +640,11 @@ func (s *Store) ReplaceMeetingNoteFile(ctx context.Context, userID int64, meetin
|
|||||||
}
|
}
|
||||||
|
|
||||||
type fileUploadMetadata struct {
|
type fileUploadMetadata struct {
|
||||||
MIMEType string `db:"mimetype"`
|
MIMEType string `db:"mimetype"`
|
||||||
FileSize int64 `db:"size"`
|
FileSize int64 `db:"size"`
|
||||||
FileETag string `db:"etag"`
|
FileETag string `db:"etag"`
|
||||||
Location string `db:"location"`
|
Location string `db:"location"`
|
||||||
|
OriginalName string `db:"original_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) fileUploadMetadata(ctx context.Context, fileID string) fileUploadMetadata {
|
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
|
return meta
|
||||||
}
|
}
|
||||||
if decodedID > 0 {
|
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 {
|
if err == nil {
|
||||||
return meta
|
return meta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, candidate := range locationCandidates {
|
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)
|
FROM im_fileuploads WHERE tenant_id=? AND (location=? OR location LIKE ?) ORDER BY createdat DESC LIMIT 1`, s.tenant(), candidate, "%/"+candidate)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return meta
|
return meta
|
||||||
@@ -752,7 +759,7 @@ func normalizeMeetingNoteFileMetadata(input MeetingNoteFileInput, meta fileUploa
|
|||||||
fileSize = meta.FileSize
|
fileSize = meta.FileSize
|
||||||
}
|
}
|
||||||
fileETag := firstNonEmpty(input.FileETag, meta.FileETag)
|
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)
|
return fileName, strings.TrimSpace(mimeType), fileSize, strings.TrimSpace(fileETag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user