Skip to content

Commit 22e245a

Browse files
committed
fix(review): align falsy merge semantics with original JS
parseToolAllowlist array branch back to || (drop 0/false entries). readFileNumber falls through on 0 like fileConfig.X || default. buildBackendAuthHeaders coerces truthy non-strings via String() as before. Document that Docker images do not bake local config.json.
1 parent d523dd1 commit 22e245a

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎docs/docker.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ docker run -d \
9292

9393
> 后端 `10001` 仅容器内部使用,不要对外发布(compose 默认也只映射代理端口;改端口用 `OPENCODE_PROXY_PORT`,如 `8090`)。
9494
95+
> 注意:镜像构建时**不会**把本地 `config.json` 烘焙进去(多阶段构建只复制 `dist/` 与依赖,避免把本地密钥带进镜像)。容器内配置请用环境变量,或 `-v ./config.json:/home/node/project/config.json:ro` 挂载(代理会按 `dist/` 同层 → 项目根 → 工作目录顺序查找)。
96+
9597
### 多架构
9698

9799
`ghcr.io/samson910022/opencode2api:latest` 同时含 `linux/amd64` 与 `linux/arm64`,ARM 机器可直接 pull,无需本地 build(仅自带 `custom-bin/opencode` 二进制时才需按架构重建)。

‎index.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ function parseBool(value: unknown, fallback: boolean): boolean {
2323

2424
function parseToolAllowlist(value: unknown, fallback: string[] = []): string[] {
2525
if (Array.isArray(value)) {
26-
return [...new Set((value as unknown[]).map((entry) => String(entry ?? '').trim()).filter(Boolean))];
26+
// NOTE: `||` (not `??`) matches the original JS verbatim: falsy entries
27+
// (0/false) stringify to '' and are filtered out instead of becoming
28+
// "0"/"false" allowlist entries.
29+
return [...new Set((value as unknown[]).map((entry) => String((entry as unknown) || '').trim()).filter(Boolean))];
2730
}
2831
if (typeof value === 'string') {
2932
return [...new Set(value.split(',').map((entry) => entry.trim()).filter(Boolean))];
@@ -96,7 +99,9 @@ function readFileString(key: string, fallback: string): string {
9699

97100
function readFileNumber(key: string, fallback: number): number {
98101
const v: unknown = fileConfig[key];
99-
if (typeof v === 'number' && Number.isFinite(v)) return v;
102+
// NOTE: `0` falls through to fallback to match the original
103+
// `fileConfig.X || default` semantics verbatim.
104+
if (typeof v === 'number' && Number.isFinite(v) && v !== 0) return v;
100105
if (typeof v === 'string' && v.trim() !== '') {
101106
const n = parseInt(v, 10);
102107
if (Number.isFinite(n)) return n;

‎src/backend/manager.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,10 @@ export function lock(task: unknown, timeout: unknown = 120000): Promise<unknown>
230230
* Robust Health Check Helper
231231
*/
232232
export function buildBackendAuthHeaders(password: unknown = ''): Record<string, string> | undefined {
233-
if (!password || typeof password !== 'string' || !password) return undefined;
234-
const token = Buffer.from(`opencode:${password}`).toString('base64');
233+
// NOTE: falsy check (not typeof) matches the original JS verbatim: truthy
234+
// non-strings (e.g. numeric 123 from config.json) are coerced via String().
235+
if (!password) return undefined;
236+
const token = Buffer.from(`opencode:${String(password)}`).toString('base64');
235237
return { Authorization: `Basic ${token}` };
236238
}
237239

0 commit comments

Comments
 (0)