mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
chore(server): final-review polish — stale CI refs, dockerignore key, boundary pins, zero-byte tempfile contract case
This commit is contained in:
@@ -84,7 +84,14 @@ const S3_VARS = [
|
||||
'TREK_S3_RETRIES',
|
||||
'TREK_S3_TIMEOUT_MS',
|
||||
] as const;
|
||||
const S3_REQUIRED = S3_VARS.slice(0, 4);
|
||||
// Explicit, not `S3_VARS.slice(0, 4)` — the required set must not silently
|
||||
// shift if S3_VARS is ever reordered.
|
||||
const S3_REQUIRED: (typeof S3_VARS)[number][] = [
|
||||
'TREK_S3_ENDPOINT',
|
||||
'TREK_S3_BUCKET',
|
||||
'TREK_S3_ACCESS_KEY_ID',
|
||||
'TREK_S3_SECRET_ACCESS_KEY',
|
||||
];
|
||||
|
||||
/**
|
||||
* All-or-nothing: any TREK_S3_* set means the operator wants off-box storage;
|
||||
@@ -92,7 +99,7 @@ const S3_REQUIRED = S3_VARS.slice(0, 4);
|
||||
* Prefix shape delegates to storage-keys — the single source of key rules.
|
||||
*/
|
||||
function s3Preconditions(raw: RawEnv): string[] {
|
||||
const present = (key: string): boolean => Boolean(raw[key]?.trim());
|
||||
const present = (key: (typeof S3_VARS)[number]): boolean => Boolean(raw[key]?.trim());
|
||||
if (!S3_VARS.some(present)) return [];
|
||||
const problems: string[] = [];
|
||||
for (const key of S3_REQUIRED) {
|
||||
|
||||
@@ -124,7 +124,8 @@ function isNotFound(err: unknown): boolean {
|
||||
* `signedHeaders()` (aws4.js:311-322, which just map/join whatever
|
||||
* `filterHeaders()` produced) sign `content-length` *twice*
|
||||
* (`SignedHeaders=content-length;content-length;...`, confirmed live
|
||||
* against MinIO in the repro below). MinIO's own canonicalization of the
|
||||
* against MinIO (see the manual procedure in docker-compose.minio-test.yml)).
|
||||
* MinIO's own canonicalization of the
|
||||
* headers it actually received doesn't reproduce that duplicate, so the
|
||||
* signatures disagree — 403. Any non-empty body makes
|
||||
* `headers['content-length']` a truthy number, so aws4's guard never fires
|
||||
@@ -480,6 +481,12 @@ function peekStream(source: Readable, limit: number): Promise<{ chunks: Buffer[]
|
||||
const chunk = Buffer.isBuffer(raw) ? raw : Buffer.from(raw);
|
||||
chunks.push(chunk);
|
||||
size += chunk.length;
|
||||
// Strictly `>`, not `>=`: a stream ending at exactly `limit` bytes is
|
||||
// "ended within the limit" and buffers to PutObject, while a
|
||||
// LocalTempFile of exactly `MULTIPART_THRESHOLD` (see put()'s `size <
|
||||
// MULTIPART_THRESHOLD` check) goes to Upload instead. Both boundaries
|
||||
// are correct on their own terms — deliberate asymmetry, not a bug;
|
||||
// do not "align" them.
|
||||
if (size > limit) {
|
||||
cleanup();
|
||||
resolve({ chunks, size, ended: false });
|
||||
|
||||
Reference in New Issue
Block a user