logo
18
3
WeChat Login

feat: 新增倒计时功能#47

Merged
created 1 weeks ago
main
feature/huimin_0407
Edit
OverviewCommits
4
Files changed
5
AttachmentsTAPD

以下内容由 AI 生成

新增侧边栏 CNB 面板及回收倒计时功能,优化文件树样式并扩展环境变量

  1. README 补充 CNB 面板功能说明,含倒计时、环境管理等模块
  2. 常量文件新增构建开始时间环境变量 CNB_BUILD_START_TIME
  3. 侧边栏引入新变量,实现倒计时渲染与文件树缩进优化
Clipboard_Screenshot_1775704250.png
NPC
reviewed
src/sidebar/sidebar.js

问题: 定时器内存泄漏风险handleCountdown 函数中使用 setInterval 创建定时器,但没有保存返回值,也没有提供清理机制。当侧边栏被反复重新加载时,可能会累积多个定时器,导致内存泄漏和性能问题。
建议保存定时器 ID 并在适当时机清理:

function handleCountdown() {
    // ... 现有代码 ...
    
    let timerId = null;
    
    function update() {
        // ... 现有逻辑 ...
    }
    
    update();
    timerId = setInterval(update, 1000);
    
    // 返回清理函数,供外部调用
    return function cleanup() {
        if (timerId) {
            clearInterval(timerId);
            timerId = null;
        }
    };
}

或者在 window.onunload 时清理定时器。

src/sidebar/sidebar.js

问题: 日期解析异常处理缺失new Date(buildStartTime).getTime() 可能返回 NaN,当 buildStartTime 为无效日期格式时,后续所有时间计算都会失败,导致显示 NaN:NaN:NaN 等异常结果。
建议增加日期有效性校验:

const startMs = new Date(buildStartTime).getTime();

// 验证日期是否有效
if (isNaN(startMs)) {
    section.style.display = 'none';
    console.warn('Invalid buildStartTime format:', buildStartTime);
    return;
}

const endMs = startMs + maxRunTime;
src/sidebar/sidebar.js

问题: 边界值处理不够健壮

  • Number() 对非数字字符串返回 NaN,当前仅检查 !maxRunTime 无法正确处理 NaN
  • maxRunTime 若为负数或过小的正数,会导致倒计时逻辑异常
    建议增强数值校验:
const maxRunTime = Number(section.getAttribute('data-max-run-time'));
const buildStartTime = section.getAttribute('data-build-start-time');

// 更严格的校验
if (!maxRunTime || isNaN(maxRunTime) || maxRunTime <= 0 || !buildStartTime) {
    section.style.display = 'none';
    return;
}
cnb-uld-1jlo3j25lis using the squash method to merge into9fb8900c
feat: 新增倒计时功能

Successfully merged and closed

branch can be safely deleted
Reviewer
(folger)
(晶晶)
(哪嘟通临时工 )
Assignee
None yet
Label
None yet
Participant