chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { closeSync, openSync, readSync, readdirSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
|
||||
// Read intrinsic sizes before rendering HTML so anchor positions do not depend
|
||||
// on when the screenshot requests finish. Product screenshots are PNG files.
|
||||
export function readScreenshotSizes(directory) {
|
||||
const sizes = {};
|
||||
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
||||
if (!entry.isFile() || !entry.name.endsWith('.png')) continue;
|
||||
const file = openSync(join(directory, entry.name), 'r');
|
||||
const header = Buffer.alloc(24);
|
||||
try {
|
||||
if (readSync(file, header, 0, 24, 0) !== 24
|
||||
|| !header.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))
|
||||
|| header.toString('ascii', 12, 16) !== 'IHDR') {
|
||||
throw new Error(`Invalid PNG screenshot: ${entry.name}`);
|
||||
}
|
||||
const width = header.readUInt32BE(16);
|
||||
const height = header.readUInt32BE(20);
|
||||
if (!width || !height) throw new Error(`Invalid screenshot dimensions: ${entry.name}`);
|
||||
sizes[`/screenshots/${entry.name}`] = { width, height };
|
||||
} finally {
|
||||
closeSync(file);
|
||||
}
|
||||
}
|
||||
return sizes;
|
||||
}
|
||||
Reference in new issue
Block a user