vdi/web-fe/mock/images.ts

92 lines
2.7 KiB
TypeScript

export default {
'POST /api/nex/v1/queryimagesList': (req: any, res: any) => {
const { page_size, page_num } = req.body;
const data = [];
function getRandomFormat() {
const random = Math.random(); // 生成 0 ~ 1 的随机数
if (random < 0.33) {
return 1;
} else if (random < 0.66) {
return 2;
} else {
return 3;
}
}
for (let i = 1; i <= page_size; i++) {
data.push({
id: i,
image_name: `Win版 PR 2024 【支持win10、win11】.zip${
(page_num - 1) * page_size + i
}`,
image_type: getRandomFormat(),
bt_path: `/serve/logs`,
image_version: '1.0.0',
os_version: 'Ubuntu 20.04',
image_status: Math.random() > 0.5 ? 1 : 2,
storage_path: '/mock/images',
create_time: +new Date(),
});
}
const result = {
code: '200',
message: '操作成功',
data: {
total: 520,
page_num: page_num,
page_size: page_size,
data: data,
},
};
setTimeout(() => {
res.send(result);
}, 500);
},
'POST /api/v1/images/file/chunk/upload': (req: any, res: any) => {
// 打印所有接收到的字段
console.log('=== 分片上传信息 ===');
console.log('文件ID:', req.body.file_id);
console.log('文件名:', req.body.file_name);
console.log('文件大小:', req.body.file_size);
console.log('分片索引:', req.body.shard_index);
console.log('分片总数:', req.body.shard_total);
console.log('分片大小:', req.body.chunk_size);
console.log('分片MD5:', req.body.chunk_md5);
// 如果有文件上传,打印文件信息
if (req.files && req.files.chunk) {
console.log('上传的分片文件:', req.files.chunk);
}
// 模拟上传进度
const shardIndex = parseInt(req.body.shard_index);
const shardTotal = parseInt(req.body.shard_total);
console.log(`分片上传进度: ${shardIndex}/${shardTotal}`);
// 修改判断逻辑:当分片索引等于分片总数时,表示上传完成
if (shardIndex === shardTotal) {
console.log('文件上传完成!');
res.send({
uploadedChunks: shardIndex,
success: true,
totalChunks: shardTotal,
message: '分片上传成功',
status: 'completed',
});
} else {
// 模拟上传中
const progress = Math.round((shardIndex / shardTotal) * 100);
console.log(`上传进度: ${progress}%`);
res.send({
uploadedChunks: shardIndex,
success: true,
totalChunks: shardTotal,
message: '分片上传成功',
status: 'uploading',
});
}
},
};