From 197ce6faffc6e039c9a5bfc91bd7d487c9df9f3b Mon Sep 17 00:00:00 2001 From: Daniel Salazar Date: Thu, 25 Jun 2026 14:47:29 -0700 Subject: [PATCH] fix: LegacyFSController (#3308) --- .../controllers/fs/LegacyFSController.ts | 114 ------------------ 1 file changed, 114 deletions(-) diff --git a/src/backend/controllers/fs/LegacyFSController.ts b/src/backend/controllers/fs/LegacyFSController.ts index 34c971c79..a0df0057b 100644 --- a/src/backend/controllers/fs/LegacyFSController.ts +++ b/src/backend/controllers/fs/LegacyFSController.ts @@ -2196,120 +2196,6 @@ export class LegacyFSController extends PuterController { } // -- Helpers --------------------------------------------------------- - - #parsePositiveIntegerQuery( - query: Record, - key: string, - message: string, - ): number | undefined { - const value = query[key]; - if (value === undefined || value === null || value === '') { - return undefined; - } - const parsed = Number.parseInt(String(value), 10); - if (!Number.isInteger(parsed) || parsed < 1) { - throw new HttpError(400, message, { legacyCode: 'bad_request' }); - } - return parsed; - } - - #parseNonNegativeIntegerQuery( - query: Record, - key: string, - message: string, - ): number | undefined { - const value = query[key]; - if (value === undefined || value === null || value === '') { - return undefined; - } - const parsed = Number.parseInt(String(value), 10); - if (!Number.isInteger(parsed) || parsed < 0) { - throw new HttpError(400, message, { legacyCode: 'bad_request' }); - } - return parsed; - } - - #normalizeRangeHeader(rangeHeader: string): string | undefined { - const firstRange = rangeHeader.includes(',') - ? rangeHeader.split(',')[0]?.trim() - : rangeHeader.trim(); - if (!firstRange) return undefined; - - const matches = firstRange.match(/^bytes=(\d+)-(\d*)$/); - if (!matches) return undefined; - - const [, start, end] = matches; - return end ? `bytes=${start}-${end}` : `bytes=${start}-`; - } - - #pipeLimitedLines( - source: NodeJS.ReadableStream, - res: Response, - lineCount: number, - ): void { - let remainingLines = lineCount; - let isClosed = false; - - const closeSource = () => { - if (isClosed) return; - isClosed = true; - if ('destroy' in source && typeof source.destroy === 'function') { - source.destroy(); - } - }; - - source.on('error', (err) => { - if (!isClosed) { - isClosed = true; - res.destroy(err); - } - }); - - res.on('close', () => { - closeSource(); - }); - - source.on('data', (chunk: Buffer | string) => { - if (isClosed) return; - - const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk); - let endIndex = buffer.length; - - for (let index = 0; index < buffer.length; index++) { - if (buffer[index] !== 0x0a) continue; - remainingLines -= 1; - if (remainingLines === 0) { - endIndex = index + 1; - break; - } - } - - if (endIndex > 0) { - const canContinue = res.write(buffer.subarray(0, endIndex)); - if (!canContinue) { - source.pause(); - res.once('drain', () => { - if (!isClosed) { - source.resume(); - } - }); - } - } - - if (endIndex !== buffer.length) { - res.end(); - closeSource(); - } - }); - - source.on('end', () => { - if (!isClosed) { - isClosed = true; - res.end(); - } - }); - } - #requireActor(req: Request) { const actor = req.actor; if (!actor) {