1
This commit is contained in:
@@ -155,151 +155,6 @@ module.exports = {
|
|||||||
return ctx.success(version);
|
return ctx.success(version);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /admin_api/version/create:
|
|
||||||
* post:
|
|
||||||
* summary: 创建版本
|
|
||||||
* description: 创建新版本信息
|
|
||||||
* tags: [后台-版本管理]
|
|
||||||
* requestBody:
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* required:
|
|
||||||
* - version
|
|
||||||
* - platform
|
|
||||||
* - arch
|
|
||||||
* - download_url
|
|
||||||
* - file_path
|
|
||||||
* properties:
|
|
||||||
* version:
|
|
||||||
* type: string
|
|
||||||
* description: 版本号(x.y.z 格式)
|
|
||||||
* platform:
|
|
||||||
* type: string
|
|
||||||
* description: 平台类型
|
|
||||||
* arch:
|
|
||||||
* type: string
|
|
||||||
* description: 架构类型
|
|
||||||
* download_url:
|
|
||||||
* type: string
|
|
||||||
* description: 下载地址
|
|
||||||
* file_path:
|
|
||||||
* type: string
|
|
||||||
* description: 服务器文件路径
|
|
||||||
* file_size:
|
|
||||||
* type: integer
|
|
||||||
* description: 文件大小(字节)
|
|
||||||
* file_hash:
|
|
||||||
* type: string
|
|
||||||
* description: SHA256 哈希值
|
|
||||||
* release_notes:
|
|
||||||
* type: string
|
|
||||||
* description: 更新日志
|
|
||||||
* force_update:
|
|
||||||
* type: integer
|
|
||||||
* description: 是否强制更新(1:是 0:否)
|
|
||||||
* status:
|
|
||||||
* type: integer
|
|
||||||
* description: 状态(1:启用 0:禁用)
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: 创建成功
|
|
||||||
*/
|
|
||||||
'POST /version/create': async (ctx) => {
|
|
||||||
const models = Framework.getModels();
|
|
||||||
const { version_info } = models;
|
|
||||||
const body = ctx.getBody();
|
|
||||||
|
|
||||||
// 参数验证
|
|
||||||
if (!body.version) {
|
|
||||||
return ctx.fail('版本号不能为空');
|
|
||||||
}
|
|
||||||
if (!body.platform) {
|
|
||||||
return ctx.fail('平台类型不能为空');
|
|
||||||
}
|
|
||||||
if (!body.arch) {
|
|
||||||
return ctx.fail('架构类型不能为空');
|
|
||||||
}
|
|
||||||
if (!body.download_url) {
|
|
||||||
return ctx.fail('下载地址不能为空');
|
|
||||||
}
|
|
||||||
if (!body.file_path) {
|
|
||||||
return ctx.fail('文件路径不能为空');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证版本号格式
|
|
||||||
if (!version_service.is_valid_version(body.version)) {
|
|
||||||
return ctx.fail('版本号格式错误,应为 x.y.z 格式');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证平台类型
|
|
||||||
if (!version_service.is_valid_platform(body.platform)) {
|
|
||||||
return ctx.fail('平台类型错误,应为 win32/darwin/linux');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证架构类型
|
|
||||||
if (!version_service.is_valid_arch(body.arch)) {
|
|
||||||
return ctx.fail('架构类型错误,应为 x64/ia32/arm64');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查版本是否已存在
|
|
||||||
const existing = await version_info.findOne({
|
|
||||||
where: {
|
|
||||||
version: body.version,
|
|
||||||
platform: body.platform,
|
|
||||||
arch: body.arch
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existing) {
|
|
||||||
return ctx.fail('该版本已存在');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果提供了文件路径,计算文件大小和哈希
|
|
||||||
if (body.file_path) {
|
|
||||||
try {
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const full_path = path.resolve(body.file_path);
|
|
||||||
|
|
||||||
if (fs.existsSync(full_path)) {
|
|
||||||
// 计算文件大小
|
|
||||||
if (!body.file_size) {
|
|
||||||
const stats = fs.statSync(full_path);
|
|
||||||
body.file_size = stats.size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算文件哈希
|
|
||||||
if (!body.file_hash) {
|
|
||||||
body.file_hash = await version_service.calculate_file_hash(full_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('计算文件信息失败:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建版本
|
|
||||||
const version = await version_info.create({
|
|
||||||
version: body.version,
|
|
||||||
platform: body.platform,
|
|
||||||
arch: body.arch,
|
|
||||||
download_url: body.download_url,
|
|
||||||
file_path: body.file_path,
|
|
||||||
file_size: body.file_size || 0,
|
|
||||||
file_hash: body.file_hash || '',
|
|
||||||
release_notes: body.release_notes || '',
|
|
||||||
force_update: body.force_update || 0,
|
|
||||||
status: body.status !== undefined ? body.status : 1
|
|
||||||
});
|
|
||||||
|
|
||||||
return ctx.success(version, '版本创建成功');
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
* /admin_api/version/update:
|
* /admin_api/version/update:
|
||||||
|
|||||||
@@ -266,91 +266,88 @@ module.exports = {
|
|||||||
* description: 参数错误
|
* description: 参数错误
|
||||||
*/
|
*/
|
||||||
'POST /version/create': async (ctx) => {
|
'POST /version/create': async (ctx) => {
|
||||||
try {
|
|
||||||
const models = Framework.getModels();
|
|
||||||
const { version_info } = models;
|
|
||||||
const body = ctx.getBody();
|
|
||||||
|
|
||||||
// 参数验证
|
const models = Framework.getModels();
|
||||||
if (!body.version) {
|
const { version_info } = models;
|
||||||
return ctx.fail('版本号不能为空', 400);
|
const body = ctx.getBody();
|
||||||
}
|
|
||||||
if (!body.platform) {
|
|
||||||
return ctx.fail('平台类型不能为空', 400);
|
|
||||||
}
|
|
||||||
if (!body.arch) {
|
|
||||||
return ctx.fail('架构类型不能为空', 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证版本号格式
|
// 参数验证
|
||||||
if (!version_service.is_valid_version(body.version)) {
|
if (!body.version) {
|
||||||
return ctx.fail('版本号格式错误,应为 x.y.z 格式', 400);
|
return ctx.fail('版本号不能为空', 400);
|
||||||
}
|
}
|
||||||
|
if (!body.platform) {
|
||||||
|
return ctx.fail('平台类型不能为空', 400);
|
||||||
|
}
|
||||||
|
if (!body.arch) {
|
||||||
|
return ctx.fail('架构类型不能为空', 400);
|
||||||
|
}
|
||||||
|
|
||||||
// 验证平台类型
|
// 验证版本号格式
|
||||||
if (!version_service.is_valid_platform(body.platform)) {
|
if (!version_service.is_valid_version(body.version)) {
|
||||||
return ctx.fail('平台类型错误,应为 win32/darwin/linux', 400);
|
return ctx.fail('版本号格式错误,应为 x.y.z 格式', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证架构类型
|
// 验证平台类型
|
||||||
if (!version_service.is_valid_arch(body.arch)) {
|
if (!version_service.is_valid_platform(body.platform)) {
|
||||||
return ctx.fail('架构类型错误,应为 x64/ia32/arm64', 400);
|
return ctx.fail('平台类型错误,应为 win32/darwin/linux', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查版本是否已存在
|
// 验证架构类型
|
||||||
const existing = await version_info.findOne({
|
if (!version_service.is_valid_arch(body.arch)) {
|
||||||
where: {
|
return ctx.fail('架构类型错误,应为 x64/ia32/arm64', 400);
|
||||||
version: body.version,
|
}
|
||||||
platform: body.platform,
|
|
||||||
arch: body.arch
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existing) {
|
// 检查版本是否已存在
|
||||||
return ctx.fail('该版本已存在', 400);
|
const existing = await version_info.findOne({
|
||||||
}
|
where: {
|
||||||
|
|
||||||
// 如果提供了文件路径,计算文件大小和哈希
|
|
||||||
if (body.file_path) {
|
|
||||||
try {
|
|
||||||
const full_path = path.resolve(body.file_path);
|
|
||||||
|
|
||||||
if (fs.existsSync(full_path)) {
|
|
||||||
// 计算文件大小
|
|
||||||
if (!body.file_size) {
|
|
||||||
const stats = fs.statSync(full_path);
|
|
||||||
body.file_size = stats.size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算文件哈希
|
|
||||||
if (!body.file_hash) {
|
|
||||||
body.file_hash = await version_service.calculate_file_hash(full_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('计算文件信息失败:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建版本
|
|
||||||
const version = await version_info.create({
|
|
||||||
version: body.version,
|
version: body.version,
|
||||||
platform: body.platform,
|
platform: body.platform,
|
||||||
arch: body.arch,
|
arch: body.arch
|
||||||
download_url: body.download_url || '',
|
}
|
||||||
file_path: body.file_path || '',
|
});
|
||||||
file_size: body.file_size || 0,
|
|
||||||
file_hash: body.file_hash || '',
|
|
||||||
release_notes: body.release_notes || '',
|
|
||||||
force_update: body.force_update || 0,
|
|
||||||
status: body.status !== undefined ? body.status : 1
|
|
||||||
});
|
|
||||||
|
|
||||||
return ctx.success(version, '版本创建成功');
|
if (existing) {
|
||||||
} catch (error) {
|
return ctx.fail('该版本已存在', 400);
|
||||||
console.error('创建版本错误:', error);
|
|
||||||
return ctx.fail('服务器错误', 500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果提供了文件路径,计算文件大小和哈希
|
||||||
|
if (body.file_path) {
|
||||||
|
try {
|
||||||
|
const full_path = path.resolve(body.file_path);
|
||||||
|
|
||||||
|
if (fs.existsSync(full_path)) {
|
||||||
|
// 计算文件大小
|
||||||
|
if (!body.file_size) {
|
||||||
|
const stats = fs.statSync(full_path);
|
||||||
|
body.file_size = stats.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算文件哈希
|
||||||
|
if (!body.file_hash) {
|
||||||
|
body.file_hash = await version_service.calculate_file_hash(full_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('计算文件信息失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建版本
|
||||||
|
const version = await version_info.create({
|
||||||
|
version: body.version,
|
||||||
|
platform: body.platform,
|
||||||
|
arch: body.arch,
|
||||||
|
download_url: body.download_url || '',
|
||||||
|
file_path: body.file_path || '',
|
||||||
|
file_size: body.file_size || 0,
|
||||||
|
file_hash: body.file_hash || '',
|
||||||
|
release_notes: body.release_notes || '',
|
||||||
|
force_update: body.force_update || 0,
|
||||||
|
status: body.status !== undefined ? body.status : 1
|
||||||
|
});
|
||||||
|
|
||||||
|
return ctx.success(version, '版本创建成功');
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user