Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/utopia-server/src/api/sources_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ pub async fn sync_now(

#[derive(Deserialize)]
pub struct IngestBody {
/// 墓碑带着 external_id 时用不上文件名(身份是 external_id),缺了也收;
/// 其余情况仍然必填,空串在下面的校验里挡
#[serde(default)]
pub filename: String,
/// 墓碑推送(`deleted: true`)可以不带 content——指南一直这么写,而字段
/// 从前是必填,缺了就在反序列化那一步被拒。其余情况仍然必填:空串在
Expand Down
36 changes: 36 additions & 0 deletions crates/utopia-server/src/api/sources_statements_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,42 @@ async fn a_tombstone_marks_the_item_missing_and_a_new_push_revives_it() -> anyho
f.cleanup().await
}

/// api 来源的墓碑按 external_id 认身份,不用再带文件名;正常推送缺文件名照旧不收
#[tokio::test]
async fn an_api_tombstone_needs_only_its_external_id() -> anyhow::Result<()> {
let Some(f) = Fixture::new().await? else {
return Ok(());
};
let (status, body) = f
.push_api(&json!({ "filename": "note-7.md", "content": "Kitchen inventory.", "external_id": "note-7" }))
.await?;
assert_eq!(status, StatusCode::OK, "{body}");
let (status, body) = f
.push_api(&json!({ "external_id": "note-7", "deleted": true }))
.await?;
assert_eq!(status, StatusCode::OK, "{body}");
assert_eq!(body["action"], "marked_missing");
// 回复对没推过的 id 也是 marked_missing,所以要看文档本身真的标了
let doc = documents::find_by_external_key(&f.pool, f.api_source, "api:note-7")
.await?
.expect("the tombstone marks the document, it does not delete it");
let (missing,): (bool,) =
sqlx::query_as("SELECT missing_since IS NOT NULL FROM documents WHERE id = $1")
.bind(doc.id)
.fetch_one(&f.pool)
.await?;
assert!(missing, "api:note-7 is marked missing");
let (status, body) = f
.push_api(&json!({ "content": "Kitchen inventory.", "external_id": "note-8" }))
.await?;
assert_ne!(
status,
StatusCode::OK,
"a push with content still needs its filename: {body}"
);
f.cleanup().await
}

/// 密钥的查看和轮换对 `statements` 来源和 `api` 来源一样可用:创建时给过一次的密钥
/// 之后还查得到,轮换后旧密钥立刻失效、新密钥能推。端到端跑服务时抓到的:这两个接口
/// 原来只认 `api`
Expand Down
2 changes: 1 addition & 1 deletion web/src/docs/ingest.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Content-Type: application/json

| Field | Required | Meaning |
|---|---|---|
| `filename` | yes | Display name; also the fallback identity when `external_id` is absent. |
| `filename` | yes* | Display name; also the fallback identity when `external_id` is absent. *Optional on a tombstone that has `external_id`.* |
| `content` | yes* | Full text. *Optional when `deleted` is `true`.* |
| `doc_time` | no | RFC 3339; the document's position on the time axis. |
| `external_id` | no | Stable identity. Same identity + new content → update in place. Without it, `filename` is the identity. |
Expand Down
Loading