修复:集成聊天图片预览与真实尺寸发送

This commit is contained in:
Christ committed 2026-08-18 15:08:37 +08:00
1 parent 9eb6be2875
commit ee228381cf
36 files changed
+331 -83

No files matched your search

+14
View File
@@ -266,5 +266,19 @@ func TestChatImageUploaderRejectsUnsupportedAndEmptyPlatformResults(t *testing.T
}
}
// TestChatImageUploaderPreservesPlatformDimensions 验证图片尺寸从 MTOP 结果映射到应用端口且不被丢弃。
func TestChatImageUploaderPreservesPlatformDimensions(t *testing.T) {
// store、cleanup 保存包含测试账号凭证的临时数据库及清理函数。
store, cleanup := newAdapterTestStore(t)
defer cleanup()
// client 返回带真实像素尺寸的平台上传结果。
client := fakeChatUploadClient{upload: &mtop.ChatImageUpload{URL: "https://cdn.example/image.jpg", Width: 1920, Height: 1080}}
// upload 保存应用适配器转换后的非敏感图片结果。
upload, err := NewChatImageUploader(store, func() mtop.Client { return client }, nil).UploadChatImage(context.Background(), "cid", "a.jpg", "image/jpeg", []byte("image"))
if err != nil || upload.URL == "" || upload.Width != 1920 || upload.Height != 1080 {
t.Fatalf("upload=%+v err=%v", upload, err)
}
}
var _ chatapp.SessionRepository = chatRepository{}
var _ chatapp.IdentityResolver = chatIdentityResolver{}
+3 -3
View File
@@ -132,11 +132,11 @@ func (s chatSender) SendText(ctx context.Context, chatID, toUserID, text, messag
}
// SendImage 发送图片并将应用层幂等键传递给运行时接口。
func (s chatSender) SendImage(ctx context.Context, chatID, toUserID, imageURL string, cardID int64, messageKey string) error {
func (s chatSender) SendImage(ctx context.Context, chatID, toUserID, imageURL string, cardID int64, width, height int, messageKey string) error {
if s.sender == nil {
return chatapp.ErrUnavailable
}
return s.sender.SendImage(engine.WithOutgoingMessageKey(ctx, messageKey), chatID, toUserID, imageURL, cardID)
return s.sender.SendImage(engine.WithOutgoingMessageKey(ctx, messageKey), chatID, toUserID, imageURL, cardID, width, height)
}
// chatCredentialRepository 将 Cookie 读取与写回限制在平台适配器内。
@@ -216,7 +216,7 @@ func (u chatImageUploader) UploadChatImage(ctx context.Context, accountID, filen
}
}
}
return chatapp.ImageUpload{URL: upload.URL}, nil
return chatapp.ImageUpload{URL: upload.URL, Width: upload.Width, Height: upload.Height}, nil
}
// 编译期确认聊天实时适配器覆盖应用层定义的全部能力。