Files
work-hours-tracker/server/worker.js
T
OpenClaw Agent 2329955e32 baseline: 薪酬逻辑收口到 shared/payroll.js 后的当前全量状态
这是第一个包含完整工作区的提交,也是后续「拆 SFC / 上 Vite」的回滚基线。

此前的提交均为 index.html 单文件历史快照,由 .bak 文件重建。

当前状态(提交前已实测):
- index.html 内联薪酬算法已删除,改调 WHTPayroll
- shared/payroll.js 为唯一薪酬实现,浏览器与 Node 共用
- 对外接口未变:aggregateMonth / isCutEdge / payDayKind 等保留同名薄包装

未入库内容见 .gitignore:依赖、Chrome 验证 profile、验证截图、
运行时 sqlite 数据与日志、时间戳备份、.trash。
2026-09-05 14:35:00 +08:00

39 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Cloudflare Workers 入口
//
// 与 node-server.js 是同一套 core/api.js,只是换了存储适配器(D1)与静态资源方式。
// 部署前:
// 1. wrangler d1 create work-hours # 拿到 database_id 填进 wrangler.toml
// 2. npm run cf:migrate # 建表
// 3. npm run cf:deploy
//
// 静态资源走 Workers Assets(wrangler.toml 里的 [assets]),
// 所以这里只处理 /api/*,其余交回 env.ASSETS。
import { handleApi } from './core/api.js';
import { D1Store } from './adapters/d1.js';
export default {
async fetch(request, env) {
const url = new URL(request.url);
if (url.pathname.startsWith('/api/')) {
if (!env.DB) {
return new Response(
JSON.stringify({ ok: false, error: 'D1 未绑定:请在 wrangler.toml 配置 [[d1_databases]] binding = "DB"' }),
{ status: 500, headers: { 'content-type': 'application/json; charset=utf-8' } }
);
}
return handleApi(request, new D1Store(env.DB), {
allowRegister: env.ALLOW_REGISTER === '1'
});
}
// 静态资源:绑定了 Assets 就交给它,否则给个明确提示而不是 404 让人猜
if (env.ASSETS) return env.ASSETS.fetch(request);
return new Response('静态资源未绑定(需在 wrangler.toml 配置 [assets])', {
status: 404,
headers: { 'content-type': 'text/plain; charset=utf-8' }
});
}
};