07955ddf07
服务号「植趣 ZeeQ」已认证,走网页授权(snsapi_base,只拿 openid、用户无感), 不接管消息推送,副作用最小。 流程:PC 建 ticket → 二维码指向 /wx/mp?t= → 用户微信扫码 → 302 到微信授权页 → 回调 /api/v1/wx/mp/callback 用 code 换 openid → 找/建用户 → ticket 置 authorized → PC 轮询 /wx/mp/poll 拿到 authorized → 签发 JWT。ticket 一次性消费防重放。 - 配置(appid/secret/base_url)后台可改,secret AES 加密入库,与微信支付同一套 secrets; - ticket 存 Redis(短 TTL),无 Redis 时回退进程内内存(本地单实例可用,生产必须有 Redis); - User 加 wechat_openid。**部分唯一索引**(WHERE openid <> '')而非普通唯一: 存量邮箱用户该列是空串,普通唯一索引会让多个空串互撞、AutoMigrate 直接失败 —— 与之前 NULL 余额同类的坑,这次提前避开。 单测覆盖:授权 URL 拼接(含 #wechat_redirect 锚点必须在末尾)、secret 加密往返、 建号/查号、空 openid 不误命中存量用户。微信 API 调用依赖公网回调,本地测不了, 留待部署后真机扫码。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
40 lines
1.7 KiB
Go
40 lines
1.7 KiB
Go
package store
|
|
|
|
import "context"
|
|
|
|
// 数据源清单查询(admin「数据源 & RAG」页做实用;此前该页图谱与权重全 mock)。
|
|
// 全平台口径 → WithoutTenant。Doc.KB 存的是 KB 名字(非 id),故按 (space_id, name) 关联。
|
|
|
|
// DatasourceKB 是一条知识库的清单行(含文档数与总字数、租户名)。
|
|
type DatasourceKB struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
// SpaceID 是检索作用域键的前半段:向量/全文/图谱三库里的库名是 "<space_id>/<name>"
|
|
// (见 handler.scopedKB)。admin 检索试验台要按这个完整键定位库,故必须带出来。
|
|
SpaceID string `json:"space_id"`
|
|
Kind string `json:"kind"`
|
|
TenantID string `json:"tenant_id"`
|
|
TenantName string `json:"tenant_name"`
|
|
Owner string `json:"owner"`
|
|
DocCount int64 `json:"doc_count"`
|
|
TotalWords int64 `json:"total_words"`
|
|
}
|
|
|
|
// AllDatasources 列出全平台知识库 + 各库文档数/总字数(admin 数据源清单)。
|
|
func (p *Postgres) AllDatasources(ctx context.Context) []DatasourceKB {
|
|
if p.db == nil {
|
|
return nil
|
|
}
|
|
var out []DatasourceKB
|
|
p.db.WithContext(WithoutTenant(ctx)).Table("sundynix_kb k").
|
|
Select("k.id, k.name, k.space_id, k.kind, k.tenant_id, coalesce(t.name,'') as tenant_name, k.owner, " +
|
|
"count(d.id) as doc_count, coalesce(sum(d.size),0) as total_words").
|
|
Joins("left join sundynix_doc d on d.kb = k.name and d.space_id = k.space_id and d.deleted_at is null").
|
|
Joins("left join sundynix_tenant t on t.id = k.tenant_id").
|
|
Where("k.deleted_at is null").
|
|
Group("k.id, k.name, k.space_id, k.kind, k.tenant_id, t.name, k.owner").
|
|
Order("doc_count desc, k.created_at desc").
|
|
Scan(&out)
|
|
return out
|
|
}
|