feat: 添加下载授权文件功能,支持下载包含授权码和RSA公钥的压缩包,并更新相关国际化文本
This commit is contained in:
1 parent
c9958b12c3
commit
994a5de632
22 files changed
+716
-93
No files matched your search
@@ -28,17 +28,15 @@ jobs:
|
|||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
cache-dependency-path: frontend/package-lock.json
|
cache-dependency-path: frontend/package-lock.json
|
||||||
|
|
||||||
# 缓存node_modules和构建输出
|
# 缓存node_modules(不缓存构建输出,确保每次都是最新构建)
|
||||||
- name: Cache dependencies and build
|
- name: Cache dependencies
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
frontend/node_modules
|
frontend/node_modules
|
||||||
frontend/production
|
key: ${{ runner.os }}-frontend-deps-${{ hashFiles('frontend/package-lock.json') }}
|
||||||
key: ${{ runner.os }}-frontend-${{ hashFiles('frontend/package-lock.json', 'frontend/src/**/*', 'frontend/vite.config.ts') }}
|
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-frontend-${{ hashFiles('frontend/package-lock.json') }}
|
${{ runner.os }}-frontend-deps-
|
||||||
${{ runner.os }}-frontend-
|
|
||||||
|
|
||||||
# 安装依赖
|
# 安装依赖
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
@@ -46,23 +44,33 @@ jobs:
|
|||||||
cd frontend
|
cd frontend
|
||||||
npm ci
|
npm ci
|
||||||
|
|
||||||
# 并行执行类型检查和构建
|
# 清理旧的构建目录(确保使用最新代码构建)
|
||||||
|
- name: Clean old build artifacts
|
||||||
|
run: |
|
||||||
|
cd frontend
|
||||||
|
rm -rf production dist
|
||||||
|
echo "Cleaned old build directories"
|
||||||
|
|
||||||
|
# 执行类型检查和构建
|
||||||
- name: Type check and build
|
- name: Type check and build
|
||||||
run: |
|
run: |
|
||||||
cd frontend
|
cd frontend
|
||||||
# 设置构建环境变量,确保与本地构建一致
|
# 设置构建环境变量,确保与本地构建一致
|
||||||
export VITE_OUTDIR=production
|
export VITE_OUTDIR=production
|
||||||
export VITE_ADDRESS_BASE_URL=/production/
|
export VITE_ADDRESS_BASE_URL=/production/
|
||||||
# 并行执行类型检查和构建以节省时间
|
# 先执行类型检查
|
||||||
npm run type-check &
|
npm run type-check
|
||||||
npm run build:prod &
|
# 然后执行构建
|
||||||
wait
|
npm run build:prod
|
||||||
# 检查构建结果
|
# 检查构建结果
|
||||||
echo "Build completed, checking production directory:"
|
echo "Build completed, checking production directory:"
|
||||||
ls -la production/
|
ls -la production/
|
||||||
# 验证构建产物中的 base 路径
|
# 验证构建产物中的 base 路径
|
||||||
echo "Verifying base path in index.html:"
|
echo "Verifying base path in index.html:"
|
||||||
grep -o 'href="/production/' production/index.html | head -1 || echo "Warning: base path not found"
|
grep -o 'href="/production/' production/index.html | head -1 || echo "Warning: base path not found"
|
||||||
|
# 显示构建产物的时间戳,确认是新构建的
|
||||||
|
echo "Build timestamp:"
|
||||||
|
stat production/index.html 2>/dev/null || ls -la production/index.html
|
||||||
|
|
||||||
# 准备临时部署目录
|
# 准备临时部署目录
|
||||||
- name: Prepare temp directory
|
- name: Prepare temp directory
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ enums:
|
|||||||
|
|
||||||
encryption_type:
|
encryption_type:
|
||||||
"standard": "Standard"
|
"standard": "Standard"
|
||||||
"advanced": "Advanced"
|
|
||||||
|
|
||||||
authorization_status:
|
authorization_status:
|
||||||
"normal": "Normal"
|
"normal": "Normal"
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ enums:
|
|||||||
|
|
||||||
encryption_type:
|
encryption_type:
|
||||||
"standard": "標準暗号化"
|
"standard": "標準暗号化"
|
||||||
"advanced": "高度暗号化"
|
|
||||||
|
|
||||||
authorization_status:
|
authorization_status:
|
||||||
"normal": "正常"
|
"normal": "正常"
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ enums:
|
|||||||
|
|
||||||
encryption_type:
|
encryption_type:
|
||||||
"standard": "标准加密"
|
"standard": "标准加密"
|
||||||
"advanced": "高级加密"
|
|
||||||
|
|
||||||
authorization_status:
|
authorization_status:
|
||||||
"normal": "正常"
|
"normal": "正常"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// Package swagger Code generated by swaggo/swag. DO NOT EDIT
|
// Code generated by swaggo/swag. DO NOT EDIT.
|
||||||
|
|
||||||
package swagger
|
package swagger
|
||||||
|
|
||||||
import "github.com/swaggo/swag"
|
import "github.com/swaggo/swag"
|
||||||
@@ -1363,6 +1364,73 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/api/v1/authorization-codes/{id}/download": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "下载授权码文件,包含授权码和RSA公钥,供客户端使用",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/zip"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"授权码管理"
|
||||||
|
],
|
||||||
|
"summary": "下载授权文件",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "授权码ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "包含授权码文件和RSA公钥的压缩包",
|
||||||
|
"schema": {
|
||||||
|
"type": "file"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "请求参数无效",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/models.ErrorResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "未认证",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/models.ErrorResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "授权码不存在",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/models.ErrorResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"409": {
|
||||||
|
"description": "授权码不可用",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/models.ErrorResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "服务器内部错误",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/models.ErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/v1/authorization-codes/{id}/lock": {
|
"/api/v1/authorization-codes/{id}/lock": {
|
||||||
"put": {
|
"put": {
|
||||||
"security": [
|
"security": [
|
||||||
@@ -1984,7 +2052,7 @@ const docTemplate = `{
|
|||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/octet-stream"
|
"application/zip"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"许可证管理"
|
"许可证管理"
|
||||||
@@ -2001,7 +2069,7 @@ const docTemplate = `{
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "许可证文件",
|
"description": "包含许可证文件和RSA公钥的压缩包",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "file"
|
"type": "file"
|
||||||
}
|
}
|
||||||
@@ -3865,8 +3933,6 @@ var SwaggerInfo = &swag.Spec{
|
|||||||
Description: "软件授权管理平台API文档",
|
Description: "软件授权管理平台API文档",
|
||||||
InfoInstanceName: "swagger",
|
InfoInstanceName: "swagger",
|
||||||
SwaggerTemplate: docTemplate,
|
SwaggerTemplate: docTemplate,
|
||||||
LeftDelim: "{{",
|
|
||||||
RightDelim: "}}",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -1360,6 +1360,73 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/api/v1/authorization-codes/{id}/download": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "下载授权码文件,包含授权码和RSA公钥,供客户端使用",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/zip"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"授权码管理"
|
||||||
|
],
|
||||||
|
"summary": "下载授权文件",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "授权码ID",
|
||||||
|
"name": "id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "包含授权码文件和RSA公钥的压缩包",
|
||||||
|
"schema": {
|
||||||
|
"type": "file"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "请求参数无效",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/models.ErrorResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "未认证",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/models.ErrorResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"404": {
|
||||||
|
"description": "授权码不存在",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/models.ErrorResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"409": {
|
||||||
|
"description": "授权码不可用",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/models.ErrorResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "服务器内部错误",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/models.ErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/api/v1/authorization-codes/{id}/lock": {
|
"/api/v1/authorization-codes/{id}/lock": {
|
||||||
"put": {
|
"put": {
|
||||||
"security": [
|
"security": [
|
||||||
@@ -1981,7 +2048,7 @@
|
|||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
"produces": [
|
"produces": [
|
||||||
"application/octet-stream"
|
"application/zip"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"许可证管理"
|
"许可证管理"
|
||||||
@@ -1998,7 +2065,7 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "许可证文件",
|
"description": "包含许可证文件和RSA公钥的压缩包",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "file"
|
"type": "file"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1959,6 +1959,49 @@ paths:
|
|||||||
summary: 查询授权变更历史列表
|
summary: 查询授权变更历史列表
|
||||||
tags:
|
tags:
|
||||||
- 授权码管理
|
- 授权码管理
|
||||||
|
/api/v1/authorization-codes/{id}/download:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 下载授权码文件,包含授权码和RSA公钥,供客户端使用
|
||||||
|
parameters:
|
||||||
|
- description: 授权码ID
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/zip
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: 包含授权码文件和RSA公钥的压缩包
|
||||||
|
schema:
|
||||||
|
type: file
|
||||||
|
"400":
|
||||||
|
description: 请求参数无效
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/models.ErrorResponse'
|
||||||
|
"401":
|
||||||
|
description: 未认证
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/models.ErrorResponse'
|
||||||
|
"404":
|
||||||
|
description: 授权码不存在
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/models.ErrorResponse'
|
||||||
|
"409":
|
||||||
|
description: 授权码不可用
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/models.ErrorResponse'
|
||||||
|
"500":
|
||||||
|
description: 服务器内部错误
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/models.ErrorResponse'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
|
summary: 下载授权文件
|
||||||
|
tags:
|
||||||
|
- 授权码管理
|
||||||
/api/v1/authorization-codes/{id}/lock:
|
/api/v1/authorization-codes/{id}/lock:
|
||||||
put:
|
put:
|
||||||
consumes:
|
consumes:
|
||||||
@@ -2349,10 +2392,10 @@ paths:
|
|||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
produces:
|
produces:
|
||||||
- application/octet-stream
|
- application/zip
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: 许可证文件
|
description: 包含许可证文件和RSA公钥的压缩包
|
||||||
schema:
|
schema:
|
||||||
type: file
|
type: file
|
||||||
"400":
|
"400":
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"license-manager/internal/api/middleware"
|
"license-manager/internal/api/middleware"
|
||||||
|
"license-manager/internal/config"
|
||||||
"license-manager/internal/models"
|
"license-manager/internal/models"
|
||||||
"license-manager/internal/service"
|
"license-manager/internal/service"
|
||||||
"license-manager/pkg/i18n"
|
"license-manager/pkg/i18n"
|
||||||
@@ -211,6 +218,148 @@ func (h *AuthorizationCodeHandler) GetAuthorizationCode(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DownloadAuthorizationFile 下载授权文件
|
||||||
|
// @Summary 下载授权文件
|
||||||
|
// @Description 下载授权码文件,包含授权码和RSA公钥,供客户端使用
|
||||||
|
// @Tags 授权码管理
|
||||||
|
// @Accept json
|
||||||
|
// @Produce application/zip
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param id path string true "授权码ID"
|
||||||
|
// @Success 200 {file} binary "包含授权码文件和RSA公钥的压缩包"
|
||||||
|
// @Failure 400 {object} models.ErrorResponse "请求参数无效"
|
||||||
|
// @Failure 401 {object} models.ErrorResponse "未认证"
|
||||||
|
// @Failure 404 {object} models.ErrorResponse "授权码不存在"
|
||||||
|
// @Failure 409 {object} models.ErrorResponse "授权码不可用"
|
||||||
|
// @Failure 500 {object} models.ErrorResponse "服务器内部错误"
|
||||||
|
// @Router /api/v1/authorization-codes/{id}/download [get]
|
||||||
|
func (h *AuthorizationCodeHandler) DownloadAuthorizationFile(c *gin.Context) {
|
||||||
|
lang := middleware.GetLanguage(c)
|
||||||
|
id := c.Param("id")
|
||||||
|
if id == "" {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900001", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := middleware.WithLanguage(c.Request.Context(), c)
|
||||||
|
|
||||||
|
fileData, fileName, authCode, err := h.authCodeService.GenerateAuthorizationFile(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
var i18nErr *i18n.I18nError
|
||||||
|
if errors.As(err, &i18nErr) {
|
||||||
|
c.JSON(i18nErr.HttpCode, models.ErrorResponse{
|
||||||
|
Code: i18nErr.Code,
|
||||||
|
Message: i18nErr.Message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := config.GetConfig()
|
||||||
|
if cfg == nil || cfg.License.RSA.PublicKeyPath == "" {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
publicKeyPath := filepath.Clean(cfg.License.RSA.PublicKeyPath)
|
||||||
|
publicKeyData, err := os.ReadFile(publicKeyPath)
|
||||||
|
if err != nil {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var buffer bytes.Buffer
|
||||||
|
zipWriter := zip.NewWriter(&buffer)
|
||||||
|
|
||||||
|
const zipAuthFileName = "authorization_code.txt"
|
||||||
|
authFileWriter, err := zipWriter.Create(zipAuthFileName)
|
||||||
|
if err != nil {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, err := authFileWriter.Write(fileData); err != nil {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
publicKeyWriter, err := zipWriter.Create("rsa_public_key.pem")
|
||||||
|
if err != nil {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, err := publicKeyWriter.Write(publicKeyData); err != nil {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := zipWriter.Close(); err != nil {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
packageFileName := fmt.Sprintf("authorization_package_%s.zip", strings.TrimSpace(authCode))
|
||||||
|
if strings.TrimSpace(authCode) == "" {
|
||||||
|
baseName := strings.TrimSuffix(fileName, filepath.Ext(fileName))
|
||||||
|
packageFileName = fmt.Sprintf("%s_package.zip", baseName)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Header("Content-Description", "File Transfer")
|
||||||
|
c.Header("Content-Type", "application/zip")
|
||||||
|
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", packageFileName))
|
||||||
|
c.Header("Content-Transfer-Encoding", "binary")
|
||||||
|
c.Header("Cache-Control", "must-revalidate")
|
||||||
|
c.Header("Pragma", "public")
|
||||||
|
c.Data(http.StatusOK, "application/zip", buffer.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateAuthorizationCode 更新授权码
|
// UpdateAuthorizationCode 更新授权码
|
||||||
// @Summary 更新授权码
|
// @Summary 更新授权码
|
||||||
// @Description 更新授权码信息,所有字段都是可选的,需要指定变更类型和原因
|
// @Description 更新授权码信息,所有字段都是可选的,需要指定变更类型和原因
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"license-manager/internal/api/middleware"
|
"license-manager/internal/api/middleware"
|
||||||
|
"license-manager/internal/config"
|
||||||
"license-manager/internal/models"
|
"license-manager/internal/models"
|
||||||
"license-manager/internal/service"
|
"license-manager/internal/service"
|
||||||
"license-manager/pkg/i18n"
|
"license-manager/pkg/i18n"
|
||||||
@@ -298,10 +304,10 @@ func (h *LicenseHandler) RevokeLicense(c *gin.Context) {
|
|||||||
// @Description 下载加密的许可证文件,用于客户端软件激活
|
// @Description 下载加密的许可证文件,用于客户端软件激活
|
||||||
// @Tags 许可证管理
|
// @Tags 许可证管理
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce application/octet-stream
|
// @Produce application/zip
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
// @Param id path string true "许可证ID"
|
// @Param id path string true "许可证ID"
|
||||||
// @Success 200 {file} binary "许可证文件"
|
// @Success 200 {file} binary "包含许可证文件和RSA公钥的压缩包"
|
||||||
// @Failure 400 {object} models.ErrorResponse "请求参数无效"
|
// @Failure 400 {object} models.ErrorResponse "请求参数无效"
|
||||||
// @Failure 401 {object} models.ErrorResponse "未认证"
|
// @Failure 401 {object} models.ErrorResponse "未认证"
|
||||||
// @Failure 404 {object} models.ErrorResponse "许可证不存在"
|
// @Failure 404 {object} models.ErrorResponse "许可证不存在"
|
||||||
@@ -309,9 +315,9 @@ func (h *LicenseHandler) RevokeLicense(c *gin.Context) {
|
|||||||
// @Failure 500 {object} models.ErrorResponse "服务器内部错误"
|
// @Failure 500 {object} models.ErrorResponse "服务器内部错误"
|
||||||
// @Router /api/v1/licenses/{id}/download [get]
|
// @Router /api/v1/licenses/{id}/download [get]
|
||||||
func (h *LicenseHandler) DownloadLicenseFile(c *gin.Context) {
|
func (h *LicenseHandler) DownloadLicenseFile(c *gin.Context) {
|
||||||
|
lang := middleware.GetLanguage(c)
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
if id == "" {
|
if id == "" {
|
||||||
lang := middleware.GetLanguage(c)
|
|
||||||
status, errCode, message := i18n.NewI18nErrorResponse("900001", lang)
|
status, errCode, message := i18n.NewI18nErrorResponse("900001", lang)
|
||||||
c.JSON(status, models.ErrorResponse{
|
c.JSON(status, models.ErrorResponse{
|
||||||
Code: errCode,
|
Code: errCode,
|
||||||
@@ -324,7 +330,7 @@ func (h *LicenseHandler) DownloadLicenseFile(c *gin.Context) {
|
|||||||
// 设置语言到Context中
|
// 设置语言到Context中
|
||||||
ctx := middleware.WithLanguage(c.Request.Context(), c)
|
ctx := middleware.WithLanguage(c.Request.Context(), c)
|
||||||
|
|
||||||
fileData, fileName, err := h.licenseService.GenerateLicenseFile(ctx, id)
|
fileData, fileName, licenseKey, err := h.licenseService.GenerateLicenseFile(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 错误已经在Service层完全包装好了,直接使用
|
// 错误已经在Service层完全包装好了,直接使用
|
||||||
var i18nErr *i18n.I18nError
|
var i18nErr *i18n.I18nError
|
||||||
@@ -347,16 +353,99 @@ func (h *LicenseHandler) DownloadLicenseFile(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg := config.GetConfig()
|
||||||
|
if cfg == nil || cfg.License.RSA.PublicKeyPath == "" {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
publicKeyPath := filepath.Clean(cfg.License.RSA.PublicKeyPath)
|
||||||
|
publicKeyData, err := os.ReadFile(publicKeyPath)
|
||||||
|
if err != nil {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var buffer bytes.Buffer
|
||||||
|
zipWriter := zip.NewWriter(&buffer)
|
||||||
|
|
||||||
|
const zipLicenseFileName = "license.lic"
|
||||||
|
licenseFileWriter, err := zipWriter.Create(zipLicenseFileName)
|
||||||
|
if err != nil {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, err := licenseFileWriter.Write(fileData); err != nil {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
publicKeyWriter, err := zipWriter.Create("rsa_public_key.pem")
|
||||||
|
if err != nil {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, err := publicKeyWriter.Write(publicKeyData); err != nil {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := zipWriter.Close(); err != nil {
|
||||||
|
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
|
||||||
|
c.JSON(status, models.ErrorResponse{
|
||||||
|
Code: errCode,
|
||||||
|
Message: message,
|
||||||
|
Timestamp: time.Now().Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
packageFileName := fmt.Sprintf("license_package_%s.zip", strings.TrimSpace(licenseKey))
|
||||||
|
if strings.TrimSpace(licenseKey) == "" {
|
||||||
|
baseName := strings.TrimSuffix(fileName, filepath.Ext(fileName))
|
||||||
|
packageFileName = fmt.Sprintf("%s_package.zip", baseName)
|
||||||
|
}
|
||||||
|
|
||||||
// 设置响应头,指示这是一个文件下载
|
// 设置响应头,指示这是一个文件下载
|
||||||
c.Header("Content-Description", "File Transfer")
|
c.Header("Content-Description", "File Transfer")
|
||||||
c.Header("Content-Type", "application/octet-stream")
|
c.Header("Content-Type", "application/zip")
|
||||||
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", fileName))
|
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", packageFileName))
|
||||||
c.Header("Content-Transfer-Encoding", "binary")
|
c.Header("Content-Transfer-Encoding", "binary")
|
||||||
c.Header("Cache-Control", "must-revalidate")
|
c.Header("Cache-Control", "must-revalidate")
|
||||||
c.Header("Pragma", "public")
|
c.Header("Pragma", "public")
|
||||||
|
|
||||||
// 返回文件内容
|
// 返回文件内容
|
||||||
c.Data(http.StatusOK, "application/octet-stream", fileData)
|
c.Data(http.StatusOK, "application/zip", buffer.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActivateLicense 激活许可证
|
// ActivateLicense 激活许可证
|
||||||
@@ -533,4 +622,4 @@ func (h *LicenseHandler) GetStatsOverview(c *gin.Context) {
|
|||||||
Message: successMessage,
|
Message: successMessage,
|
||||||
Data: data,
|
Data: data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ func SetupRouter() *gin.Engine {
|
|||||||
public := api.Group("")
|
public := api.Group("")
|
||||||
{
|
{
|
||||||
public.POST("/v1/login", authHandler.Login)
|
public.POST("/v1/login", authHandler.Login)
|
||||||
|
|
||||||
// 许可证激活接口(客户端软件使用)
|
// 许可证激活接口(客户端软件使用)
|
||||||
public.POST("/v1/activate", licenseHandler.ActivateLicense)
|
public.POST("/v1/activate", licenseHandler.ActivateLicense)
|
||||||
public.POST("/v1/heartbeat", licenseHandler.Heartbeat)
|
public.POST("/v1/heartbeat", licenseHandler.Heartbeat)
|
||||||
@@ -89,7 +89,7 @@ func SetupRouter() *gin.Engine {
|
|||||||
// 认证相关
|
// 认证相关
|
||||||
auth.POST("/v1/logout", authHandler.Logout)
|
auth.POST("/v1/logout", authHandler.Logout)
|
||||||
auth.POST("/v1/auth/refresh", authHandler.RefreshToken)
|
auth.POST("/v1/auth/refresh", authHandler.RefreshToken)
|
||||||
|
|
||||||
// 客户管理
|
// 客户管理
|
||||||
auth.GET("/customers", customerHandler.GetCustomerList)
|
auth.GET("/customers", customerHandler.GetCustomerList)
|
||||||
auth.GET("/customers/:id", customerHandler.GetCustomer)
|
auth.GET("/customers/:id", customerHandler.GetCustomer)
|
||||||
@@ -97,30 +97,31 @@ func SetupRouter() *gin.Engine {
|
|||||||
auth.PUT("/customers/:id", customerHandler.UpdateCustomer)
|
auth.PUT("/customers/:id", customerHandler.UpdateCustomer)
|
||||||
auth.DELETE("/customers/:id", customerHandler.DeleteCustomer)
|
auth.DELETE("/customers/:id", customerHandler.DeleteCustomer)
|
||||||
auth.PATCH("/customers/:id/status", customerHandler.UpdateCustomerStatus)
|
auth.PATCH("/customers/:id/status", customerHandler.UpdateCustomerStatus)
|
||||||
|
|
||||||
// 枚举管理
|
// 枚举管理
|
||||||
auth.GET("/enums", enumHandler.GetAllEnums)
|
auth.GET("/enums", enumHandler.GetAllEnums)
|
||||||
auth.GET("/enums/:type", enumHandler.GetEnumsByType)
|
auth.GET("/enums/:type", enumHandler.GetEnumsByType)
|
||||||
|
|
||||||
// 授权码管理
|
// 授权码管理
|
||||||
auth.GET("/v1/authorization-codes", authCodeHandler.GetAuthorizationCodeList)
|
auth.GET("/v1/authorization-codes", authCodeHandler.GetAuthorizationCodeList)
|
||||||
auth.POST("/v1/authorization-codes", authCodeHandler.CreateAuthorizationCode)
|
auth.POST("/v1/authorization-codes", authCodeHandler.CreateAuthorizationCode)
|
||||||
auth.GET("/v1/authorization-codes/:id", authCodeHandler.GetAuthorizationCode)
|
auth.GET("/v1/authorization-codes/:id", authCodeHandler.GetAuthorizationCode)
|
||||||
|
auth.GET("/v1/authorization-codes/:id/download", authCodeHandler.DownloadAuthorizationFile)
|
||||||
auth.PUT("/v1/authorization-codes/:id", authCodeHandler.UpdateAuthorizationCode)
|
auth.PUT("/v1/authorization-codes/:id", authCodeHandler.UpdateAuthorizationCode)
|
||||||
auth.PUT("/v1/authorization-codes/:id/lock", authCodeHandler.LockUnlockAuthorizationCode)
|
auth.PUT("/v1/authorization-codes/:id/lock", authCodeHandler.LockUnlockAuthorizationCode)
|
||||||
auth.DELETE("/v1/authorization-codes/:id", authCodeHandler.DeleteAuthorizationCode)
|
auth.DELETE("/v1/authorization-codes/:id", authCodeHandler.DeleteAuthorizationCode)
|
||||||
auth.GET("/v1/authorization-codes/:id/changes", authCodeHandler.GetAuthorizationChangeList)
|
auth.GET("/v1/authorization-codes/:id/changes", authCodeHandler.GetAuthorizationChangeList)
|
||||||
|
|
||||||
// 许可证管理
|
// 许可证管理
|
||||||
auth.GET("/v1/licenses", licenseHandler.GetLicenseList)
|
auth.GET("/v1/licenses", licenseHandler.GetLicenseList)
|
||||||
auth.GET("/v1/licenses/:id", licenseHandler.GetLicense)
|
auth.GET("/v1/licenses/:id", licenseHandler.GetLicense)
|
||||||
auth.POST("/v1/licenses", licenseHandler.CreateLicense)
|
auth.POST("/v1/licenses", licenseHandler.CreateLicense)
|
||||||
auth.PUT("/v1/licenses/:id/revoke", licenseHandler.RevokeLicense)
|
auth.PUT("/v1/licenses/:id/revoke", licenseHandler.RevokeLicense)
|
||||||
auth.GET("/v1/licenses/:id/download", licenseHandler.DownloadLicenseFile)
|
auth.GET("/v1/licenses/:id/download", licenseHandler.DownloadLicenseFile)
|
||||||
|
|
||||||
// 统计分析
|
// 统计分析
|
||||||
auth.GET("/v1/stats/overview", licenseHandler.GetStatsOverview)
|
auth.GET("/v1/stats/overview", licenseHandler.GetStatsOverview)
|
||||||
|
|
||||||
// 仪表盘接口
|
// 仪表盘接口
|
||||||
auth.GET("/v1/dashboard/authorization-trend", dashboardHandler.GetAuthorizationTrend)
|
auth.GET("/v1/dashboard/authorization-trend", dashboardHandler.GetAuthorizationTrend)
|
||||||
auth.GET("/v1/dashboard/recent-authorizations", dashboardHandler.GetRecentAuthorizations)
|
auth.GET("/v1/dashboard/recent-authorizations", dashboardHandler.GetRecentAuthorizations)
|
||||||
|
|||||||
@@ -228,6 +228,34 @@ func (s *authorizationCodeService) GetAuthorizationCode(ctx context.Context, id
|
|||||||
return authCode, nil
|
return authCode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateAuthorizationFile 生成授权码文件内容
|
||||||
|
func (s *authorizationCodeService) GenerateAuthorizationFile(ctx context.Context, id string) ([]byte, string, string, error) {
|
||||||
|
lang := pkgcontext.GetLanguageFromContext(ctx)
|
||||||
|
|
||||||
|
if id == "" {
|
||||||
|
return nil, "", "", i18n.NewI18nError("900001", lang)
|
||||||
|
}
|
||||||
|
|
||||||
|
authCode, err := s.authCodeRepo.GetAuthorizationCodeByID(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, repository.ErrAuthorizationCodeNotFound) {
|
||||||
|
return nil, "", "", i18n.NewI18nError("300001", lang) // 授权码不存在
|
||||||
|
}
|
||||||
|
return nil, "", "", i18n.NewI18nError("900004", lang, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
if authCode.IsLocked {
|
||||||
|
return nil, "", "", i18n.NewI18nError("300003", lang) // 授权码已锁定
|
||||||
|
}
|
||||||
|
if now.Before(authCode.StartDate) || now.After(authCode.EndDate) {
|
||||||
|
return nil, "", "", i18n.NewI18nError("300001", lang) // 授权码未生效或已过期
|
||||||
|
}
|
||||||
|
|
||||||
|
fileName := fmt.Sprintf("authorization_%s.txt", authCode.Code)
|
||||||
|
return []byte(authCode.Code), fileName, authCode.Code, nil
|
||||||
|
}
|
||||||
|
|
||||||
// fillAuthorizationCodeDisplayFields 填充完整授权码模型的多语言显示字段
|
// fillAuthorizationCodeDisplayFields 填充完整授权码模型的多语言显示字段
|
||||||
func (s *authorizationCodeService) fillAuthorizationCodeDisplayFields(authCode *models.AuthorizationCode, lang string) {
|
func (s *authorizationCodeService) fillAuthorizationCodeDisplayFields(authCode *models.AuthorizationCode, lang string) {
|
||||||
// 计算状态
|
// 计算状态
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ type AuthorizationCodeService interface {
|
|||||||
LockUnlockAuthorizationCode(ctx context.Context, id string, req *models.AuthorizationCodeLockRequest) (*models.AuthorizationCode, error)
|
LockUnlockAuthorizationCode(ctx context.Context, id string, req *models.AuthorizationCodeLockRequest) (*models.AuthorizationCode, error)
|
||||||
DeleteAuthorizationCode(ctx context.Context, id string) error
|
DeleteAuthorizationCode(ctx context.Context, id string) error
|
||||||
GetAuthorizationChangeList(ctx context.Context, authCodeID string, req *models.AuthorizationChangeListRequest) (*models.AuthorizationChangeListResponse, error)
|
GetAuthorizationChangeList(ctx context.Context, authCodeID string, req *models.AuthorizationChangeListRequest) (*models.AuthorizationChangeListResponse, error)
|
||||||
|
GenerateAuthorizationFile(ctx context.Context, id string) ([]byte, string, string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LicenseService 许可证服务接口
|
// LicenseService 许可证服务接口
|
||||||
@@ -51,12 +52,12 @@ type LicenseService interface {
|
|||||||
GetLicense(ctx context.Context, id string) (*models.LicenseDetailResponse, error)
|
GetLicense(ctx context.Context, id string) (*models.LicenseDetailResponse, error)
|
||||||
CreateLicense(ctx context.Context, req *models.LicenseCreateRequest) (*models.License, error)
|
CreateLicense(ctx context.Context, req *models.LicenseCreateRequest) (*models.License, error)
|
||||||
RevokeLicense(ctx context.Context, id string, req *models.LicenseRevokeRequest) (*models.License, error)
|
RevokeLicense(ctx context.Context, id string, req *models.LicenseRevokeRequest) (*models.License, error)
|
||||||
GenerateLicenseFile(ctx context.Context, id string) ([]byte, string, error)
|
GenerateLicenseFile(ctx context.Context, id string) ([]byte, string, string, error)
|
||||||
|
|
||||||
// 客户端激活和心跳接口
|
// 客户端激活和心跳接口
|
||||||
ActivateLicense(ctx context.Context, req *models.ActivateRequest, clientIP string) (*models.ActivateResponse, error)
|
ActivateLicense(ctx context.Context, req *models.ActivateRequest, clientIP string) (*models.ActivateResponse, error)
|
||||||
Heartbeat(ctx context.Context, req *models.HeartbeatRequest, clientIP string) (*models.HeartbeatResponse, error)
|
Heartbeat(ctx context.Context, req *models.HeartbeatRequest, clientIP string) (*models.HeartbeatResponse, error)
|
||||||
|
|
||||||
// 统计接口
|
// 统计接口
|
||||||
GetStatsOverview(ctx context.Context) (*models.StatsOverviewResponse, error)
|
GetStatsOverview(ctx context.Context) (*models.StatsOverviewResponse, error)
|
||||||
}
|
}
|
||||||
@@ -65,7 +66,7 @@ type LicenseService interface {
|
|||||||
type DashboardService interface {
|
type DashboardService interface {
|
||||||
// 获取授权趋势数据
|
// 获取授权趋势数据
|
||||||
GetAuthorizationTrend(ctx context.Context, req *models.DashboardAuthorizationTrendRequest) (*models.DashboardAuthorizationTrendResponse, error)
|
GetAuthorizationTrend(ctx context.Context, req *models.DashboardAuthorizationTrendRequest) (*models.DashboardAuthorizationTrendResponse, error)
|
||||||
|
|
||||||
// 获取最近授权列表
|
// 获取最近授权列表
|
||||||
GetRecentAuthorizations(ctx context.Context, req *models.DashboardRecentAuthorizationsRequest) (*models.DashboardRecentAuthorizationsResponse, error)
|
GetRecentAuthorizations(ctx context.Context, req *models.DashboardRecentAuthorizationsRequest) (*models.DashboardRecentAuthorizationsResponse, error)
|
||||||
}
|
}
|
||||||
@@ -251,14 +251,14 @@ func (s *licenseService) RevokeLicense(ctx context.Context, id string, req *mode
|
|||||||
|
|
||||||
// 更新许可证状态为撤销
|
// 更新许可证状态为撤销
|
||||||
existingLicense.Status = "revoked"
|
existingLicense.Status = "revoked"
|
||||||
|
|
||||||
// 如果提供了撤销原因,保存到使用数据中
|
// 如果提供了撤销原因,保存到使用数据中
|
||||||
if req.Reason != "" {
|
if req.Reason != "" {
|
||||||
revokeData := map[string]interface{}{
|
revokeData := map[string]interface{}{
|
||||||
"revoked_at": time.Now().Format(time.RFC3339),
|
"revoked_at": time.Now().Format(time.RFC3339),
|
||||||
"revoke_reason": req.Reason,
|
"revoke_reason": req.Reason,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保留原有的使用数据
|
// 保留原有的使用数据
|
||||||
if len(existingLicense.UsageData) > 0 {
|
if len(existingLicense.UsageData) > 0 {
|
||||||
var existingUsageData map[string]interface{}
|
var existingUsageData map[string]interface{}
|
||||||
@@ -268,7 +268,7 @@ func (s *licenseService) RevokeLicense(ctx context.Context, id string, req *mode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
usageDataBytes, err := json.Marshal(revokeData)
|
usageDataBytes, err := json.Marshal(revokeData)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
existingLicense.UsageData = models.JSON(usageDataBytes)
|
existingLicense.UsageData = models.JSON(usageDataBytes)
|
||||||
@@ -284,14 +284,14 @@ func (s *licenseService) RevokeLicense(ctx context.Context, id string, req *mode
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GenerateLicenseFile 生成许可证文件
|
// GenerateLicenseFile 生成许可证文件
|
||||||
func (s *licenseService) GenerateLicenseFile(ctx context.Context, id string) ([]byte, string, error) {
|
func (s *licenseService) GenerateLicenseFile(ctx context.Context, id string) ([]byte, string, string, error) {
|
||||||
lang := pkgcontext.GetLanguageFromContext(ctx)
|
lang := pkgcontext.GetLanguageFromContext(ctx)
|
||||||
s.logger.Infof("[GenerateLicenseFile] 开始生成许可证文件,license_id: %s", id)
|
s.logger.Infof("[GenerateLicenseFile] 开始生成许可证文件,license_id: %s", id)
|
||||||
|
|
||||||
// 业务逻辑:参数验证
|
// 业务逻辑:参数验证
|
||||||
if id == "" {
|
if id == "" {
|
||||||
s.logger.Error("[GenerateLicenseFile] 错误:许可证ID为空")
|
s.logger.Error("[GenerateLicenseFile] 错误:许可证ID为空")
|
||||||
return nil, "", i18n.NewI18nError("900001", lang)
|
return nil, "", "", i18n.NewI18nError("900001", lang)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取许可证信息
|
// 获取许可证信息
|
||||||
@@ -300,9 +300,9 @@ func (s *licenseService) GenerateLicenseFile(ctx context.Context, id string) ([]
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Errorf("[GenerateLicenseFile] 查询许可证失败,license_id: %s, error: %v", id, err)
|
s.logger.Errorf("[GenerateLicenseFile] 查询许可证失败,license_id: %s, error: %v", id, err)
|
||||||
if errors.Is(err, repository.ErrLicenseNotFound) {
|
if errors.Is(err, repository.ErrLicenseNotFound) {
|
||||||
return nil, "", i18n.NewI18nError("300006", lang) // 许可证不存在
|
return nil, "", "", i18n.NewI18nError("300006", lang) // 许可证不存在
|
||||||
}
|
}
|
||||||
return nil, "", i18n.NewI18nError("900004", lang, err.Error())
|
return nil, "", "", i18n.NewI18nError("900004", lang, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
s.logger.Infof("[GenerateLicenseFile] 许可证信息查询成功,license_key: %s, status: %s", license.LicenseKey, license.Status)
|
s.logger.Infof("[GenerateLicenseFile] 许可证信息查询成功,license_key: %s, status: %s", license.LicenseKey, license.Status)
|
||||||
@@ -310,7 +310,7 @@ func (s *licenseService) GenerateLicenseFile(ctx context.Context, id string) ([]
|
|||||||
// 检查许可证状态
|
// 检查许可证状态
|
||||||
if license.Status == "revoked" {
|
if license.Status == "revoked" {
|
||||||
s.logger.Warnf("[GenerateLicenseFile] 许可证已被撤销,license_id: %s", id)
|
s.logger.Warnf("[GenerateLicenseFile] 许可证已被撤销,license_id: %s", id)
|
||||||
return nil, "", i18n.NewI18nError("300007", lang) // 许可证已被撤销
|
return nil, "", "", i18n.NewI18nError("300007", lang) // 许可证已被撤销
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建许可证文件内容
|
// 构建许可证文件内容
|
||||||
@@ -318,10 +318,10 @@ func (s *licenseService) GenerateLicenseFile(ctx context.Context, id string) ([]
|
|||||||
"license_key": license.LicenseKey,
|
"license_key": license.LicenseKey,
|
||||||
"authorization_code_id": license.AuthorizationCodeID,
|
"authorization_code_id": license.AuthorizationCodeID,
|
||||||
"hardware_fingerprint": license.HardwareFingerprint,
|
"hardware_fingerprint": license.HardwareFingerprint,
|
||||||
"status": license.Status,
|
"status": license.Status,
|
||||||
"activated_at": license.ActivatedAt,
|
"activated_at": license.ActivatedAt,
|
||||||
"config_updated_at": license.ConfigUpdatedAt,
|
"config_updated_at": license.ConfigUpdatedAt,
|
||||||
"generated_at": time.Now().Format(time.RFC3339),
|
"generated_at": time.Now().Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
|
|
||||||
// 包含授权码信息
|
// 包含授权码信息
|
||||||
@@ -331,7 +331,7 @@ func (s *licenseService) GenerateLicenseFile(ctx context.Context, id string) ([]
|
|||||||
licenseFileData["end_date"] = license.AuthorizationCode.EndDate
|
licenseFileData["end_date"] = license.AuthorizationCode.EndDate
|
||||||
licenseFileData["deployment_type"] = license.AuthorizationCode.DeploymentType
|
licenseFileData["deployment_type"] = license.AuthorizationCode.DeploymentType
|
||||||
licenseFileData["max_activations"] = license.AuthorizationCode.MaxActivations
|
licenseFileData["max_activations"] = license.AuthorizationCode.MaxActivations
|
||||||
|
|
||||||
// 包含功能配置
|
// 包含功能配置
|
||||||
if len(license.AuthorizationCode.FeatureConfig) > 0 {
|
if len(license.AuthorizationCode.FeatureConfig) > 0 {
|
||||||
var featureConfig map[string]interface{}
|
var featureConfig map[string]interface{}
|
||||||
@@ -339,7 +339,7 @@ func (s *licenseService) GenerateLicenseFile(ctx context.Context, id string) ([]
|
|||||||
licenseFileData["feature_config"] = featureConfig
|
licenseFileData["feature_config"] = featureConfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 包含使用限制
|
// 包含使用限制
|
||||||
if len(license.AuthorizationCode.UsageLimits) > 0 {
|
if len(license.AuthorizationCode.UsageLimits) > 0 {
|
||||||
var usageLimits map[string]interface{}
|
var usageLimits map[string]interface{}
|
||||||
@@ -347,7 +347,7 @@ func (s *licenseService) GenerateLicenseFile(ctx context.Context, id string) ([]
|
|||||||
licenseFileData["usage_limits"] = usageLimits
|
licenseFileData["usage_limits"] = usageLimits
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 包含自定义参数
|
// 包含自定义参数
|
||||||
if len(license.AuthorizationCode.CustomParameters) > 0 {
|
if len(license.AuthorizationCode.CustomParameters) > 0 {
|
||||||
var customParameters map[string]interface{}
|
var customParameters map[string]interface{}
|
||||||
@@ -360,19 +360,19 @@ func (s *licenseService) GenerateLicenseFile(ctx context.Context, id string) ([]
|
|||||||
// 序列化许可证数据
|
// 序列化许可证数据
|
||||||
licenseJSON, err := json.Marshal(licenseFileData)
|
licenseJSON, err := json.Marshal(licenseFileData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", i18n.NewI18nError("300009", lang) // 许可证文件生成失败
|
return nil, "", "", i18n.NewI18nError("300009", lang) // 许可证文件生成失败
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用RSA数字签名
|
// 使用RSA数字签名
|
||||||
encryptedData, err := s.signLicenseFile(licenseJSON)
|
encryptedData, err := s.signLicenseFile(licenseJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", i18n.NewI18nError("300009", lang) // 许可证文件生成失败
|
return nil, "", "", i18n.NewI18nError("300009", lang) // 许可证文件生成失败
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成文件名
|
// 生成文件名
|
||||||
fileName := fmt.Sprintf("license_%s.lic", license.LicenseKey)
|
fileName := fmt.Sprintf("license_%s.lic", license.LicenseKey)
|
||||||
|
|
||||||
return encryptedData, fileName, nil
|
return encryptedData, fileName, license.LicenseKey, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// generateLicenseKey 生成许可证密钥
|
// generateLicenseKey 生成许可证密钥
|
||||||
@@ -489,9 +489,9 @@ func (s *licenseService) ActivateLicense(ctx context.Context, req *models.Activa
|
|||||||
|
|
||||||
// 检查是否已存在相同硬件指纹的许可证
|
// 检查是否已存在相同硬件指纹的许可证
|
||||||
var existingLicense models.License
|
var existingLicense models.License
|
||||||
err = tx.Where("authorization_code_id = ? AND hardware_fingerprint = ?",
|
err = tx.Where("authorization_code_id = ? AND hardware_fingerprint = ?",
|
||||||
authCode.ID, req.HardwareFingerprint).First(&existingLicense).Error
|
authCode.ID, req.HardwareFingerprint).First(&existingLicense).Error
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// 已存在,直接激活
|
// 已存在,直接激活
|
||||||
existingLicense.Status = "active"
|
existingLicense.Status = "active"
|
||||||
@@ -500,7 +500,7 @@ func (s *licenseService) ActivateLicense(ctx context.Context, req *models.Activa
|
|||||||
existingLicense.ActivatedAt = &now
|
existingLicense.ActivatedAt = &now
|
||||||
existingLicense.LastHeartbeat = &now
|
existingLicense.LastHeartbeat = &now
|
||||||
existingLicense.LastOnlineIP = &clientIP
|
existingLicense.LastOnlineIP = &clientIP
|
||||||
|
|
||||||
if err := tx.Save(&existingLicense).Error; err != nil {
|
if err := tx.Save(&existingLicense).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -655,10 +655,10 @@ func (s *licenseService) generateLicenseFileContent(license *models.License, aut
|
|||||||
"license_key": license.LicenseKey,
|
"license_key": license.LicenseKey,
|
||||||
"authorization_code_id": license.AuthorizationCodeID,
|
"authorization_code_id": license.AuthorizationCodeID,
|
||||||
"hardware_fingerprint": license.HardwareFingerprint,
|
"hardware_fingerprint": license.HardwareFingerprint,
|
||||||
"status": license.Status,
|
"status": license.Status,
|
||||||
"activated_at": license.ActivatedAt,
|
"activated_at": license.ActivatedAt,
|
||||||
"config_updated_at": license.ConfigUpdatedAt,
|
"config_updated_at": license.ConfigUpdatedAt,
|
||||||
"generated_at": time.Now().Format(time.RFC3339),
|
"generated_at": time.Now().Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
|
|
||||||
if authCode != nil {
|
if authCode != nil {
|
||||||
@@ -667,7 +667,7 @@ func (s *licenseService) generateLicenseFileContent(license *models.License, aut
|
|||||||
licenseFileData["end_date"] = authCode.EndDate
|
licenseFileData["end_date"] = authCode.EndDate
|
||||||
licenseFileData["deployment_type"] = authCode.DeploymentType
|
licenseFileData["deployment_type"] = authCode.DeploymentType
|
||||||
licenseFileData["max_activations"] = authCode.MaxActivations
|
licenseFileData["max_activations"] = authCode.MaxActivations
|
||||||
|
|
||||||
// 包含功能配置等
|
// 包含功能配置等
|
||||||
if len(authCode.FeatureConfig) > 0 {
|
if len(authCode.FeatureConfig) > 0 {
|
||||||
var featureConfig map[string]interface{}
|
var featureConfig map[string]interface{}
|
||||||
@@ -675,14 +675,14 @@ func (s *licenseService) generateLicenseFileContent(license *models.License, aut
|
|||||||
licenseFileData["feature_config"] = featureConfig
|
licenseFileData["feature_config"] = featureConfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(authCode.UsageLimits) > 0 {
|
if len(authCode.UsageLimits) > 0 {
|
||||||
var usageLimits map[string]interface{}
|
var usageLimits map[string]interface{}
|
||||||
if err := json.Unmarshal(authCode.UsageLimits, &usageLimits); err == nil {
|
if err := json.Unmarshal(authCode.UsageLimits, &usageLimits); err == nil {
|
||||||
licenseFileData["usage_limits"] = usageLimits
|
licenseFileData["usage_limits"] = usageLimits
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(authCode.CustomParameters) > 0 {
|
if len(authCode.CustomParameters) > 0 {
|
||||||
var customParameters map[string]interface{}
|
var customParameters map[string]interface{}
|
||||||
if err := json.Unmarshal(authCode.CustomParameters, &customParameters); err == nil {
|
if err := json.Unmarshal(authCode.CustomParameters, &customParameters); err == nil {
|
||||||
@@ -748,7 +748,7 @@ func (s *licenseService) signLicenseFile(data []byte) ([]byte, error) {
|
|||||||
// 构建签名后的许可证文件结构
|
// 构建签名后的许可证文件结构
|
||||||
licenseWithSignature := map[string]interface{}{
|
licenseWithSignature := map[string]interface{}{
|
||||||
"data": string(data), // 原始数据(JSON字符串)
|
"data": string(data), // 原始数据(JSON字符串)
|
||||||
"signature": signature, // 数字签名
|
"signature": signature, // 数字签名
|
||||||
"algorithm": "RSA-PSS-SHA256",
|
"algorithm": "RSA-PSS-SHA256",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+28
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
// Vue 文件类型检查配置
|
||||||
|
"volar.takeOverMode.enabled": true,
|
||||||
|
"typescript.tsdk": "node_modules/typescript/lib",
|
||||||
|
"typescript.enablePromptUseWorkspaceTsdk": true,
|
||||||
|
|
||||||
|
// TypeScript 检查配置
|
||||||
|
"typescript.preferences.includePackageJsonAutoImports": "on",
|
||||||
|
"typescript.suggest.autoImports": true,
|
||||||
|
|
||||||
|
// 启用实时类型检查
|
||||||
|
"typescript.validate.enable": true,
|
||||||
|
"javascript.validate.enable": true,
|
||||||
|
|
||||||
|
// 显示所有诊断信息(包括未使用的变量)
|
||||||
|
"typescript.preferences.showUnused": true,
|
||||||
|
"javascript.preferences.showUnused": true,
|
||||||
|
|
||||||
|
// Vue 文件检查
|
||||||
|
"volar.codeLens.pugTools": false,
|
||||||
|
"volar.codeLens.scriptSetupTools": true,
|
||||||
|
|
||||||
|
// 文件关联
|
||||||
|
"files.associations": {
|
||||||
|
"*.vue": "vue"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -320,6 +320,15 @@ export function downloadLicenseFile(id: string): Promise<AxiosResponse<Blob>> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载授权文件包(授权码+公钥)
|
||||||
|
*/
|
||||||
|
export function downloadAuthorizationFile(id: string): Promise<AxiosResponse<Blob>> {
|
||||||
|
return Axios.get(`/api/v1/authorization-codes/${id}/download`, {
|
||||||
|
responseType: 'blob'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 创建许可证请求(手动绑定设备)
|
// 创建许可证请求(手动绑定设备)
|
||||||
export interface LicenseDeviceCreateRequest {
|
export interface LicenseDeviceCreateRequest {
|
||||||
authorization_code_id: string
|
authorization_code_id: string
|
||||||
|
|||||||
@@ -128,8 +128,19 @@ const quickOptions = computed(() => [
|
|||||||
|
|
||||||
// 响应式数据
|
// 响应式数据
|
||||||
const { isMobile } = useDevice()
|
const { isMobile } = useDevice()
|
||||||
const selectedQuick = ref('week')
|
const selectedQuick = ref('month')
|
||||||
const dateRange = ref<[string, string]>(['2024-05-13', '2024-05-17']) // 初始值会被handleQuickSelect('week')覆盖
|
|
||||||
|
const getCurrentMonthRange = (): [string, string] => {
|
||||||
|
const today = new Date()
|
||||||
|
const startDate = new Date(today.getFullYear(), today.getMonth(), 1)
|
||||||
|
const endDate = new Date(today.getFullYear(), today.getMonth() + 1, 0)
|
||||||
|
return [
|
||||||
|
startDate.toISOString().split('T')[0],
|
||||||
|
endDate.toISOString().split('T')[0]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateRange = ref<[string, string]>(getCurrentMonthRange())
|
||||||
const chartRef = ref()
|
const chartRef = ref()
|
||||||
const datePickerRef = ref()
|
const datePickerRef = ref()
|
||||||
|
|
||||||
@@ -141,6 +152,11 @@ const chartLoading = ref(false)
|
|||||||
const chartOption = computed(() => {
|
const chartOption = computed(() => {
|
||||||
const dates = trendData.value.map(item => item.date.substring(5)) // 只显示月-日
|
const dates = trendData.value.map(item => item.date.substring(5)) // 只显示月-日
|
||||||
const values = trendData.value.map(item => item.value)
|
const values = trendData.value.map(item => item.value)
|
||||||
|
const rawMax = values.length ? Math.max(...values) : 0
|
||||||
|
const baseMax = Math.max(rawMax, 20)
|
||||||
|
const minTickCount = 4 // 至少展示4个区间
|
||||||
|
const niceInterval = Math.max(5, Math.ceil(baseMax / minTickCount / 5) * 5)
|
||||||
|
const niceMax = Math.ceil(baseMax / niceInterval) * niceInterval
|
||||||
|
|
||||||
return {
|
return {
|
||||||
grid: {
|
grid: {
|
||||||
@@ -169,8 +185,8 @@ const chartOption = computed(() => {
|
|||||||
yAxis: {
|
yAxis: {
|
||||||
type: 'value',
|
type: 'value',
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 20,
|
max: niceMax,
|
||||||
interval: 5,
|
interval: niceInterval,
|
||||||
axisLine: {
|
axisLine: {
|
||||||
show: false
|
show: false
|
||||||
},
|
},
|
||||||
@@ -367,9 +383,9 @@ const updateChartData = () => {
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
console.log('LicenseTrendChart 组件已挂载,开始初始化')
|
console.log('LicenseTrendChart 组件已挂载,开始初始化')
|
||||||
// 初始化时直接调用快捷选择,设置为本周
|
// 初始化时直接调用快捷选择,设置为本月
|
||||||
handleQuickSelect('week')
|
handleQuickSelect('month')
|
||||||
console.log('已调用 handleQuickSelect(week)')
|
console.log('已调用 handleQuickSelect(month)')
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,19 @@
|
|||||||
|
|
||||||
<!-- 操作按钮组 -->
|
<!-- 操作按钮组 -->
|
||||||
<div class="action-buttons">
|
<div class="action-buttons">
|
||||||
|
<!-- 文档 & GitHub 外部链接 -->
|
||||||
|
<template v-for="link in externalLinks" :key="link.key">
|
||||||
|
<el-tooltip :content="t(`navigation.tooltip.${link.key}`)" placement="bottom">
|
||||||
|
<button
|
||||||
|
class="action-btn external-link-btn"
|
||||||
|
type="button"
|
||||||
|
@click="handleExternalLink(link.url)"
|
||||||
|
>
|
||||||
|
<span class="external-link-label">{{ t(`navigation.external.${link.key}`) }}</span>
|
||||||
|
</button>
|
||||||
|
</el-tooltip>
|
||||||
|
</template>
|
||||||
|
|
||||||
<!-- 搜索按钮(暂时禁用) -->
|
<!-- 搜索按钮(暂时禁用) -->
|
||||||
<!--
|
<!--
|
||||||
<el-tooltip :content="t('navigation.tooltip.search')" placement="bottom">
|
<el-tooltip :content="t('navigation.tooltip.search')" placement="bottom">
|
||||||
@@ -178,6 +191,17 @@ const { notificationCount = 24 } = defineProps<Props>()
|
|||||||
// 功能暂未启用,隐藏通知入口
|
// 功能暂未启用,隐藏通知入口
|
||||||
const showNotification = false
|
const showNotification = false
|
||||||
|
|
||||||
|
type ExternalLinkKey = 'docs' | 'github'
|
||||||
|
interface ExternalLink {
|
||||||
|
key: ExternalLinkKey
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const externalLinks: ExternalLink[] = [
|
||||||
|
{ key: 'docs', url: 'https://docs.lm.cedar-v.com/' },
|
||||||
|
{ key: 'github', url: 'https://github.com/cedar-v/license-manager' }
|
||||||
|
]
|
||||||
|
|
||||||
// 定义组件事件
|
// 定义组件事件
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
sidebarToggle: []
|
sidebarToggle: []
|
||||||
@@ -229,6 +253,10 @@ const handleNotificationClick = () => {
|
|||||||
emit('notificationClick')
|
emit('notificationClick')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleExternalLink = (url: string) => {
|
||||||
|
window.open(url, '_blank', 'noopener,noreferrer')
|
||||||
|
}
|
||||||
|
|
||||||
// 语言切换
|
// 语言切换
|
||||||
const languageOptions: Array<{ code: SupportedLocale; label: string }> = [
|
const languageOptions: Array<{ code: SupportedLocale; label: string }> = [
|
||||||
{ code: 'en', label: 'English' },
|
{ code: 'en', label: 'English' },
|
||||||
@@ -579,6 +607,20 @@ const handleUserCommand = async (command: string) => {
|
|||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.external-link-btn {
|
||||||
|
min-width: 72px;
|
||||||
|
padding: 0 16px;
|
||||||
|
width: auto;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.external-link-label {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--app-text-primary);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
.action-btn:hover {
|
.action-btn:hover {
|
||||||
background: var(--el-color-primary-light-9);
|
background: var(--el-color-primary-light-9);
|
||||||
}
|
}
|
||||||
@@ -810,6 +852,10 @@ const handleUserCommand = async (command: string) => {
|
|||||||
background: rgba(255, 255, 255, 0.08) !important;
|
background: rgba(255, 255, 255, 0.08) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[data-theme="dark"] .external-link-label {
|
||||||
|
color: #f9fafb !important;
|
||||||
|
}
|
||||||
|
|
||||||
[data-theme="dark"] .action-btn:hover {
|
[data-theme="dark"] .action-btn:hover {
|
||||||
background: rgba(16, 185, 129, 0.15) !important;
|
background: rgba(16, 185, 129, 0.15) !important;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,13 @@
|
|||||||
"search": "Search",
|
"search": "Search",
|
||||||
"notification": "Notifications",
|
"notification": "Notifications",
|
||||||
"language": "Switch Language",
|
"language": "Switch Language",
|
||||||
"theme": "Switch Theme"
|
"theme": "Switch Theme",
|
||||||
|
"docs": "Open Documentation",
|
||||||
|
"github": "Open GitHub"
|
||||||
|
},
|
||||||
|
"external": {
|
||||||
|
"docs": "Docs",
|
||||||
|
"github": "GitHub"
|
||||||
},
|
},
|
||||||
"breadcrumb": {
|
"breadcrumb": {
|
||||||
"dashboard": "Dashboard",
|
"dashboard": "Dashboard",
|
||||||
@@ -391,7 +397,7 @@
|
|||||||
"updateLicense": "Update License",
|
"updateLicense": "Update License",
|
||||||
"renewLicense": "Renew License",
|
"renewLicense": "Renew License",
|
||||||
"revokeLicense": "Revoke License",
|
"revokeLicense": "Revoke License",
|
||||||
"downloadCertificate": "Download Deployment Package"
|
"downloadCertificate": "Download Authorization File"
|
||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"copySuccess": "License code copied to clipboard",
|
"copySuccess": "License code copied to clipboard",
|
||||||
@@ -400,7 +406,8 @@
|
|||||||
"updateComingSoon": "Update license feature is under development...",
|
"updateComingSoon": "Update license feature is under development...",
|
||||||
"renewComingSoon": "Renew license feature is under development...",
|
"renewComingSoon": "Renew license feature is under development...",
|
||||||
"revokeComingSoon": "Revoke license feature is under development...",
|
"revokeComingSoon": "Revoke license feature is under development...",
|
||||||
"downloadComingSoon": "Download certificate feature is under development...",
|
"downloadSuccess": "Authorization file download started",
|
||||||
|
"downloadError": "Failed to download authorization file, please try again later",
|
||||||
"revokeConfirm": "Are you sure you want to revoke this license? This action cannot be undone!",
|
"revokeConfirm": "Are you sure you want to revoke this license? This action cannot be undone!",
|
||||||
"revokeTitle": "Warning",
|
"revokeTitle": "Warning",
|
||||||
"revokeConfirmButton": "Confirm Revoke",
|
"revokeConfirmButton": "Confirm Revoke",
|
||||||
|
|||||||
@@ -64,7 +64,13 @@
|
|||||||
"search": "検索",
|
"search": "検索",
|
||||||
"notification": "通知",
|
"notification": "通知",
|
||||||
"language": "言語切り替え",
|
"language": "言語切り替え",
|
||||||
"theme": "テーマ切り替え"
|
"theme": "テーマ切り替え",
|
||||||
|
"docs": "ドキュメントを開く",
|
||||||
|
"github": "GitHub を開く"
|
||||||
|
},
|
||||||
|
"external": {
|
||||||
|
"docs": "ドキュメント",
|
||||||
|
"github": "GitHub"
|
||||||
},
|
},
|
||||||
"breadcrumb": {
|
"breadcrumb": {
|
||||||
"dashboard": "ダッシュボード",
|
"dashboard": "ダッシュボード",
|
||||||
@@ -391,7 +397,7 @@
|
|||||||
"updateLicense": "ライセンス更新",
|
"updateLicense": "ライセンス更新",
|
||||||
"renewLicense": "ライセンス延長",
|
"renewLicense": "ライセンス延長",
|
||||||
"revokeLicense": "ライセンス取り消し",
|
"revokeLicense": "ライセンス取り消し",
|
||||||
"downloadCertificate": "デプロイメントパッケージをダウンロード"
|
"downloadCertificate": "認証ファイルをダウンロード"
|
||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"copySuccess": "ライセンスコードがクリップボードにコピーされました",
|
"copySuccess": "ライセンスコードがクリップボードにコピーされました",
|
||||||
@@ -400,7 +406,8 @@
|
|||||||
"updateComingSoon": "ライセンス更新機能は開発中です...",
|
"updateComingSoon": "ライセンス更新機能は開発中です...",
|
||||||
"renewComingSoon": "ライセンス延長機能は開発中です...",
|
"renewComingSoon": "ライセンス延長機能は開発中です...",
|
||||||
"revokeComingSoon": "ライセンス取り消し機能は開発中です...",
|
"revokeComingSoon": "ライセンス取り消し機能は開発中です...",
|
||||||
"downloadComingSoon": "証明書ダウンロード機能は開発中です...",
|
"downloadSuccess": "認証ファイルのダウンロードを開始しました",
|
||||||
|
"downloadError": "認証ファイルのダウンロードに失敗しました。後でもう一度お試しください",
|
||||||
"revokeConfirm": "このライセンスを取り消してもよろしいですか?この操作は元に戻せません!",
|
"revokeConfirm": "このライセンスを取り消してもよろしいですか?この操作は元に戻せません!",
|
||||||
"revokeTitle": "警告",
|
"revokeTitle": "警告",
|
||||||
"revokeConfirmButton": "取り消し確認",
|
"revokeConfirmButton": "取り消し確認",
|
||||||
|
|||||||
@@ -64,7 +64,13 @@
|
|||||||
"search": "搜索",
|
"search": "搜索",
|
||||||
"notification": "消息通知",
|
"notification": "消息通知",
|
||||||
"language": "切换语言",
|
"language": "切换语言",
|
||||||
"theme": "切换主题"
|
"theme": "切换主题",
|
||||||
|
"docs": "查看文档",
|
||||||
|
"github": "打开 GitHub"
|
||||||
|
},
|
||||||
|
"external": {
|
||||||
|
"docs": "文档",
|
||||||
|
"github": "GitHub"
|
||||||
},
|
},
|
||||||
"breadcrumb": {
|
"breadcrumb": {
|
||||||
"dashboard": "仪表盘",
|
"dashboard": "仪表盘",
|
||||||
@@ -391,7 +397,7 @@
|
|||||||
"updateLicense": "变更授权",
|
"updateLicense": "变更授权",
|
||||||
"renewLicense": "延期授权",
|
"renewLicense": "延期授权",
|
||||||
"revokeLicense": "撤销许可证",
|
"revokeLicense": "撤销许可证",
|
||||||
"downloadCertificate": "下载部署包"
|
"downloadCertificate": "授权文件下载"
|
||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
"copySuccess": "授权码已复制到剪贴板",
|
"copySuccess": "授权码已复制到剪贴板",
|
||||||
@@ -400,7 +406,8 @@
|
|||||||
"updateComingSoon": "变更授权功能开发中...",
|
"updateComingSoon": "变更授权功能开发中...",
|
||||||
"renewComingSoon": "延期授权功能开发中...",
|
"renewComingSoon": "延期授权功能开发中...",
|
||||||
"revokeComingSoon": "撤销许可证功能开发中...",
|
"revokeComingSoon": "撤销许可证功能开发中...",
|
||||||
"downloadComingSoon": "下载凭单功能开发中...",
|
"downloadSuccess": "授权文件已开始下载",
|
||||||
|
"downloadError": "下载授权文件失败,请稍后重试",
|
||||||
"revokeConfirm": "确定要撤销此许可证吗?此操作不可逆!",
|
"revokeConfirm": "确定要撤销此许可证吗?此操作不可逆!",
|
||||||
"revokeTitle": "警告",
|
"revokeTitle": "警告",
|
||||||
"revokeConfirmButton": "确定撤销",
|
"revokeConfirmButton": "确定撤销",
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ const handleDownloadLicense = async (device: LicenseDevice) => {
|
|||||||
response.headers?.['content-disposition'] || response.headers?.['Content-Disposition']
|
response.headers?.['content-disposition'] || response.headers?.['Content-Disposition']
|
||||||
const filename =
|
const filename =
|
||||||
extractFilename(disposition) ||
|
extractFilename(disposition) ||
|
||||||
`${device.customer_name || 'license'}-${device.id}.lic`
|
`${device.customer_name || 'license'}-${device.id}.zip`
|
||||||
|
|
||||||
const blobUrl = window.URL.createObjectURL(response.data)
|
const blobUrl = window.URL.createObjectURL(response.data)
|
||||||
const link = document.createElement('a')
|
const link = document.createElement('a')
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ import { ref, onMounted } from 'vue'
|
|||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { getLicenseDetail, type AuthorizationCode } from '@/api/license'
|
import { getLicenseDetail, downloadAuthorizationFile, type AuthorizationCode } from '@/api/license'
|
||||||
import LicenseTabIcon from '@/components/common/icons/LicenseTabIcon.vue'
|
import LicenseTabIcon from '@/components/common/icons/LicenseTabIcon.vue'
|
||||||
import BasicInfo from './components/BasicInfo.vue'
|
import BasicInfo from './components/BasicInfo.vue'
|
||||||
import AuthorizationInfo from './components/AuthorizationInfo.vue'
|
import AuthorizationInfo from './components/AuthorizationInfo.vue'
|
||||||
@@ -142,8 +142,62 @@ const handleRenewLicense = () => {
|
|||||||
ElMessage.info(t('pages.licenses.detail.messages.renewComingSoon'))
|
ElMessage.info(t('pages.licenses.detail.messages.renewComingSoon'))
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleDownloadCertificate = () => {
|
const getFileNameFromDisposition = (disposition?: string | null) => {
|
||||||
ElMessage.info(t('pages.licenses.detail.messages.downloadComingSoon'))
|
const defaultName = 'authorization_package.zip'
|
||||||
|
if (!disposition) return defaultName
|
||||||
|
|
||||||
|
const utf8Match = disposition.match(/filename\*=UTF-8''([^;]+)/i)
|
||||||
|
if (utf8Match?.[1]) {
|
||||||
|
try {
|
||||||
|
return decodeURIComponent(utf8Match[1])
|
||||||
|
} catch {
|
||||||
|
return utf8Match[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const asciiMatch = disposition.match(/filename="?([^";]+)"?/i)
|
||||||
|
if (asciiMatch?.[1]) {
|
||||||
|
return asciiMatch[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultName
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDownloadCertificate = async () => {
|
||||||
|
if (!licenseData.value?.id) {
|
||||||
|
ElMessage.error(t('pages.licenses.detail.messages.missingId'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await downloadAuthorizationFile(licenseData.value.id)
|
||||||
|
const fileName = getFileNameFromDisposition(response.headers['content-disposition'])
|
||||||
|
const blob = new Blob([response.data], { type: 'application/zip' })
|
||||||
|
const url = window.URL.createObjectURL(blob)
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.href = url
|
||||||
|
link.download = fileName
|
||||||
|
document.body.appendChild(link)
|
||||||
|
link.click()
|
||||||
|
document.body.removeChild(link)
|
||||||
|
window.URL.revokeObjectURL(url)
|
||||||
|
ElMessage.success(t('pages.licenses.detail.messages.downloadSuccess'))
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('下载授权文件失败:', error)
|
||||||
|
let message = t('pages.licenses.detail.messages.downloadError')
|
||||||
|
if (error?.response?.data instanceof Blob) {
|
||||||
|
try {
|
||||||
|
const text = await error.response.data.text()
|
||||||
|
const parsed = JSON.parse(text)
|
||||||
|
if (parsed?.message) {
|
||||||
|
message = parsed.message
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore parse errors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ElMessage.error(message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadLicenseData = async () => {
|
const loadLicenseData = async () => {
|
||||||
|
|||||||
Reference in new issue
Block a user