feat(sites): 站点请求失败留样(site_failure_sample,每站最近 5 份)
- 迁移 0077 新表 site_failure_sample:类型(parse_error / challenge)、请求类型、脱敏 URL、状态码、
关键响应头、错误文案、命中规则、脱敏页面开头(≤ 64 KB);样本几十 KB,不放进每条请求都读的 site.config
- 适配器 onFailureSample 回调接到 runtime.siteAdapter,异步写入并删到最近 5 份,写失败只记日志
- GET /sites/{id}/failure-samples(不带正文)与 /failure-samples/{sampleId}(带正文)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
1 parent
1779e1a0f2
commit
0088c1c9e7
10 files changed
+355
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import type { Kysely } from "kysely";
|
||||
import { dropTables, execDdl } from "../src/migration-helpers.ts";
|
||||
|
||||
// 站点请求失败留样:列表 / 搜索 / 详情报「页面结构无法识别」或「人机验证」时,存一份脱敏后的页面开头(≤ 64 KB)
|
||||
// 与 URL(脱敏)、状态码、关键响应头、请求类型。每站只留最近 5 份(写入时顺手删旧的);站点页「技术信息」里看。
|
||||
// 单独一张表:样本有几十 KB,不放进每条站点请求都要读的 site.config。
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: 迁移不依赖应用表类型
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await execDdl(
|
||||
db,
|
||||
`
|
||||
create table site_failure_sample (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
site_id uuid not null references site(id) on delete cascade,
|
||||
kind text not null check (kind in ('parse_error', 'challenge')),
|
||||
request_kind text not null,
|
||||
url text not null,
|
||||
http_status integer,
|
||||
headers jsonb not null default '{}'::jsonb,
|
||||
message text not null,
|
||||
rule text,
|
||||
body text not null,
|
||||
truncated boolean not null default false,
|
||||
created_at timestamptz not null default now()
|
||||
);
|
||||
create index site_failure_sample_site_idx on site_failure_sample (site_id, created_at desc);
|
||||
`,
|
||||
);
|
||||
}
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: 同上
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await execDdl(db, dropTables(["site_failure_sample"]));
|
||||
}
|
||||
Reference in new issue
Block a user