**资料文件全链**(用户:审核资料这一步要真产出 word/excel/md/html,前端能渲、点资料名能开)
接手时这一步一个文件都产不出来 —— S3 剧本白纸黑字写着「file_ref 本 MVP 阶段可留空」。
文件是台账那一行的投影,不另存一份:
· 声明 `file:{titleColumn,bodyColumn,formatColumn}`,它同时是授权面(没声明就点不开)
· 现造真字节 —— docx/xlsx 是自己打的 OOXML 包(zip-write:store+CRC32,零依赖)
· 读回来渲 —— 解的就是造出来那份字节,渲得出来才证明文件是真的
· 件上 `data-file-of` → 工作区二级界面(Word 纸面/Excel 网格/渲好的 md/沙箱 html)+ 下载原件
放行落地前把每一份冻进 `sys.task_asset_file`(迁移 0029):归档件点开的必须是签字那一刻
那一份,而资料落在主数据上、试跑单不落正式表 —— 不存这一份,收工后一个都点不开。
工作成果里「产出的资料」自成一摞。Markdown 富文本渲染顺带销账(仍零依赖)。
**Harness**
· 画面按「这一拍办完之后」在办的那一步挑 —— 从前拿拍首的局面决定拍尾的事:
收掉 S4、发出 S5 的卡,而屏上还摆着 S4 的只读件,人无处可填(墙要配路第四次现形)
· 验收「重做」真能退回重做,且打回后台账没动就不许再提交(软硬两段,不锁死单子)
· 立监听的授权面是清单声明;发卡的授权面是调人预算,不是计划项
· 读工具同参重调有兜底;空转写身后还有行动就不废串;finish 的 doneWhen 按写完后的草稿算
**界面**
· 翻件与翻页各归各位(从前二选一,多卡多页时页翻不动);没得翻写「—」不写 0/0
· 工作成果详情能翻份;表宽超出能横滑(E04/I01 抄版式时把 overflow-x 抄丢了)
· 查看面灰底滚过一屏变白 —— 两条独立的路都治了(沙箱内不同色 / 弹性子项不长个)
· 测试台「取不到」不再当成「还活着」
**活动**
E04 关系覆盖、I01 品牌内容各自补到验收线:判据全读基座数、判据指向的东西摆上卡面、
样例满载且名字 ≤14 字;提交前要裁的判据搬进说明书(模型会压拍,压过之后只有说明书还在)。
验收:e2e i01 4/4、e04 3/3 全部 released,资料在办中渲得出、放行后存了档点得开;
门禁 typecheck/lint/depcruise/1628 测全绿。
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EEJX8Z7CHejvwmDQyPQuBX
102 lines
3.8 KiB
TypeScript
102 lines
3.8 KiB
TypeScript
/**
|
|
* 最小 ZIP 打包器 —— docx / xlsx 就是 ZIP 包着几份 XML,写它才写得出真文件。
|
|
*
|
|
* 只做 **store(不压缩,method 0)**:合法的 ZIP,Word / Excel / macOS 归档工具都认。
|
|
* 为什么不压:压缩要 deflate + 一套长度对账,而这些 XML 至多几十 KB ——
|
|
* 省下来的那几 KB 换一处能错的地方,不划算。将来真要压,把 `method` 与数据段一起换即可。
|
|
*
|
|
* 读的那一侧在 `upload-extract.ts`(`readZip`),两边合起来能自证:
|
|
* 造出来的包读得回来,读回来的内容与进去的一模一样。
|
|
*/
|
|
|
|
/** CRC-32(IEEE 多项式 0xEDB88320)—— ZIP 每条目都要校验和,写错了解压工具会报损坏 */
|
|
const CRC_TABLE = (() => {
|
|
const table = new Uint32Array(256);
|
|
for (let i = 0; i < 256; i += 1) {
|
|
let c = i;
|
|
for (let k = 0; k < 8; k += 1) c = (c & 1) === 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
table[i] = c >>> 0;
|
|
}
|
|
return table;
|
|
})();
|
|
|
|
export function crc32Of(bytes: Uint8Array): number {
|
|
let c = 0xffffffff;
|
|
for (const b of bytes) c = (CRC_TABLE[(c ^ b) & 0xff] ?? 0) ^ (c >>> 8);
|
|
return (c ^ 0xffffffff) >>> 0;
|
|
}
|
|
|
|
type Entry = readonly [name: string, bytes: Uint8Array];
|
|
|
|
/**
|
|
* 打包。条目顺序即包内顺序 —— `[Content_Types].xml` 习惯放第一条(不少读取器认这个)。
|
|
*
|
|
* 时间戳一律写 1980-01-01(DOS 时间的下限):同样的入参出同样的字节,
|
|
* 这样「文件变没变」就是内容的事,不掺一个每次都不同的时间 —— 也让测试断得住。
|
|
*/
|
|
export function zipStore(entries: readonly Entry[]): Uint8Array {
|
|
const enc = new TextEncoder();
|
|
const locals: Uint8Array[] = [];
|
|
const centrals: Uint8Array[] = [];
|
|
let offset = 0;
|
|
|
|
for (const [name, data] of entries) {
|
|
const nameBytes = enc.encode(name);
|
|
const crc = crc32Of(data);
|
|
|
|
const local = new Uint8Array(30 + nameBytes.length + data.length);
|
|
const lv = new DataView(local.buffer);
|
|
lv.setUint32(0, 0x04034b50, true); // 本地头签名
|
|
lv.setUint16(4, 20, true); // 需要 2.0 才能解
|
|
lv.setUint16(6, 0x0800, true); // 位标志:文件名是 UTF-8
|
|
lv.setUint16(8, 0, true); // method 0 = store
|
|
lv.setUint16(10, 0, true); // 时:0
|
|
lv.setUint16(12, 33, true); // 日:1980-01-01
|
|
lv.setUint32(14, crc, true);
|
|
lv.setUint32(18, data.length, true); // 压缩后大小 = 原大小(store)
|
|
lv.setUint32(22, data.length, true);
|
|
lv.setUint16(26, nameBytes.length, true);
|
|
lv.setUint16(28, 0, true); // 无 extra
|
|
local.set(nameBytes, 30);
|
|
local.set(data, 30 + nameBytes.length);
|
|
locals.push(local);
|
|
|
|
const central = new Uint8Array(46 + nameBytes.length);
|
|
const cv = new DataView(central.buffer);
|
|
cv.setUint32(0, 0x02014b50, true); // 中央目录签名
|
|
cv.setUint16(4, 20, true); // 造它的版本
|
|
cv.setUint16(6, 20, true);
|
|
cv.setUint16(8, 0x0800, true);
|
|
cv.setUint16(10, 0, true);
|
|
cv.setUint16(12, 0, true);
|
|
cv.setUint16(14, 33, true);
|
|
cv.setUint32(16, crc, true);
|
|
cv.setUint32(20, data.length, true);
|
|
cv.setUint32(24, data.length, true);
|
|
cv.setUint16(28, nameBytes.length, true);
|
|
cv.setUint32(42, offset, true); // 本地头在包里的偏移
|
|
central.set(nameBytes, 46);
|
|
centrals.push(central);
|
|
|
|
offset += local.length;
|
|
}
|
|
|
|
const centralSize = centrals.reduce((n, c) => n + c.length, 0);
|
|
const eocd = new Uint8Array(22);
|
|
const ev = new DataView(eocd.buffer);
|
|
ev.setUint32(0, 0x06054b50, true);
|
|
ev.setUint16(8, entries.length, true); // 本卷条目数
|
|
ev.setUint16(10, entries.length, true); // 总条目数
|
|
ev.setUint32(12, centralSize, true);
|
|
ev.setUint32(16, offset, true); // 中央目录起点
|
|
|
|
const total = offset + centralSize + eocd.length;
|
|
const out = new Uint8Array(total);
|
|
let p = 0;
|
|
for (const part of [...locals, ...centrals, eocd]) {
|
|
out.set(part, p);
|
|
p += part.length;
|
|
}
|
|
return out;
|
|
}
|