Skip to content

Commit

Permalink
fix: throw error if no disk space is left
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Nov 14, 2024
1 parent 4ef7ebb commit c26de4e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backend/src/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
HttpException,
HttpStatus,
Injectable,
InternalServerErrorException,
NotFoundException,
} from "@nestjs/common";
import { JwtService } from "@nestjs/jwt";
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit c26de4e

Please sign in to comment.