fix: retain cultivate feed media references
This commit is contained in:
@@ -23,8 +23,9 @@ type cultivateRelationsRequest struct {
|
||||
}
|
||||
|
||||
type cultivateFilesRequest struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
FileIDs []string `json:"file_ids"`
|
||||
UserID int64 `json:"user_id"`
|
||||
ReferenceID int64 `json:"reference_id"`
|
||||
FileIDs []string `json:"file_ids"`
|
||||
}
|
||||
|
||||
type cultivateReviewRequest struct {
|
||||
@@ -162,6 +163,7 @@ func serveCultivateFiles(w http.ResponseWriter, r *http.Request, tenantID types.
|
||||
}
|
||||
uid := store.EncodeUid(body.UserID)
|
||||
items := make([]map[string]any, 0, len(body.FileIDs))
|
||||
fileIDs := make([]string, 0, len(body.FileIDs))
|
||||
for _, supplied := range body.FileIDs {
|
||||
fileID := normalizeIMUploadedFileID(supplied)
|
||||
file, err := store.Files.Get(tenantID, fileID)
|
||||
@@ -173,11 +175,24 @@ func serveCultivateFiles(w http.ResponseWriter, r *http.Request, tenantID types.
|
||||
writeIMError(w, r, http.StatusUnprocessableEntity, 30000, imReasonMalformedRequest, "invalid file", map[string]any{"file_id": supplied})
|
||||
return
|
||||
}
|
||||
fileIDs = append(fileIDs, fileID)
|
||||
items = append(items, map[string]any{"file_id": fileID, "mime_type": file.MimeType, "size": file.Size, "review_status": cultivateFileReviewStatus(tenantID, fileID)})
|
||||
}
|
||||
if body.ReferenceID > 0 {
|
||||
for index, fileID := range fileIDs {
|
||||
if err := store.Files.LinkAttachments(tenantID, cultivateFileReferenceTopic(body.ReferenceID, index), types.ZeroUid, []string{fileID}); err != nil {
|
||||
writeIMError(w, r, http.StatusInternalServerError, 90000, imReasonInternal, "failed to retain file", nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
writeIMSuccess(w, r, map[string]any{"items": items})
|
||||
}
|
||||
|
||||
func cultivateFileReferenceTopic(referenceID int64, index int) string {
|
||||
return "cvp" + strconv.FormatInt(referenceID, 36) + "x" + strconv.FormatInt(int64(index), 36)
|
||||
}
|
||||
|
||||
func fileOwner(file *types.FileDef) string {
|
||||
if file == nil {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user