feat: list all product releases and document client upgrades
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
@@ -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