- 学生程序每次运行放进 bubblewrap:断网,只读挂载系统文件、运行时和自己的工程目录, 看不到其他进程和服务器环境变量;限制堆内存 128 MB、CPU 时间 120 秒、运行 60 分钟, nice 10,全站同时运行上限 150;启动时自检沙箱,不可用时拒绝运行 - 编译检查(SIM001):网络、反射、启动进程、调用本机代码、加载程序集、dynamic 给出中文报错 - 访问口令:cookie 保存口令哈希,按真实 IP 限制输错次数;前端口令页 - 服务端配置集中到 config.ts,可用环境变量覆盖;Bun 直接提供打包好的网页 - Dockerfile(多阶段,服务端打包成单文件)、compose.yaml(Caddy 只收 HTTP,接入 NPM 的 npm_proxy 网络)、deploy/deploy.sh(本机构建后经 ssh 传到服务器)和部署说明 - 测试:沙箱隔离、内存上限、CPU 时间上限、编译检查 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
17 lines
555 B
TypeScript
17 lines
555 B
TypeScript
/** 逐行读取子进程输出 */
|
|
export async function readLines(stream: ReadableStream<Uint8Array>, onLine: (line: string) => void) {
|
|
const decoder = new TextDecoder()
|
|
let buffer = ''
|
|
for await (const chunk of stream) {
|
|
buffer += decoder.decode(chunk, { stream: true })
|
|
let index = buffer.indexOf('\n')
|
|
while (index >= 0) {
|
|
const line = buffer.slice(0, index).trimEnd()
|
|
buffer = buffer.slice(index + 1)
|
|
if (line) onLine(line)
|
|
index = buffer.indexOf('\n')
|
|
}
|
|
}
|
|
if (buffer.trim()) onLine(buffer.trim())
|
|
}
|