feat(versions): 加壳版本可视化(已加固徽标 + 派生来源)

- 版本列表返回 source_version(派生来源版本号),新增「派生自」列
- 版本号后加「已加固」徽标;未加固版本该列显示 -
- 版本详情页加加壳来源横幅(来源版本 + 跳转加壳任务)
- PublishAsVersion 自动进位改为跳过已占用的号;不再误回写 task.version_id
- 前端 schema 补 protected/source_version_id/protect_task_id/source_version
This commit is contained in:
hermes
2026-11-21 16:54:56 +08:00
parent 02df87f464
commit 683ebb31df
8 changed files with 236 additions and 101 deletions
+17 -6
View File
@@ -64,19 +64,30 @@ func PublishAsVersion(taskID uint, opts PublishOptions) (*model.Version, error)
hasSrc := task.VersionID > 0 && database.DB.First(&src, task.VersionID).Error == nil
versionStr := strings.TrimSpace(opts.Version)
if versionStr == "" {
autoBump := versionStr == ""
if autoBump {
switch {
case hasSrc:
versionStr = BumpVersion(src.Version)
versionStr = src.Version
default:
// 不是从某个版本加壳的(面板直传),就按应用当前最高版本进位
var latest model.Version
if database.DB.Where("application_id = ?", app.ID).Order("id DESC").First(&latest).Error == nil {
versionStr = BumpVersion(latest.Version)
versionStr = latest.Version
} else {
versionStr = time.Now().Format("2006.01.02.1504")
}
}
// 自动进位要避开已存在的号:源版本 9.9.9 但 9.9.10 已被人占时继续往上找
for i := 0; i < 200; i++ {
next := BumpVersion(versionStr)
var used int64
database.DB.Model(&model.Version{}).
Where("application_id = ? AND version = ?", app.ID, next).Count(&used)
versionStr = next
if used == 0 {
break
}
}
}
var dup int64
database.DB.Model(&model.Version{}).
@@ -179,8 +190,8 @@ func PublishAsVersion(taskID uint, opts PublishOptions) (*model.Version, error)
})
}
database.DB.Model(&model.ProtectTask{}).Where("id = ?", task.ID).
Update("version_id", v.ID)
// 注意:不要回写 task.version_id —— 那一列表示「加壳来源版本」,
// 生成了哪个版本要靠 version.protect_task_id 反查。
return &v, nil
}
+118 -81
View File
@@ -209,24 +209,45 @@ func handleGetAllVersions(c *gin.Context) {
type VersionWithAppName struct {
model.Version
ApplicationName string `json:"application_name"`
Status string `json:"status"`
Status string `json:"status"`
SourceVersion string `json:"source_version"` // 加壳派生来源的版本号,非加壳版本为空
}
// 一次性查出派生来源版本号(加壳生成的版本才有 source_version_id)
sourceIDs := make([]uint, 0, len(versions))
for _, v := range versions {
if v.SourceVersionID != nil && *v.SourceVersionID > 0 {
sourceIDs = append(sourceIDs, *v.SourceVersionID)
}
}
sourceVersionMap := make(map[uint]string)
if len(sourceIDs) > 0 {
var srcs []model.Version
database.DB.Select("id, version").Where("id IN ?", sourceIDs).Find(&srcs)
for _, s := range srcs {
sourceVersionMap[s.ID] = s.Version
}
}
result := make([]VersionWithAppName, len(versions))
for i, v := range versions {
appName := appNameMap[v.ApplicationID]
log.Printf("[DEBUG] Mapping version %d: ApplicationID=%d -> AppName=%s\n", i, v.ApplicationID, appName)
// 使用数据库中的 publish_status 作为状态
status := v.PublishStatus
if status == "" {
status = "draft"
}
srcVer := ""
if v.SourceVersionID != nil {
srcVer = sourceVersionMap[*v.SourceVersionID]
}
result[i] = VersionWithAppName{
Version: v,
ApplicationName: appName,
Status: status,
Status: status,
SourceVersion: srcVer,
}
}
@@ -262,54 +283,70 @@ func handleGetVersionByID(c *gin.Context) {
}
response.Success(c, gin.H{
"id": version.ID,
"application_id": version.ApplicationID,
"application_name": appNameMap[version.ApplicationID],
"version": version.Version,
"description": version.Description,
"file_path": version.FilePath,
"file_size": version.FileSize,
"file_hash": version.FileHash,
"update_strategy": version.UpdateStrategy,
"update_type": version.UpdateType,
"update_method": version.UpdateMethod,
"custom_download_url": version.CustomDownloadURL,
"changelog": version.Changelog,
"status": version.PublishStatus,
"publish_status": version.PublishStatus,
"superseded_by": version.SupersededBy,
"published_at": version.PublishedAt,
"deprecated_at": version.DeprecatedAt,
"base_version_id": version.BaseVersionID,
"entry_file": version.EntryFile,
"entry_files": version.EntryFiles,
"desktop_shortcut_files": version.DesktopShortcutFiles,
"full_package_path": version.FullPackagePath,
"full_package_size": version.FullPackageSize,
"full_package_hash": version.FullPackageHash,
"files": version.Files,
"created_at": version.CreatedAt,
"updated_at": version.UpdatedAt,
"id": version.ID,
"application_id": version.ApplicationID,
"application_name": appNameMap[version.ApplicationID],
"version": version.Version,
"description": version.Description,
"file_path": version.FilePath,
"file_size": version.FileSize,
"file_hash": version.FileHash,
"update_strategy": version.UpdateStrategy,
"update_type": version.UpdateType,
"update_method": version.UpdateMethod,
"custom_download_url": version.CustomDownloadURL,
"changelog": version.Changelog,
"status": version.PublishStatus,
"publish_status": version.PublishStatus,
"superseded_by": version.SupersededBy,
"published_at": version.PublishedAt,
"deprecated_at": version.DeprecatedAt,
"base_version_id": version.BaseVersionID,
"protected": version.Protected,
"source_version_id": version.SourceVersionID,
"protect_task_id": version.ProtectTaskID,
"source_version": sourceVersionLabel(version.SourceVersionID),
"entry_file": version.EntryFile,
"entry_files": version.EntryFiles,
"desktop_shortcut_files": version.DesktopShortcutFiles,
"full_package_path": version.FullPackagePath,
"full_package_size": version.FullPackageSize,
"full_package_hash": version.FullPackageHash,
"files": version.Files,
"created_at": version.CreatedAt,
"updated_at": version.UpdatedAt,
})
}
// sourceVersionLabel 取派生来源版本的版本号(没有则空串)
func sourceVersionLabel(id *uint) string {
if id == nil || *id == 0 {
return ""
}
var v model.Version
if err := database.DB.Select("id, version").First(&v, *id).Error; err != nil {
return ""
}
return v.Version
}
type CreateVersionRequest struct {
ApplicationID uint `json:"application_id"`
Version string `json:"version"`
FilePath string `json:"file_path"`
FileSize int64 `json:"file_size"`
FileHash string `json:"file_hash"`
EntryFile string `json:"entry_file"`
EntryFiles string `json:"entry_files"`
DesktopShortcutFiles string `json:"desktop_shortcut_files"`
UpdateStrategy string `json:"update_strategy"`
UpdateType string `json:"update_type"`
UpdateMethod string `json:"update_method"`
CustomDownloadURL string `json:"custom_download_url"`
Description string `json:"description"`
Changelog string `json:"changelog"`
BaseVersionID *uint `json:"base_version_id"`
Files []VersionFileInput `json:"files"`
ApplicationID uint `json:"application_id"`
Version string `json:"version"`
FilePath string `json:"file_path"`
FileSize int64 `json:"file_size"`
FileHash string `json:"file_hash"`
EntryFile string `json:"entry_file"`
EntryFiles string `json:"entry_files"`
DesktopShortcutFiles string `json:"desktop_shortcut_files"`
UpdateStrategy string `json:"update_strategy"`
UpdateType string `json:"update_type"`
UpdateMethod string `json:"update_method"`
CustomDownloadURL string `json:"custom_download_url"`
Description string `json:"description"`
Changelog string `json:"changelog"`
BaseVersionID *uint `json:"base_version_id"`
Files []VersionFileInput `json:"files"`
}
type VersionFileInput struct {
@@ -348,21 +385,21 @@ func handleCreateVersionGlobal(c *gin.Context) {
}
version := model.Version{
ApplicationID: req.ApplicationID,
Version: req.Version,
FilePath: req.FilePath,
FileSize: req.FileSize,
FileHash: req.FileHash,
EntryFile: req.EntryFile,
EntryFiles: req.EntryFiles,
DesktopShortcutFiles: req.DesktopShortcutFiles,
UpdateStrategy: req.UpdateStrategy,
UpdateType: req.UpdateType,
UpdateMethod: req.UpdateMethod,
CustomDownloadURL: req.CustomDownloadURL,
Description: req.Description,
Changelog: req.Changelog,
PublishStatus: "draft",
ApplicationID: req.ApplicationID,
Version: req.Version,
FilePath: req.FilePath,
FileSize: req.FileSize,
FileHash: req.FileHash,
EntryFile: req.EntryFile,
EntryFiles: req.EntryFiles,
DesktopShortcutFiles: req.DesktopShortcutFiles,
UpdateStrategy: req.UpdateStrategy,
UpdateType: req.UpdateType,
UpdateMethod: req.UpdateMethod,
CustomDownloadURL: req.CustomDownloadURL,
Description: req.Description,
Changelog: req.Changelog,
PublishStatus: "draft",
}
if version.UpdateStrategy == "" {
@@ -499,21 +536,21 @@ func handleCreateVersionGlobal(c *gin.Context) {
}
type UpdateVersionRequest struct {
Version string `json:"version"`
FilePath string `json:"file_path"`
FileSize int64 `json:"file_size"`
FileHash string `json:"file_hash"`
EntryFile string `json:"entry_file"`
EntryFiles string `json:"entry_files"`
DesktopShortcutFiles string `json:"desktop_shortcut_files"`
UpdateStrategy string `json:"update_strategy"`
UpdateType string `json:"update_type"`
UpdateMethod string `json:"update_method"`
CustomDownloadURL string `json:"custom_download_url"`
Description string `json:"description"`
Changelog string `json:"changelog"`
BaseVersionID *uint `json:"base_version_id"`
Files []VersionFileInput `json:"files"`
Version string `json:"version"`
FilePath string `json:"file_path"`
FileSize int64 `json:"file_size"`
FileHash string `json:"file_hash"`
EntryFile string `json:"entry_file"`
EntryFiles string `json:"entry_files"`
DesktopShortcutFiles string `json:"desktop_shortcut_files"`
UpdateStrategy string `json:"update_strategy"`
UpdateType string `json:"update_type"`
UpdateMethod string `json:"update_method"`
CustomDownloadURL string `json:"custom_download_url"`
Description string `json:"description"`
Changelog string `json:"changelog"`
BaseVersionID *uint `json:"base_version_id"`
Files []VersionFileInput `json:"files"`
}
func handleUpdateVersionGlobal(c *gin.Context) {
@@ -884,10 +921,10 @@ func handleBatchDeleteVersions(c *gin.Context) {
}
type UploadVersionZipResponse struct {
FilePath string `json:"file_path"`
FileSize int64 `json:"file_size"`
FileHash string `json:"file_hash"`
Files []VersionFileInfo `json:"files"`
FilePath string `json:"file_path"`
FileSize int64 `json:"file_size"`
FileHash string `json:"file_hash"`
Files []VersionFileInfo `json:"files"`
}
type VersionFileInfo struct {
+8 -7
View File
@@ -653,12 +653,6 @@ func registerWriteTools(s *mcpserver.MCPServer) {
Changelog: req.GetString("changelog", ""),
PublishNow: req.GetBool("publish_now", false),
}
if opts.Version == "" && task.VersionID > 0 {
var src model.Version
if database.DB.First(&src, task.VersionID).Error == nil {
opts.Version = protect.BumpVersion(src.Version)
}
}
if req.GetBool("dry_run", true) {
var srcInfo gin.H
@@ -668,11 +662,18 @@ func registerWriteTools(s *mcpserver.MCPServer) {
srcInfo = gin.H{"source_version_id": src.ID, "source_version": src.Version, "source_publish_status": src.PublishStatus}
}
}
planned := opts.Version
if planned == "" && task.VersionID > 0 {
var src model.Version
if database.DB.First(&src, task.VersionID).Error == nil {
planned = protect.BumpVersion(src.Version) + "(自动进位,若已占用会继续往上找)"
}
}
return sdk.NewToolResultJSON(gin.H{
"dry_run": true, "task_id": task.ID, "application_id": task.ApplicationID,
"source_name": task.SourceName, "output_name": task.OutputName,
"output_size": task.OutputSize, "arch": task.Arch,
"planned_version": opts.Version, "update_strategy": opts.UpdateStrategy,
"planned_version": planned, "update_strategy": opts.UpdateStrategy,
"publish_now": opts.PublishNow, "source": srcInfo,
})
}
+35 -1
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { Check, CheckCircle, Eye, FileArchive, FilePlus, GitBranch, Loader2, Upload, UploadCloud, X } from 'lucide-vue-next'
import { Check, CheckCircle, Eye, FileArchive, FilePlus, GitBranch, Loader2, Upload, UploadCloud, X, ShieldCheck } from 'lucide-vue-next'
import { computed, onMounted, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRoute, useRouter } from 'vue-router'
@@ -129,11 +129,24 @@ function toggleDesktopShortcut(filePath: string) {
}
}
const protectInfo = ref<{ protected: boolean, sourceVersion: string, sourceVersionId: number | null, taskId: number | null }>({
protected: false,
sourceVersion: '',
sourceVersionId: null,
taskId: null,
})
async function fetchVersion() {
loading.value = true
try {
const ver = await api.get<any>(`/dev/versions/${versionId.value}`)
if (ver) {
protectInfo.value = {
protected: !!ver.protected,
sourceVersion: ver.source_version || '',
sourceVersionId: ver.source_version_id ?? null,
taskId: ver.protect_task_id ?? null,
}
formData.value.application_id = String(ver.application_id || '')
formData.value.version = ver.version || ''
formData.value.description = ver.description || ''
@@ -424,6 +437,27 @@ onMounted(() => {
</div>
<div v-else class="space-y-6">
<!-- 加壳来源提示 -->
<div
v-if="protectInfo.protected"
class="flex flex-wrap items-center gap-3 rounded-lg border border-emerald-500/30 bg-emerald-500/5 px-4 py-3 text-sm"
>
<ShieldCheck class="h-4 w-4 text-emerald-600 dark:text-emerald-400" />
<span class="font-medium text-emerald-700 dark:text-emerald-300">{{ t('admin.versions.protectedBanner') }}</span>
<span v-if="protectInfo.sourceVersion" class="text-muted-foreground">
{{ t('admin.versions.derivedFrom') }}
<code class="ml-1 rounded bg-muted px-1.5 py-0.5">{{ protectInfo.sourceVersion }}</code>
</span>
<span v-else class="text-muted-foreground">{{ t('admin.versions.sourceUnknown') }}</span>
<RouterLink
v-if="protectInfo.taskId"
:to="`/admin/protect`"
class="ml-auto text-xs text-primary underline-offset-4 hover:underline"
>
{{ t('admin.versions.viewProtectTask', { id: protectInfo.taskId }) }}
</RouterLink>
</div>
<div class="grid gap-6 lg:grid-cols-3">
<div class="lg:col-span-2 space-y-6">
<UiCard>
@@ -1,4 +1,4 @@
import { Download, Edit, Trash2, Upload, Archive, ArrowDownToLine, Package } from 'lucide-vue-next'
import { Download, Edit, Trash2, Upload, Archive, ArrowDownToLine, Package, ShieldCheck, UploadCloud } from 'lucide-vue-next'
import type { ColumnDef } from '@tanstack/vue-table'
import { h } from 'vue'
@@ -34,7 +34,39 @@ export function getColumns(options: ColumnOptions, t: (key: string) => string):
accessorKey: 'version',
header: () => t('admin.versions.columns.version'),
cell: ({ row }) => {
return h('code', { class: 'text-sm bg-muted px-2 py-1 rounded' }, row.original.version)
const code = h('code', { class: 'text-sm bg-muted px-2 py-1 rounded' }, row.original.version)
if (!row.original.protected)
return code
const tag = h(Badge, {
variant: 'outline',
class: 'ml-1.5 gap-1 border-emerald-500/40 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400',
title: t('admin.versions.protectedHint'),
}, () => [h(ShieldCheck, { class: 'h-3 w-3' }), h('span', {}, t('admin.versions.protectedBadge'))])
return h('div', { class: 'flex items-center' }, [code, tag])
},
},
{
id: 'source_version',
header: () => t('admin.versions.columns.sourceVersion'),
cell: ({ row }) => {
const src = row.original.source_version
const muted = 'flex items-center gap-1 text-xs text-muted-foreground'
if (!row.original.protected)
return h('span', { class: muted }, [h('span', { class: 'inline-block h-3 w-3 shrink-0' }), h('span', {}, '-')])
if (!row.original.source_version_id)
return h('span', { class: muted }, [
h(UploadCloud, { class: 'h-3 w-3 shrink-0' }),
h('span', {}, t('admin.versions.sourceDirect')),
])
if (!src)
return h('span', { class: muted }, [
h(UploadCloud, { class: 'h-3 w-3 shrink-0' }),
h('span', {}, t('admin.versions.sourceUnknown')),
])
return h('div', { class: 'flex items-center gap-1' }, [
h(ArrowDownToLine, { class: 'h-3 w-3 text-muted-foreground' }),
h('code', { class: 'text-xs bg-muted px-1.5 py-0.5 rounded' }, src),
])
},
},
{
@@ -20,6 +20,10 @@ export const versionSchema = z.object({
status: z.string(), // 兼容旧字段
publish_status: publishStatusSchema,
superseded_by: z.number().nullable().optional(),
protected: z.boolean().optional(),
source_version_id: z.number().nullable().optional(),
protect_task_id: z.number().nullable().optional(),
source_version: z.string().optional(),
published_at: z.string().nullable().optional(),
deprecated_at: z.string().nullable().optional(),
changelog: z.string(),
+10 -2
View File
@@ -1431,7 +1431,8 @@
"status": "Status",
"deltaPackage": "Delta",
"createdAt": "Created At",
"actions": "Actions"
"actions": "Actions",
"sourceVersion": "Derived from"
},
"actions": {
"download": "Download",
@@ -1543,7 +1544,14 @@
"updateFailed": "Failed to update version",
"fetchFailed": "Failed to fetch version information",
"fetchAppsFailed": "Failed to fetch application list"
}
},
"protectedBadge": "Protected",
"protectedHint": "This version is a protected artifact with the verification shell",
"protectedBanner": "This version was generated by the protect tool",
"derivedFrom": "derived from",
"sourceUnknown": "source version removed",
"viewProtectTask": "View protect task #{id}",
"sourceDirect": "uploaded & protected"
},
"cardTypes": {
"title": "Card Type Management",
+10 -2
View File
@@ -1416,7 +1416,8 @@
"status": "状态",
"deltaPackage": "增量包",
"createdAt": "创建时间",
"actions": "操作"
"actions": "操作",
"sourceVersion": "派生自"
},
"actions": {
"download": "下载",
@@ -1539,7 +1540,14 @@
"updateFailed": "更新失败",
"fetchFailed": "获取版本信息失败",
"fetchAppsFailed": "获取应用列表失败"
}
},
"protectedBadge": "已加固",
"protectedHint": "此版本是加壳产物,入口文件带验证壳",
"protectedBanner": "此版本由加壳工具生成",
"derivedFrom": "派生自",
"sourceUnknown": "来源版本已删除",
"viewProtectTask": "查看加壳任务 #{id}",
"sourceDirect": "直接上传加壳"
},
"cardTypes": {
"title": "卡类管理",