fix: throw error if no disk space is left
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
|||||||
HttpException,
|
HttpException,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
Injectable,
|
Injectable,
|
||||||
|
InternalServerErrorException,
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
} from "@nestjs/common";
|
} from "@nestjs/common";
|
||||||
import { JwtService } from "@nestjs/jwt";
|
import { JwtService } from "@nestjs/jwt";
|
||||||
@@ -59,6 +60,13 @@ export class FileService {
|
|||||||
|
|
||||||
const buffer = Buffer.from(data, "base64");
|
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
|
// Check if share size limit is exceeded
|
||||||
const fileSizeSum = share.files.reduce(
|
const fileSizeSum = share.files.reduce(
|
||||||
(n, { size }) => n + parseInt(size),
|
(n, { size }) => n + parseInt(size),
|
||||||
|
|||||||
Reference in New Issue
Block a user