H-28: harden Shangwutong CID sync (#5)
* fix(shangwutong): close contact sync review gaps * fix(shangwutong): harden CID sync boundaries --------- Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
@@ -37,7 +37,12 @@ func (h *ShangwutongConnectorHandler) UpdateContactMetadata(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
var request shangwutongContactMetadataRequest
|
||||
if err := c.ShouldBindJSON(&request); err != nil || strings.TrimSpace(request.CID) == "" {
|
||||
if err := c.ShouldBindJSON(&request); err != nil {
|
||||
h.connectorError(c, http.StatusUnprocessableEntity, "invalid_contact_metadata", "cid is required", false)
|
||||
return
|
||||
}
|
||||
request.CID = strings.TrimSpace(request.CID)
|
||||
if request.CID == "" || len(request.CID) > 255 {
|
||||
h.connectorError(c, http.StatusUnprocessableEntity, "invalid_contact_metadata", "cid is required", false)
|
||||
return
|
||||
}
|
||||
@@ -48,13 +53,16 @@ func (h *ShangwutongConnectorHandler) UpdateContactMetadata(c *gin.Context) {
|
||||
}
|
||||
metadata := map[string]any{}
|
||||
if len(contactInbox.ChannelMetadata) > 0 {
|
||||
_ = json.Unmarshal(contactInbox.ChannelMetadata, &metadata)
|
||||
if err := json.Unmarshal(contactInbox.ChannelMetadata, &metadata); err != nil {
|
||||
h.connectorError(c, http.StatusInternalServerError, "contact_metadata_invalid", "stored contact metadata is invalid", true)
|
||||
return
|
||||
}
|
||||
}
|
||||
if metadata["cid"] == strings.TrimSpace(request.CID) {
|
||||
if metadata["cid"] == request.CID {
|
||||
c.JSON(http.StatusOK, gin.H{"updated": false})
|
||||
return
|
||||
}
|
||||
metadata["cid"] = strings.TrimSpace(request.CID)
|
||||
metadata["cid"] = request.CID
|
||||
encoded, err := json.Marshal(metadata)
|
||||
if err != nil {
|
||||
h.connectorError(c, http.StatusInternalServerError, "contact_metadata_update_failed", "failed to encode contact metadata", true)
|
||||
|
||||
Reference in New Issue
Block a user