From c26de4e881edfe6c7db617c0aeba89871397ebe2 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Thu, 14 Nov 2024 18:44:32 +0100 Subject: [PATCH] fix: throw error if no disk space is left --- backend/src/file/file.service.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/src/file/file.service.ts b/backend/src/file/file.service.ts index ce9958dd..9bf833e9 100644 --- a/backend/src/file/file.service.ts +++ b/backend/src/file/file.service.ts @@ -3,6 +3,7 @@ import { HttpException, HttpStatus, Injectable, + InternalServerErrorException, NotFoundException, } from "@nestjs/common"; import { JwtService } from "@nestjs/jwt"; @@ -59,6 +60,13 @@ export class FileService { const buffer = Buffer.from(data, "base64"); + // Check if there is enough space on the server + const space = await fs.promises.statfs(SHARE_DIRECTORY); + const availableSpace = space.bavail * space.bsize; + if (availableSpace < buffer.byteLength) { + throw new InternalServerErrorException("Not enough space on the server"); + } + // Check if share size limit is exceeded const fileSizeSum = share.files.reduce( (n, { size }) => n + parseInt(size),