refactor: rename temp-chunks to temp-uploads and update related configurations

- Changed references from 'temp-chunks' to 'temp-uploads' across .dockerignore, Dockerfile, and various configuration files for consistency.
- Introduced a new directories configuration file to manage directory paths more effectively.
- Updated file handling in the server code to utilize streaming for uploads and downloads, improving performance and memory management.
- Enhanced cleanup processes for temporary directories to maintain a tidy file structure.
This commit is contained in:
Daniel Luiz Alves
2025-07-06 00:06:09 -03:00
parent c9a9f1d6cf
commit 95939f8f47
21 changed files with 296 additions and 217 deletions

View File

@@ -533,8 +533,23 @@ export class ReverseShareService {
const { FilesystemStorageProvider } = await import("../../providers/filesystem-storage.provider.js");
const provider = FilesystemStorageProvider.getInstance();
const sourceBuffer = await provider.downloadFile(file.objectName);
await provider.uploadFile(newObjectName, sourceBuffer);
// Use streaming copy for filesystem mode
const sourcePath = provider.getFilePath(file.objectName);
const fs = await import("fs");
const { pipeline } = await import("stream/promises");
const sourceStream = fs.createReadStream(sourcePath);
const decryptStream = provider.createDecryptStream();
// Create a passthrough stream to get the decrypted content
const { PassThrough } = await import("stream");
const passThrough = new PassThrough();
// First, decrypt the source file into the passthrough stream
await pipeline(sourceStream, decryptStream, passThrough);
// Then upload the decrypted content
await provider.uploadFileFromStream(newObjectName, passThrough);
} else {
const downloadUrl = await this.fileService.getPresignedGetUrl(file.objectName, 300);
const uploadUrl = await this.fileService.getPresignedPutUrl(newObjectName, 300);
@@ -544,11 +559,13 @@ export class ReverseShareService {
throw new Error(`Failed to download file: ${response.statusText}`);
}
const fileBuffer = Buffer.from(await response.arrayBuffer());
if (!response.body) {
throw new Error("No response body received");
}
const uploadResponse = await fetch(uploadUrl, {
method: "PUT",
body: fileBuffer,
body: response.body,
headers: {
"Content-Type": "application/octet-stream",
},