fix(storage): route every file op through getStorageBackend()
Removes 12 direct minioClient.{put,get,remove}Object call sites that
bypassed the pluggable storage abstraction. Filesystem-mode deploys
(MULTI_NODE_DEPLOYMENT=false, storage_backend=filesystem) silently
broke at every site: GDPR export, invoice PDF, EOI generation, portal
download, file upload, folder create/rename/delete, signed PDF land,
maintenance cleanup, etc. Each site now resolves the active backend
and uses its put/get/delete + the new presignDownloadUrl() helper.
Folder marker objects in /files/folders/* keep the same on-the-wire
shape but route through the backend. A future refactor should move
folder bookkeeping to a DB-backed virtual-folder table (see audit
HIGH §3 follow-up note in the route file).
Sites left untouched: src/lib/services/system-monitoring.service.ts
and src/app/api/ready/route.ts use minioClient.bucketExists as an S3-
specific health probe — those are correctly mode-aware and stay.
Refs: docs/audit-comprehensive-2026-05-05.md HIGH §3 (auditor-D Issue 1)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,8 @@ import { createAuditLog, type AuditMeta } from '@/lib/audit';
|
||||
import { diffEntity } from '@/lib/entity-diff';
|
||||
import { NotFoundError, ValidationError } from '@/lib/errors';
|
||||
import { emitToRoom } from '@/lib/socket/server';
|
||||
import { minioClient, buildStoragePath } from '@/lib/minio';
|
||||
import { buildStoragePath } from '@/lib/minio';
|
||||
import { getStorageBackend } from '@/lib/storage';
|
||||
import { env } from '@/lib/env';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { generatePdf } from '@/lib/pdf/generate';
|
||||
@@ -525,13 +526,14 @@ export async function generateFromTemplate(
|
||||
'pdf',
|
||||
);
|
||||
|
||||
await minioClient.putObject(
|
||||
env.MINIO_BUCKET,
|
||||
storagePath,
|
||||
Buffer.from(pdfBytes),
|
||||
pdfBytes.byteLength,
|
||||
{ 'Content-Type': 'application/pdf' },
|
||||
);
|
||||
{
|
||||
const buffer = Buffer.from(pdfBytes);
|
||||
const backend = await getStorageBackend();
|
||||
await backend.put(storagePath, buffer, {
|
||||
contentType: 'application/pdf',
|
||||
sizeBytes: buffer.length,
|
||||
});
|
||||
}
|
||||
|
||||
// Create file record
|
||||
const [fileRecord] = await db
|
||||
@@ -661,13 +663,14 @@ async function generateEoiFromSourcePdf(
|
||||
'pdf',
|
||||
);
|
||||
|
||||
await minioClient.putObject(
|
||||
env.MINIO_BUCKET,
|
||||
storagePath,
|
||||
Buffer.from(pdfBytes),
|
||||
pdfBytes.byteLength,
|
||||
{ 'Content-Type': 'application/pdf' },
|
||||
);
|
||||
{
|
||||
const buffer = Buffer.from(pdfBytes);
|
||||
const backend = await getStorageBackend();
|
||||
await backend.put(storagePath, buffer, {
|
||||
contentType: 'application/pdf',
|
||||
sizeBytes: buffer.length,
|
||||
});
|
||||
}
|
||||
|
||||
const [fileRecord] = await db
|
||||
.insert(files)
|
||||
@@ -809,11 +812,13 @@ async function generateAndSignViaInApp(
|
||||
file: DbFile;
|
||||
});
|
||||
|
||||
// Fetch PDF bytes from MinIO to send to Documenso
|
||||
const pdfStream = await minioClient.getObject(env.MINIO_BUCKET, file.storagePath);
|
||||
// Fetch PDF bytes from the active storage backend to send to Documenso.
|
||||
const pdfStream = await (await getStorageBackend()).get(file.storagePath);
|
||||
const chunks: Buffer[] = [];
|
||||
for await (const chunk of pdfStream) {
|
||||
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk as ArrayBuffer));
|
||||
if (Buffer.isBuffer(chunk)) chunks.push(chunk);
|
||||
else if (typeof chunk === 'string') chunks.push(Buffer.from(chunk));
|
||||
else chunks.push(Buffer.from(chunk as Uint8Array));
|
||||
}
|
||||
const pdfBase64 = Buffer.concat(chunks).toString('base64');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user