Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implenet new datamodel on the backend #9

Merged
merged 5 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"rules": {
"prettier/prettier": 2,
"no-console": 0,
"no-process-env": 0
"no-process-env": 0,
"no-inline-comments": 0,
"line-comment-position": 0
},
"globals": {
"NodeJS": true
Expand Down
5 changes: 4 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"semi": true,
"trailingComma": "none",
"singleQuote": true,
"printWidth": 120
"printWidth": 120,
"rules": {
"no-inline-comments": "off"
}
j-maynard marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const logger: Logger = pino({
});

// Database handling and export
export const connectToDb = async (datasourceOptions: DataSourceOptions) => {
export const databaseManager = async (datasourceOptions: DataSourceOptions) => {
dbManager = new DatabaseManager(datasourceOptions, logger);
await dbManager.initializeDataSource();
};
Expand Down
29 changes: 25 additions & 4 deletions src/controllers/blob-storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { BlobServiceClient, ContainerClient, StorageSharedKeyCredential } from '@azure/storage-blob';
import { Readable } from 'stream';

import {
BlobServiceClient,
BlobUploadCommonResponse,
ContainerClient,
StorageSharedKeyCredential
} from '@azure/storage-blob';
import * as dotenv from 'dotenv';
import pino from 'pino';

Expand Down Expand Up @@ -42,7 +49,7 @@ export class BlobStorageService {
return this.containerClient;
}

public async uploadFile(fileName: string | undefined, fileContent: Buffer) {
public async uploadFile(fileName: string | undefined, fileContent: Readable) {
if (fileName === undefined) {
throw new Error('File name is undefined');
}
Expand All @@ -52,7 +59,15 @@ export class BlobStorageService {

const blockBlobClient = this.containerClient.getBlockBlobClient(fileName);

const uploadBlobResponse = await blockBlobClient.upload(fileContent, fileContent.length);
const uploadOptions = {
bufferSize: 4 * 1024 * 1024, // 4MB buffer size
maxBuffers: 5 // Parallelism of 5
};
const uploadBlobResponse: BlobUploadCommonResponse = await blockBlobClient.uploadStream(
fileContent,
uploadOptions.bufferSize,
uploadOptions.maxBuffers
);
return uploadBlobResponse;
}

Expand Down Expand Up @@ -84,7 +99,13 @@ export class BlobStorageService {
if (chunk instanceof Buffer) chunks.push(chunk);
else chunks.push(Buffer.from(chunk));
}
return Buffer.concat(chunks).toString('utf-8');
return Buffer.concat(chunks);
}

public async getReadableStream(fileName: string) {
const blockBlobClient = this.containerClient.getBlockBlobClient(fileName);
const downloadBlockBlobResponse = await blockBlobClient.download();
return downloadBlockBlobResponse.readableStreamBody as Readable;
}

public async readFileToBuffer(fileName: string) {
Expand Down
Loading
Loading