1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-11-15 03:50:11 +01:00

fix: throw error if no disk space is left

This commit is contained in:
Elias Schneider 2024-11-14 18:44:32 +01:00
parent 4ef7ebb062
commit c26de4e881
No known key found for this signature in database
GPG Key ID: 07E623B294202B6C

View File

@ -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),