feat(governance): policy-driven ingestion from catalog annotations

Annotation in 来源与目录 is now the only import decision surface:
- migration 000033: catalog_import_intents (durable, rescan-proof per-file
  intent with locator snapshot + fetch lifecycle), source_items.policy_state,
  planned publication state, ui_setting_revisions.ingestion_concurrency
- marking fans a folder decision out to per-file intents, materializes
  versioned items, reuses already-verified local bytes (compare, don't pull),
  and plans one publication per routed KB; blocked retires planned rows
  while live publications stay untouched (需下架 shows in the KB diff)
- artifact.fetch worker lane (scripts/artifact_fetch.py): DingTalk export
  tree/live box API, AList /api/fs/get direct download with SSO-redirect
  fail-closed, PP ledger via locator hash; content-level dedupe on sha256
- 开始处理 promotes planned->pending inside the claim-time concurrency budget
  from system settings; claims enforce it in SQL
- monitor overview rebuilt as knowledge-base diff: planned/needs_removal per
  KB + fetch pipeline summary; frontend lanes 待入库/需下架 replace the
  deprecated snapshot change-set confirmation
- spool: images (png/jpg/gif/bmp/webp) accepted, ppt/pptx rejected in favour
  of PDF twins; DingTalk PPT resolves its converted PDF pair
This commit is contained in:
姚章浩
2026-09-13 22:17:12 +08:00
parent f6cb90cd70
commit 63f3b2c503
38 changed files with 1597 additions and 307 deletions
+29 -4
View File
@@ -34,8 +34,9 @@ type Artifact struct {
}
var supportedFormats = map[string]struct{}{
"pdf": {}, "docx": {}, "doc": {}, "xlsx": {}, "xls": {}, "pptx": {}, "ppt": {},
"pdf": {}, "docx": {}, "doc": {}, "xlsx": {}, "xls": {},
"md": {}, "txt": {}, "csv": {}, "json": {},
"png": {}, "jpg": {}, "jpeg": {}, "gif": {}, "bmp": {}, "webp": {},
}
func InspectVerified(root, relativeRef, format string, maxBytes int64) (Expectation, error) {
@@ -137,7 +138,7 @@ func validateFormat(file *os.File, format string, size int64) error {
if _, err := io.ReadFull(file, header); err != nil || !bytes.Equal(header, []byte("%PDF-")) {
return errors.New("invalid PDF magic")
}
case "docx", "xlsx", "pptx":
case "docx", "xlsx":
archive, err := zip.NewReader(file, size)
if err != nil {
return errors.New("invalid Office ZIP")
@@ -145,7 +146,6 @@ func validateFormat(file *os.File, format string, size int64) error {
required := map[string]string{
"docx": "word/document.xml",
"xlsx": "xl/workbook.xml",
"pptx": "ppt/presentation.xml",
}[format]
foundContentTypes := false
foundRequired := false
@@ -160,12 +160,37 @@ func validateFormat(file *os.File, format string, size int64) error {
if !foundContentTypes || !foundRequired {
return errors.New("missing Office package entry")
}
case "doc", "xls", "ppt":
case "doc", "xls":
header := make([]byte, 8)
oleMagic := []byte{0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1}
if _, err := io.ReadFull(file, header); err != nil || !bytes.Equal(header, oleMagic) {
return errors.New("invalid legacy Office magic")
}
case "png", "jpg", "jpeg", "gif", "bmp", "webp":
header := make([]byte, 12)
n, err := file.Read(header)
if err != nil || n < 12 {
return errors.New("invalid image header")
}
valid := false
switch format {
case "png":
valid = bytes.Equal(header[:8], []byte{0x89, 'P', 'N', 'G', 0x0d, 0x0a, 0x1a, 0x0a})
case "jpg", "jpeg":
valid = header[0] == 0xff && header[1] == 0xd8 && header[2] == 0xff
case "gif":
valid = bytes.Equal(header[:6], []byte("GIF87a")) || bytes.Equal(header[:6], []byte("GIF89a"))
case "bmp":
valid = header[0] == 'B' && header[1] == 'M'
case "webp":
valid = bytes.Equal(header[:4], []byte("RIFF")) && bytes.Equal(header[8:12], []byte("WEBP"))
}
if !valid {
return errors.New("invalid image magic")
}
if _, err := file.Seek(0, io.SeekStart); err != nil {
return errors.New("rewind image artifact")
}
case "json":
decoder := json.NewDecoder(file)
var value any