fix(weknora): 同内容重复上传改为认领而非死信
This commit is contained in:
@@ -171,6 +171,7 @@ func (handler *UploadHandler) Handle(ctx context.Context, job jobs.Job) error {
|
||||
func (handler *UploadHandler) recoverAmbiguousUpload(ctx context.Context, candidate postgresstore.PublicationForUpload) (weknora.Knowledge, error) {
|
||||
const pageSize = 100
|
||||
matches := make([]weknora.Knowledge, 0, 2)
|
||||
sameContent := make([]weknora.Knowledge, 0, 2)
|
||||
for page := 1; page <= 100; page++ {
|
||||
items, total, err := handler.client.ListKnowledge(ctx, candidate.TestKBID, page, pageSize)
|
||||
if err != nil {
|
||||
@@ -179,11 +180,20 @@ func (handler *UploadHandler) recoverAmbiguousUpload(ctx context.Context, candid
|
||||
for _, item := range items {
|
||||
publicationID, publicationOK := metadataString(item.Metadata, "publication_id")
|
||||
contentSHA, contentOK := metadataString(item.Metadata, "content_sha256")
|
||||
if item.KnowledgeBaseID == candidate.TestKBID && publicationOK && contentOK && publicationID == candidate.ID && contentSHA == candidate.SHA256 {
|
||||
if item.KnowledgeBaseID != candidate.TestKBID || !contentOK || contentSHA != candidate.SHA256 {
|
||||
continue
|
||||
}
|
||||
if publicationOK && publicationID == candidate.ID {
|
||||
matches = append(matches, item)
|
||||
if len(matches) > 1 {
|
||||
return weknora.Knowledge{}, ErrUploadRemoteIdentity
|
||||
}
|
||||
} else {
|
||||
// Same bytes already delivered under a SIBLING publication (the
|
||||
// same file exists in two source folders). A unique match here is
|
||||
// safe to adopt: WeKnora dedupes by content and would reject our
|
||||
// own upload forever otherwise.
|
||||
sameContent = append(sameContent, item)
|
||||
}
|
||||
}
|
||||
if int64(page*pageSize) >= total {
|
||||
@@ -193,6 +203,9 @@ func (handler *UploadHandler) recoverAmbiguousUpload(ctx context.Context, candid
|
||||
return weknora.Knowledge{}, ErrUploadRemoteFailed
|
||||
}
|
||||
}
|
||||
if len(matches) == 0 && len(sameContent) == 1 {
|
||||
matches = sameContent
|
||||
}
|
||||
if len(matches) != 1 {
|
||||
return weknora.Knowledge{}, ErrUploadRemoteFailed
|
||||
}
|
||||
@@ -202,8 +215,12 @@ func (handler *UploadHandler) recoverAmbiguousUpload(ctx context.Context, candid
|
||||
}
|
||||
publicationID, publicationOK := metadataString(verified.Metadata, "publication_id")
|
||||
contentSHA, contentOK := metadataString(verified.Metadata, "content_sha256")
|
||||
// The identity anchor is the content hash: it matches either our own
|
||||
// recovery (same publication_id) or a sibling's adoption (duplicate file
|
||||
// across folders). publication_id is checked only when it is ours.
|
||||
if verified.ID != matches[0].ID || verified.KnowledgeBaseID != candidate.TestKBID ||
|
||||
!publicationOK || !contentOK || publicationID != candidate.ID || contentSHA != candidate.SHA256 {
|
||||
!contentOK || contentSHA != candidate.SHA256 ||
|
||||
(publicationOK && publicationID != candidate.ID && len(sameContent) > 1) {
|
||||
return weknora.Knowledge{}, ErrUploadRemoteIdentity
|
||||
}
|
||||
return verified, nil
|
||||
|
||||
Reference in New Issue
Block a user