feat(arcrun): kbdb_get 加 type/source/user_id filter
之前只支援 block_id / page_name,撈「source=km-writer-direct 的 note」這類 跨 page 查詢做不到。Wiki UI 7B.3g 跟 mira_feed_watcher 都要用 client-side filter 繞,違反「邊用 arcrun 邊修」原則。 擴 contract:保留既有 block_id (mode A) + page_name (mode B),新增純 filter mode C:type / source / user_id 任意組合。同時 page_name + filter 也允許組合。 驗證:source=km-writer-direct&type=note&limit=5 撈到 leo 5 筆未處理河道貼文。 對應 SDD: arcrun.md 三-B 新零件 checklist + tasks.md 7B.3h(mira_feed_watcher 正在組)。
This commit is contained in:
@@ -25,9 +25,13 @@ func hostHttpRequest(
|
||||
type Input struct {
|
||||
KBDBUrl string `json:"kbdb_url"` // optional
|
||||
APIKey string `json:"api_key"` // 必填
|
||||
BlockID string `json:"block_id"` // 與 page_name 二擇一
|
||||
PageName string `json:"page_name"` // 與 block_id 二擇一
|
||||
Limit int `json:"limit"` // optional, default 50
|
||||
BlockID string `json:"block_id"` // 模式 A:單一 block by id(最優先)
|
||||
PageName string `json:"page_name"` // 模式 B:page_name 為主,可疊 type/source/user_id filter
|
||||
// 模式 C:純 filter 查詢,至少要有 type / source / user_id 其中一個(page_name 不必填)
|
||||
Type string `json:"type"` // 例:wiki-page / wiki-paragraph / triplet / note
|
||||
Source string `json:"source"` // 例:km-writer-direct / ai-canon-wiki
|
||||
UserID string `json:"user_id"` // 例:inkstone_mira_tools
|
||||
Limit int `json:"limit"` // optional, default 50
|
||||
}
|
||||
|
||||
var dummy [1]byte
|
||||
@@ -78,8 +82,10 @@ func main() {
|
||||
writeError("api_key 必填")
|
||||
return
|
||||
}
|
||||
if input.BlockID == "" && input.PageName == "" {
|
||||
writeError("block_id 或 page_name 必填其一")
|
||||
// 至少要有一個查詢條件
|
||||
hasFilter := input.Type != "" || input.Source != "" || input.UserID != ""
|
||||
if input.BlockID == "" && input.PageName == "" && !hasFilter {
|
||||
writeError("至少要有一個查詢條件:block_id / page_name / type / source / user_id")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -93,13 +99,34 @@ func main() {
|
||||
limit = 50
|
||||
}
|
||||
|
||||
// 構造 URL:block_id 模式走 /blocks/:id(單一),page_name 模式走 /blocks?page_name=...&limit=N
|
||||
// 構造 URL:block_id 模式走 /blocks/:id(單一),其餘走 /blocks?...query 列表
|
||||
var url string
|
||||
if input.BlockID != "" {
|
||||
url = kbdbURL + "/blocks/" + urlEncode(input.BlockID)
|
||||
} else {
|
||||
url = kbdbURL + "/blocks?page_name=" + urlEncode(input.PageName) +
|
||||
"&limit=" + strconv.Itoa(limit)
|
||||
// list 模式:page_name / type / source / user_id 任意組合
|
||||
params := []string{}
|
||||
if input.PageName != "" {
|
||||
params = append(params, "page_name="+urlEncode(input.PageName))
|
||||
}
|
||||
if input.Type != "" {
|
||||
params = append(params, "type="+urlEncode(input.Type))
|
||||
}
|
||||
if input.Source != "" {
|
||||
params = append(params, "source="+urlEncode(input.Source))
|
||||
}
|
||||
if input.UserID != "" {
|
||||
params = append(params, "user_id="+urlEncode(input.UserID))
|
||||
}
|
||||
params = append(params, "limit="+strconv.Itoa(limit))
|
||||
|
||||
url = kbdbURL + "/blocks?"
|
||||
for i, p := range params {
|
||||
if i > 0 {
|
||||
url += "&"
|
||||
}
|
||||
url += p
|
||||
}
|
||||
}
|
||||
|
||||
headers := map[string]string{
|
||||
|
||||
Reference in New Issue
Block a user