fix: preserve meeting note file metadata

This commit is contained in:
richjohnrambo
2026-09-17 20:40:48 +08:00
parent 9cfeb5f2c7
commit fe7d4ccb3e
6 changed files with 138 additions and 11 deletions
+49 -6
View File
@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"path/filepath"
"strings"
"sync"
"time"
@@ -592,7 +593,7 @@ func (s *Store) MeetingNoteFiles(ctx context.Context, userID int64, meetingID st
return files, nil
}
func (s *Store) CreateMeetingNoteFile(ctx context.Context, userID int64, meetingID, noteFileID, fileID, idempotencyKey string) (*MeetingNoteFile, error) {
func (s *Store) CreateMeetingNoteFile(ctx context.Context, userID int64, meetingID, noteFileID string, input MeetingNoteFileInput, idempotencyKey string) (*MeetingNoteFile, error) {
meeting, err := s.Meeting(ctx, userID, meetingID)
if err != nil {
return nil, err
@@ -601,8 +602,20 @@ func (s *Store) CreateMeetingNoteFile(ctx context.Context, userID int64, meeting
return nil, ErrForbidden
}
now := time.Now().UTC().Round(time.Millisecond)
fileName, mimeType, fileSize, fileETag := fileID, "", int64(0), ""
_ = s.db.QueryRowxContext(ctx, `SELECT IFNULL(mimetype,''),IFNULL(size,0),IFNULL(etag,'') FROM im_fileuploads WHERE id=? LIMIT 1`, fileID).Scan(&mimeType, &fileSize, &fileETag)
fileID := strings.TrimSpace(input.FileID)
fileName, mimeType, fileSize, fileETag := normalizeMeetingNoteFileName(input.FileName, fileID), strings.TrimSpace(input.MIMEType), int64(0), ""
if input.FileSize != nil && *input.FileSize > 0 {
fileSize = *input.FileSize
}
var uploadMime string
var uploadSize int64
_ = s.db.QueryRowxContext(ctx, `SELECT IFNULL(mimetype,''),IFNULL(size,0),IFNULL(etag,'') FROM im_fileuploads WHERE id=? LIMIT 1`, fileID).Scan(&uploadMime, &uploadSize, &fileETag)
if mimeType == "" {
mimeType = uploadMime
}
if fileSize <= 0 {
fileSize = uploadSize
}
_, err = s.db.ExecContext(ctx, `INSERT INTO im_meeting_note_files(note_file_id,meeting_id,file_id,uploader_id,file_name,mime_type,file_size,file_etag,status,preview_status,preview_mode,preview_file_id,version,idempotency_key,created_at,updated_at)
VALUES(?,?,?,?,?,?,?,?,'active','processing','native','',1,?,?,?)`, noteFileID, meetingID, fileID, userID, fileName, mimeType, fileSize, fileETag, idempotencyKey, now, now)
if isDuplicate(err) && idempotencyKey != "" {
@@ -624,7 +637,7 @@ func (s *Store) CreateMeetingNoteFile(ctx context.Context, userID int64, meeting
return &created, nil
}
func (s *Store) ReplaceMeetingNoteFile(ctx context.Context, userID int64, meetingID, noteFileID, fileID, idempotencyKey string, version int) (*MeetingNoteFile, error) {
func (s *Store) ReplaceMeetingNoteFile(ctx context.Context, userID int64, meetingID, noteFileID string, input MeetingNoteFileInput, idempotencyKey string, version int) (*MeetingNoteFile, error) {
meeting, err := s.Meeting(ctx, userID, meetingID)
if err != nil {
return nil, err
@@ -632,8 +645,20 @@ func (s *Store) ReplaceMeetingNoteFile(ctx context.Context, userID int64, meetin
if meeting.RecorderID != userID && meeting.OrganizerID != userID {
return nil, ErrForbidden
}
fileName, mimeType, fileSize, fileETag := fileID, "", int64(0), ""
_ = s.db.QueryRowxContext(ctx, `SELECT IFNULL(mimetype,''),IFNULL(size,0),IFNULL(etag,'') FROM im_fileuploads WHERE id=? LIMIT 1`, fileID).Scan(&mimeType, &fileSize, &fileETag)
fileID := strings.TrimSpace(input.FileID)
fileName, mimeType, fileSize, fileETag := normalizeMeetingNoteFileName(input.FileName, fileID), strings.TrimSpace(input.MIMEType), int64(0), ""
if input.FileSize != nil && *input.FileSize > 0 {
fileSize = *input.FileSize
}
var uploadMime string
var uploadSize int64
_ = s.db.QueryRowxContext(ctx, `SELECT IFNULL(mimetype,''),IFNULL(size,0),IFNULL(etag,'') FROM im_fileuploads WHERE id=? LIMIT 1`, fileID).Scan(&uploadMime, &uploadSize, &fileETag)
if mimeType == "" {
mimeType = uploadMime
}
if fileSize <= 0 {
fileSize = uploadSize
}
res, err := s.db.ExecContext(ctx, `UPDATE im_meeting_note_files SET file_id=?,file_name=?,mime_type=?,file_size=?,file_etag=?,preview_status='processing',preview_file_id='',version=version+1,idempotency_key=?,updated_at=?
WHERE meeting_id=? AND note_file_id=? AND status='active' AND version=?`,
fileID, fileName, mimeType, fileSize, fileETag, idempotencyKey, time.Now().UTC().Round(time.Millisecond), meetingID, noteFileID, version)
@@ -646,6 +671,24 @@ func (s *Store) ReplaceMeetingNoteFile(ctx context.Context, userID int64, meetin
return s.meetingNoteFile(ctx, meetingID, noteFileID)
}
func normalizeMeetingNoteFileName(fileName, fileID string) string {
fileName = strings.TrimSpace(strings.ReplaceAll(fileName, "\\", "/"))
fileName = filepath.Base(fileName)
if fileName == "." || fileName == "/" || fileName == "" {
fileName = strings.TrimSpace(fileID)
}
if len([]rune(fileName)) <= 255 {
return fileName
}
runes := []rune(fileName)
ext := filepath.Ext(fileName)
if ext == "" || len([]rune(ext)) >= 255 {
return string(runes[:255])
}
extRunes := []rune(ext)
return string(runes[:255-len(extRunes)]) + ext
}
func (s *Store) DeleteMeetingNoteFile(ctx context.Context, userID int64, meetingID, noteFileID, idempotencyKey string, version int) (*MeetingNoteFile, error) {
meeting, err := s.Meeting(ctx, userID, meetingID)
if err != nil {