feat: list all product releases and document client upgrades
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
@@ -97,6 +97,7 @@ func registerBusinessRoutes(r *gin.Engine, a *BusinessAPI) {
|
||||
secured.DELETE("/licenses/:id", a.deleteLicense)
|
||||
secured.POST("/products/:id/releases", a.createRelease)
|
||||
secured.GET("/products/:id/releases", a.listReleases)
|
||||
secured.GET("/releases", a.listReleases)
|
||||
api.POST("/customers/:customer_id/releases/:id/download", a.downloadRelease)
|
||||
secured.POST("/instances/:instance_id/freeze", a.freezeInstance)
|
||||
secured.POST("/licenses", a.issueLicense)
|
||||
|
||||
@@ -77,7 +77,7 @@ func (a *BusinessAPI) downloadIntegrationArchive(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
files := map[string][]byte{
|
||||
"README.md": []byte("# 客户端接入包\n\n阅读 protocol.md、upgrade.md 与 openapi.json,将 prompt.md 提供给实现工程师。verification-keys.md 包含当前部署验签公钥,经可信渠道核对指纹后预置;test-vectors.json 使用随机测试密钥,绝不能导入生产。upgrade.md 说明当前可用下载能力和自动升级待建设的契约;当前没有客户端版本检查或签名升级清单。此包提供文档和实现提示词,不是已完成生产验收的 SDK。\n"),
|
||||
"README.md": []byte("# 客户端接入包\n\n阅读 protocol.md、upgrade.md 与 openapi.json,将 prompt.md 提供给实现工程师。verification-keys.md 包含当前部署验签公钥,经可信渠道核对指纹后预置;test-vectors.json 使用随机测试密钥,绝不能导入生产。upgrade.md 说明当前可用下载能力和自动升级待建设的契约;当前支持实例门户版本查询与授权下载,尚无签名升级清单;按 upgrade.md 实现 UpdateClient 与安装适配器。此包提供文档和实现提示词,不是已完成生产验收的 SDK。\n"),
|
||||
"verification-keys.md": []byte(keys),
|
||||
"prompt.md": []byte(kit.Prompt),
|
||||
"test-vectors.json": vectors,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"info": {"title": "License Platform Client API", "version": "1.0.0", "description": "Client-facing endpoints. Admin session is not a client credential. See protocol.md for canonical signature and trust-root rules."},
|
||||
"servers": [{"url": "https://license.example.com", "description": "Replace with deployed HTTPS origin"}],
|
||||
"paths": {
|
||||
"/api/v1/portal/snapshot": {"post": {"summary": "实例凭据查询已发布版本与下载权限", "parameters": [{"in": "query", "name": "page", "schema": {"type": "integer", "minimum": 1}}, {"in": "query", "name": "page_size", "schema": {"type": "integer", "minimum": 1, "maximum": 100}}], "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["instance_id", "secret"], "properties": {"instance_id": {"type": "string", "format": "uuid"}, "secret": {"type": "string"}}}}}}, "responses": {"200": {"description": "data 含 customer/product/license/instance/lease/releases,meta 为分页;版本项含 id/version/sha256/size_bytes/download_allowed,不是签名升级清单。"}, "403": {"description": "实例凭据无效"}, "503": {"description": "门户不可用"}}}},
|
||||
"/api/v1/activation/instances/{instance_id}": {"post": {
|
||||
"operationId": "activateInstance", "summary": "Activate pre-provisioned instance",
|
||||
"parameters": [{"$ref": "#/components/parameters/InstanceID"}, {"$ref": "#/components/parameters/IdempotencyKey"}],
|
||||
|
||||
@@ -6,10 +6,30 @@
|
||||
|
||||
当前可用:后台按产品发布版本包,记录 version、sha256、size_bytes;客户端通过 POST /api/v1/customers/{customer_id}/releases/{release_id}/download,JSON 提交 instance_id、secret,获得当前有权访问的包。下载时检查实例归属、产品、客户、授权有效期及冻结/撤销状态,并写入下载审计。发布包当前上限 64 MiB。
|
||||
|
||||
尚未实现:面向实例的版本发现、签名升级清单、平台/架构/渠道匹配、灰度及强制升级策略、安装器、健康检查及升级结果回报。GET /api/v1/products/{id}/releases 是管理员接口,客户端不能使用管理员账号或会话调用它。release_id 不代表版本大小顺序,现有版本字符串不保证符合 SemVer。
|
||||
尚未实现:自动目标版本选择、签名升级清单、平台/架构/渠道匹配、灰度及强制升级策略、安装器、健康检查及升级结果回报。GET /api/v1/products/{id}/releases 是管理员接口,客户端不能使用管理员账号或会话调用它。release_id 不代表版本大小顺序,现有版本字符串不保证符合 SemVer。
|
||||
|
||||
下载授权不等于代码可信。当前 X-Package-SHA256 可检测字节损坏,但它与包来自同一服务,不能替代独立签名。license-v2 / lease-v2 签名只证明授权和运行状态,不是升级包签名。当前实现不能宣称已支持安全无人值守自动升级。
|
||||
|
||||
## SDK 快速接入:版本查询与下载(现有接口)
|
||||
|
||||
SDK 复用已激活实例的受保护凭据,不使用管理员会话。Python、Go、Java、.NET 和 Node.js 接入提示词均要求实现以下流程。
|
||||
|
||||
1. `POST /api/v1/portal/snapshot?page=1&page_size=20`,JSON:`{"instance_id":"实例 UUID","secret":"实例密钥"}`。读取 `data.customer.id`、`data.product`、`data.releases` 和 `meta.total/page/page_size`。按分页查询,不能只检查第一页。版本项含 `id`、`version`、`sha256`、`size_bytes`、`download_allowed`。
|
||||
2. 按产品约定比较本地版本;只有明确约定 SemVer 时使用 SemVer。列表按记录 ID 倒序,ID 不代表版本优先级。目前无 OS/架构/渠道字段,多平台包需通过受控发布说明或用户选择匹配目标。
|
||||
3. 用户确认目标后,`POST /api/v1/customers/{data.customer.id}/releases/{release.id}/download`,提交相同 JSON 凭据。`download_allowed` 仅为快照,下载会重新鉴权。
|
||||
4. 同源 HTTPS 流式下载至临时文件,校验实际长度、SHA-256 和独立可信发布签名/平台代码签名。HTTP 200 不代表包完整;凭据不放 URL,不跨域转发。门户摘要不能单独建立发布信任。
|
||||
5. 独立安装器安装并验证实际版本与业务健康,失败回退;保留 instance_id、secret、证书和租约,不能覆盖授权状态目录。
|
||||
|
||||
SDK 建议接口(客户端约定,不是新增服务端 URL):
|
||||
|
||||
- `UpdateClient.listReleases(page)`:返回分页版本、客户/产品信息与下载权限。
|
||||
- `UpdateClient.selectUpdate(currentVersion, releases, policy)`:可注入版本比较、平台选择与用户确认策略。
|
||||
- `UpdateClient.downloadRelease(release, destination)`:同源下载、超时、取消、文件大小限制,返回完整临时文件。
|
||||
- `UpdateClient.verifyPackage(file, release, trustedVerifier)`:校验长度、哈希与独立发布真实性。
|
||||
- `Installer.install(stagedPackage)`:注入桌面/服务/容器安装与回退适配器。未配置可信验证器或安装器时,只查询并提示,不自动执行。
|
||||
|
||||
交付业务调用示例,并覆盖分页、无更新、权限拒绝、损坏包、取消、安装失败回退及授权状态保留。客户端 SDK 源码和安装器仍需在目标工程实现;接入包提供可复用契约、协议和工程提示词。
|
||||
|
||||
## 第一阶段:受控人工升级(可复用现有下载接口)
|
||||
|
||||
发布负责人通过受控渠道向客户端交付目标 release_id、产品、版本、OS/架构、包长度和 SHA-256,并提供独立可信的包签名或平台代码签名校验方式。客户端使用已有实例身份下载,管理员凭据不得进入客户端。没有独立可信的签名/摘要时,仅允许管理员人工验证来源后安装,不启用自动执行。
|
||||
|
||||
@@ -86,6 +86,7 @@ func buildIntegrationKit(language, mode string) integrationKitResponse {
|
||||
Mode: mode,
|
||||
ModeLabel: modeLabel,
|
||||
Endpoints: []kitAPI{
|
||||
{Method: "POST", Path: "/api/v1/portal/snapshot", Purpose: "提交 instance_id、secret,查询已发布版本、客户 ID 与下载权限"},
|
||||
{Method: "POST", Path: "/api/v1/activation/instances/{instance_id}", Purpose: "首次激活,提交 license_key、secret 和 Idempotency-Key"},
|
||||
{Method: "POST", Path: "/api/v1/instances/{instance_id}/heartbeat", Purpose: "刷新已签名运行租约,提交 secret、client_time 和 Idempotency-Key"},
|
||||
{Method: "POST", Path: "/api/v1/customers/{customer_id}/releases/{release_id}/download", Purpose: "以实例凭据下载当前有权访问的发布包"},
|
||||
@@ -100,7 +101,7 @@ func buildIntegrationKit(language, mode string) integrationKitResponse {
|
||||
},
|
||||
Protocol: string(protocol),
|
||||
Upgrade: string(upgrade),
|
||||
Prompt: integrationPrompt(label, modeLabel) + "\n\n" + languageRequirements(language) + "\n\n必须阅读接入包 protocol.md、upgrade.md 与 openapi.json。签名规范化不是 JSON:固定顺序 key=value、LF 连接、UTF-8、无末尾换行;签名是 DER ECDSA 的无填充标准 Base64。先通过包内随机测试公钥的 license-v2 和 lease-v2 验签向量,再连接部署环境。测试公钥不得在生产中信任。\n\n客户端升级:当前仅可复用已授权发布包下载,尚未实现客户端版本检查或签名升级清单。先按 upgrade.md 的第一阶段完成受控人工升级;自动升级必须等待第二阶段升级元数据、独立发布信任根和灰度策略落地。",
|
||||
Prompt: integrationPrompt(label, modeLabel) + "\n\n" + languageRequirements(language) + "\n\n必须阅读接入包 protocol.md、upgrade.md 与 openapi.json。签名规范化不是 JSON:固定顺序 key=value、LF 连接、UTF-8、无末尾换行;签名是 DER ECDSA 的无填充标准 Base64。先通过包内随机测试公钥的 license-v2 和 lease-v2 验签向量,再连接部署环境。测试公钥不得在生产中信任。\n\n客户端升级:实现 UpdateClient.listReleases(page)、selectUpdate、downloadRelease、verifyPackage 和可注入 Installer。通过 POST /api/v1/portal/snapshot 提交 instance_id、secret,读取 data.customer.id、data.releases 与 meta 分页,再调用实例认证下载接口。按 upgrade.md 完成版本比较、用户确认、同源流式下载、长度/摘要/独立签名验证、安装与失败回退,保留授权状态。门户不是签名升级清单;平台/架构匹配、灰度及回报未实现,禁止伪造 API 或自动执行未验证包。",
|
||||
TestVector: kitVector{
|
||||
Version: "lease-v2", InstanceID: "11111111-2222-3333-4444-555555555555", State: "active",
|
||||
ServerTime: "2026-10-09T03:00:00Z", EntitlementExpiresAt: "2027-10-09T03:00:00Z", LeaseExpiresAt: "2026-10-23T03:00:00Z",
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
func TestIntegrationAuthentication(t *testing.T) {
|
||||
r := gin.New()
|
||||
registerBusinessRoutes(r, &BusinessAPI{})
|
||||
for _, path := range []string{"/api/v1/integration-kit", "/api/v1/integration-kit/download", "/api/v1/integration-kit/archive"} {
|
||||
for _, path := range []string{"/api/v1/releases", "/api/v1/integration-kit", "/api/v1/integration-kit/download", "/api/v1/integration-kit/archive"} {
|
||||
w := httptest.NewRecorder()
|
||||
r.ServeHTTP(w, httptest.NewRequest("GET", path, nil))
|
||||
if w.Code != 401 {
|
||||
@@ -40,7 +40,7 @@ func TestIntegrationInputs(t *testing.T) {
|
||||
}
|
||||
for language := range integrationLanguages {
|
||||
kit := buildIntegrationKit(language, "service")
|
||||
if !strings.Contains(kit.Prompt, languageRequirements(language)) || !strings.Contains(kit.Prompt, defaultIntegrationBaseURL) || !strings.Contains(kit.Protocol, defaultIntegrationBaseURL) || kit.PlatformBaseURL != defaultIntegrationBaseURL || !strings.Contains(kit.Protocol, "DER") || !strings.Contains(kit.Upgrade, "当前能力与实施边界") || !strings.Contains(kit.Prompt, "尚未实现客户端版本检查") {
|
||||
if !strings.Contains(kit.Prompt, languageRequirements(language)) || !strings.Contains(kit.Prompt, defaultIntegrationBaseURL) || !strings.Contains(kit.Protocol, defaultIntegrationBaseURL) || kit.PlatformBaseURL != defaultIntegrationBaseURL || !strings.Contains(kit.Protocol, "DER") || !strings.Contains(kit.Upgrade, "当前能力与实施边界") || !strings.Contains(kit.Prompt, "UpdateClient.listReleases") || !strings.Contains(kit.Upgrade, "/api/v1/portal/snapshot") {
|
||||
t.Fatal("incomplete kit")
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func TestIntegrationArchiveAndSignatures(t *testing.T) {
|
||||
mc, _ := gin.CreateTestContext(md)
|
||||
mc.Request = httptest.NewRequest("GET", "/?language=java&mode=container", nil)
|
||||
a.downloadIntegrationKit(mc)
|
||||
if md.Code != 200 || !strings.Contains(md.Body.String(), public) || !strings.Contains(md.Body.String(), "22056bfacc8fe8a240dd2125b629e60ba9f4a5ea0041a1efe034f376a258d562") || strings.Contains(md.Body.String(), "retired") || md.Header().Get("Cache-Control") != "no-store" {
|
||||
if !strings.Contains(md.Body.String(), "SDK 快速接入") || !strings.Contains(md.Body.String(), "UpdateClient.listReleases") || md.Code != 200 || !strings.Contains(md.Body.String(), public) || !strings.Contains(md.Body.String(), "22056bfacc8fe8a240dd2125b629e60ba9f4a5ea0041a1efe034f376a258d562") || strings.Contains(md.Body.String(), "retired") || md.Header().Get("Cache-Control") != "no-store" {
|
||||
t.Fatal("markdown lacks trusted deployment key")
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
@@ -6,18 +6,29 @@ import (
|
||||
)
|
||||
|
||||
func (a *BusinessAPI) listReleases(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
apiError(c, 400, "invalid_request", "产品无效")
|
||||
return
|
||||
raw := c.Param("id")
|
||||
if raw == "" {
|
||||
raw = c.Query("product_id")
|
||||
}
|
||||
where := ""
|
||||
args := []any{}
|
||||
if raw != "" {
|
||||
id, err := strconv.ParseUint(raw, 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
apiError(c, 400, "invalid_request", "产品无效")
|
||||
return
|
||||
}
|
||||
where = " WHERE r.product_id=?"
|
||||
args = append(args, id)
|
||||
}
|
||||
p, size := page(c)
|
||||
var total int
|
||||
if err = a.db.QueryRowContext(c, "SELECT COUNT(*) FROM product_releases WHERE product_id=?", id).Scan(&total); err != nil {
|
||||
if err := a.db.QueryRowContext(c, "SELECT COUNT(*) FROM product_releases r JOIN products p ON p.id=r.product_id"+where, args...).Scan(&total); err != nil {
|
||||
apiError(c, 500, "internal_error", "加载失败")
|
||||
return
|
||||
}
|
||||
rows, err := a.db.QueryContext(c, "SELECT id,version,sha256,size_bytes,published FROM product_releases WHERE product_id=? ORDER BY id DESC LIMIT ? OFFSET ?", id, size, (p-1)*size)
|
||||
args = append(args, size, (p-1)*size)
|
||||
rows, err := a.db.QueryContext(c, "SELECT r.id,r.version,r.sha256,r.size_bytes,r.published,p.id,p.name,p.code FROM product_releases r JOIN products p ON p.id=r.product_id"+where+" ORDER BY r.id DESC LIMIT ? OFFSET ?", args...)
|
||||
if err != nil {
|
||||
apiError(c, 500, "internal_error", "加载失败")
|
||||
return
|
||||
@@ -25,14 +36,14 @@ func (a *BusinessAPI) listReleases(c *gin.Context) {
|
||||
defer rows.Close()
|
||||
data := []gin.H{}
|
||||
for rows.Next() {
|
||||
var rid, n uint64
|
||||
var version, digest string
|
||||
var rid, n, pid uint64
|
||||
var version, digest, name, code string
|
||||
var published bool
|
||||
if err = rows.Scan(&rid, &version, &digest, &n, &published); err != nil {
|
||||
if err = rows.Scan(&rid, &version, &digest, &n, &published, &pid, &name, &code); err != nil {
|
||||
apiError(c, 500, "internal_error", "加载失败")
|
||||
return
|
||||
}
|
||||
data = append(data, gin.H{"id": rid, "version": version, "sha256": digest, "size_bytes": n, "published": published})
|
||||
data = append(data, gin.H{"id": rid, "version": version, "sha256": digest, "size_bytes": n, "published": published, "product_id": pid, "product_name": name, "product_code": code})
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
apiError(c, 500, "internal_error", "加载失败")
|
||||
|
||||
64
backend/internal/httpapi/releases_list_test.go
Normal file
64
backend/internal/httpapi/releases_list_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReleaseListingProductScope(t *testing.T) {
|
||||
for _, filtered := range []bool{false, true} {
|
||||
t.Run(map[bool]string{false: "all", true: "filtered"}[filtered], func(t *testing.T) {
|
||||
where := ""
|
||||
countArgs := []any{}
|
||||
listArgs := []any{20, 20}
|
||||
url := "/api/v1/releases?page=2"
|
||||
if filtered {
|
||||
where = " WHERE r.product_id=?"
|
||||
countArgs = []any{int64(7)}
|
||||
listArgs = []any{int64(7), 20, 20}
|
||||
url += "&product_id=7"
|
||||
}
|
||||
d := &dashboardDB{t: t, queries: []dashboardQuery{
|
||||
{sql: "SELECT COUNT(*) FROM product_releases r JOIN products p ON p.id=r.product_id" + where, args: countArgs, rows: [][]driver.Value{{int64(21)}}},
|
||||
{sql: "SELECT r.id,r.version,r.sha256,r.size_bytes,r.published,p.id,p.name,p.code FROM product_releases r JOIN products p ON p.id=r.product_id" + where + " ORDER BY r.id DESC LIMIT ? OFFSET ?", args: listArgs, rows: [][]driver.Value{{int64(9), "1.2.0", "hash", int64(100), true, int64(7), "产品甲", "product-a"}}},
|
||||
}}
|
||||
db := sql.OpenDB(d)
|
||||
defer db.Close()
|
||||
w := httptest.NewRecorder()
|
||||
c, _ := gin.CreateTestContext(w)
|
||||
c.Request = httptest.NewRequest("GET", url, nil)
|
||||
(&BusinessAPI{db: db}).listReleases(c)
|
||||
var body struct {
|
||||
Data []struct {
|
||||
ProductID uint64 `json:"product_id"`
|
||||
Name string `json:"product_name"`
|
||||
Code string `json:"product_code"`
|
||||
}
|
||||
Meta struct {
|
||||
Total int
|
||||
Page int
|
||||
}
|
||||
}
|
||||
if w.Code != 200 || json.Unmarshal(w.Body.Bytes(), &body) != nil || len(body.Data) != 1 || body.Data[0].ProductID != 7 || body.Data[0].Name != "产品甲" || body.Data[0].Code != "product-a" || body.Meta.Total != 21 || body.Meta.Page != 2 || len(d.queries) != 0 {
|
||||
t.Fatalf("unexpected response %d %s", w.Code, w.Body)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestReleaseListingInvalidProduct(t *testing.T) {
|
||||
for _, id := range []string{"0", "bad", "-1"} {
|
||||
w := httptest.NewRecorder()
|
||||
c, _ := gin.CreateTestContext(w)
|
||||
c.Request = httptest.NewRequest("GET", "/api/v1/releases?product_id="+id, nil)
|
||||
(&BusinessAPI{}).listReleases(c)
|
||||
c.Writer.WriteHeaderNow()
|
||||
if w.Code != 400 {
|
||||
t.Fatalf("invalid product %s: %d", id, w.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,3 +66,7 @@ Schema 11 后,配置 LICENSE_CREDENTIAL_ENCRYPTION_KEY_FILE(独立 32 字节
|
||||
License 授权列表、详情及实例状态以中文展示,API 状态枚举保持不变。已撤销授权的操作栏显示“恢复授权”,调用 `POST /api/v1/licenses/:id/restore`,必须携带 `Idempotency-Key`。仅已撤销授权可恢复,状态更新、操作记录及 `license.restore` 审计在同一事务内完成。
|
||||
|
||||
恢复沿用原开始时间、到期时间、实例绑定和凭据,不延长有效期;已过期授权恢复后显示“已到期”,需再续期。撤销及恢复作用于该授权下所有实例,客户端在下一次成功心跳时取得新状态。已冻结实例需单独解除冻结,客户或产品停用仍会限制使用。实例“已传播状态”保留客户端上次心跳结果,可与当前授权状态暂时不同。
|
||||
|
||||
### 版本管理列表
|
||||
|
||||
默认分页展示全部产品版本,支持独立产品筛选(包括停用产品),显示产品名称、编码和“已发布/未发布”。上传时需单独选择可用产品。管理员统一查询接口为 GET /api/v1/releases,可选 product_id;原按产品查询接口保留。
|
||||
|
||||
@@ -52,3 +52,7 @@ SDK 与工程提示词默认使用 `https://license.yihuiyong.cn` 作为授权
|
||||
授权实例页可导出 yhy-license-trust v1 JSON:api_base_url、protocol_versions、signature_algorithm、current_key_id、未撤销 keys(含 PEM/指纹)、instance_id、customer_id、product_id。不含 secret;激活凭据另行导出。地址必须由管理员确认,HTTPS 根地址或本机 HTTP 回环地址;本机 API 使用 18081,而非前端 15173。
|
||||
|
||||
客户端需实现此新格式的严格导入与受保护存储。导入公钥须经过受控渠道确认,不能把发现接口当作信任根;验证签名、key_id、实例/客户/产品绑定、时间及状态。生产切换必须从生产后台重新交付地址、信任和凭据。导出不是证书,不会激活客户端,也不替代后续撤销策略。各语言 SDK 尚未在本仓库实现。
|
||||
|
||||
### 升级接入
|
||||
|
||||
ZIP、Markdown、接口清单及五种语言工程提示词包含 UpdateClient 查询、目标选择、授权下载、包验证和安装适配器契约。通过 POST /api/v1/portal/snapshot 查询分页已发布版本,再使用实例凭据下载。SDK 源码与安装器需在目标客户端工程实现;签名升级清单、平台自动匹配、灰度及回报尚未实现。
|
||||
|
||||
@@ -67,7 +67,7 @@ onMounted(load)
|
||||
<h3>首次激活凭据从哪里获取?</h3>
|
||||
<p>进入“License 授权”,签发授权后点击该行“实例”,选择“创建实例并获取激活凭据”。授权码是后台授权密钥(license_key);实例 ID(instance_id)和激活密钥(secret)由平台生成。每条授权仅绑定一个实例,配置加密留存后可重复查看和下载,旧实例仅存哈希时无法恢复。secret 持续用于心跳和下载;验签公钥及实例绑定从管理台交付并由开发团队预置。</p>
|
||||
<h3>客户端升级方案</h3>
|
||||
<p class="subheading">当前支持已授权发布包下载;客户端版本检查、签名升级清单、灰度和升级回报仍待服务端建设,不能将其视为现有 API。</p>
|
||||
<p class="subheading">当前支持实例门户版本查询和授权下载;ZIP、Markdown 及工程提示词包含 UpdateClient 查询、下载、校验和安装适配要求。签名升级清单、平台匹配、灰度和升级回报仍待建设。</p>
|
||||
<details><summary>查看升级流程、安全边界与三种部署方案</summary><pre class="vector-box">{{ kit.upgrade }}</pre></details>
|
||||
<h3>租约字段示例</h3>
|
||||
<pre class="vector-box">{{ JSON.stringify(kit.payload_example, null, 2) }}</pre>
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import ReleasesPanel from './ReleasesPanel.vue'
|
||||
|
||||
describe('ReleasesPanel', () => {
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
it('loads all products by default', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue({ ok: true, json: async () => ({ data: [], meta: { total: 0 } }) })
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
const wrapper = mount(ReleasesPanel, { props: { products: [] }, global: { stubs: { ElButton: true, ElSelect: true, ElOption: true, ElInput: true, ElTable: { template: '<div><slot /></div>' }, ElTableColumn: true, ElPagination: true }, directives: { loading: () => {} } } })
|
||||
await flushPromises()
|
||||
expect(fetchMock).toHaveBeenCalledWith('/api/v1/releases?page=1', { credentials: 'include' })
|
||||
expect(wrapper.findAll('el-table-column-stub').map(c => c.attributes('label'))).toContain('产品')
|
||||
})
|
||||
it('shows validation error without sending an invalid publication', async () => {
|
||||
const wrapper = mount(ReleasesPanel, { props: { products: [] }, global: { stubs: { ElButton: { template: '<button @click="$emit(\'click\')"><slot /></button>' }, ElSelect: true, ElOption: true, ElInput: true, ElTable: true, ElTableColumn: true, ElPagination: true }, directives: { loading: () => {} } } })
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true, json: async () => ({ data: [], meta: { total: 0 } }) }))
|
||||
const wrapper = mount(ReleasesPanel, { props: { products: [] }, global: { stubs: { ElButton: { template: '<button @click="$emit(\'click\')"><slot /></button>' }, ElSelect: true, ElOption: true, ElInput: true, ElTable: { template: '<div><slot /></div>' }, ElTableColumn: true, ElPagination: true }, directives: { loading: () => {} } } })
|
||||
expect(wrapper.find('[role="alert"]').exists()).toBe(false)
|
||||
await wrapper.findAll('button')[1]!.trigger('click')
|
||||
expect(wrapper.find('[role="alert"]').text()).toContain('请选择产品')
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { onMounted, ref, watch } from 'vue'
|
||||
import type { Product } from '../api'
|
||||
const props = defineProps<{ products: Product[] }>()
|
||||
const productID = ref<number | null>(null), version = ref(''), loading = ref(false), uploading = ref(false), error = ref(''), file = ref<File | null>(null), page = ref(1), total = ref(0)
|
||||
const releases = ref<{ id: number; version: string; sha256: string; size_bytes: number; published: boolean }[]>([])
|
||||
const filterProductID = ref<number | null>(null)
|
||||
const releases = ref<{ id: number; version: string; sha256: string; size_bytes: number; published: boolean; product_name: string; product_code: string }[]>([])
|
||||
let loadSequence = 0
|
||||
async function responseJSON(response: Response) { const body = await response.json(); if (!response.ok) throw new Error(body.error?.message || '请求失败'); return body }
|
||||
async function load() {
|
||||
const sequence = ++loadSequence
|
||||
if (!productID.value) { releases.value = []; total.value = 0; return }
|
||||
loading.value = true; error.value = ''
|
||||
try { const body = await responseJSON(await fetch(`/api/v1/products/${productID.value}/releases?page=${page.value}`, { credentials: 'include' })); if (sequence === loadSequence) { releases.value = body.data; total.value = body.meta.total } }
|
||||
const productFilter = filterProductID.value ? `&product_id=${filterProductID.value}` : ''
|
||||
try { const body = await responseJSON(await fetch(`/api/v1/releases?page=${page.value}${productFilter}`, { credentials: 'include' })); if (sequence === loadSequence) { releases.value = body.data; total.value = body.meta.total } }
|
||||
catch (e) { if (sequence === loadSequence) error.value = e instanceof Error ? e.message : '加载失败' }
|
||||
finally { if (sequence === loadSequence) loading.value = false }
|
||||
}
|
||||
watch(productID, () => { page.value = 1; releases.value = []; load() })
|
||||
watch(filterProductID, () => { page.value = 1; releases.value = []; load() })
|
||||
onMounted(load)
|
||||
function choose(event: Event) { file.value = (event.target as HTMLInputElement).files?.[0] || null }
|
||||
async function upload() {
|
||||
if (uploading.value) return
|
||||
@@ -29,7 +31,7 @@ async function upload() {
|
||||
</script>
|
||||
<template>
|
||||
<section class="data-section" aria-labelledby="release-title">
|
||||
<div class="section-heading"><h2 id="release-title">产品版本</h2><el-button :loading="loading" :disabled="!productID || uploading" @click="load">刷新</el-button></div>
|
||||
<div class="section-heading"><h2 id="release-title">产品版本</h2><el-button :loading="loading" :disabled="uploading" @click="load">刷新</el-button></div>
|
||||
<div class="inline-form">
|
||||
<el-select v-model="productID" placeholder="选择产品" :disabled="uploading"><el-option v-for="product in props.products" :key="product.id" :value="product.id" :label="product.name" :disabled="!product.active" /></el-select>
|
||||
<el-input v-model="version" placeholder="版本号" :disabled="uploading" />
|
||||
@@ -37,7 +39,8 @@ async function upload() {
|
||||
<el-button type="primary" :loading="uploading" @click="upload">发布版本</el-button>
|
||||
</div>
|
||||
<p v-if="error" role="alert" class="error">{{ error }}</p>
|
||||
<el-table :data="releases" v-loading="loading" empty-text="暂无版本"><el-table-column prop="version" label="版本" /><el-table-column prop="size_bytes" label="字节数" /><el-table-column prop="sha256" label="SHA-256" min-width="290" /><el-table-column prop="published" label="已发布" /></el-table>
|
||||
<div class="inline-form"><el-select v-model="filterProductID" clearable placeholder="全部产品" aria-label="筛选产品"><el-option v-for="product in props.products" :key="product.id" :value="product.id" :label="`${product.name}(${product.code})`" /></el-select></div>
|
||||
<el-table :data="releases" v-loading="loading" empty-text="暂无版本"><el-table-column label="产品" min-width="200"><template #default="{ row }">{{ row.product_name }}({{ row.product_code }})</template></el-table-column><el-table-column prop="version" label="版本" /><el-table-column prop="size_bytes" label="字节数" /><el-table-column prop="sha256" label="SHA-256" min-width="290" /><el-table-column label="已发布"><template #default="{ row }">{{ row.published ? '已发布' : '未发布' }}</template></el-table-column></el-table>
|
||||
<el-pagination v-model:current-page="page" :total="total" :page-size="20" layout="prev, pager, next" @current-change="load" />
|
||||
</section>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user