@nasriya/hypercloud
Version:
Nasriya HyperCloud is a lightweight Node.js HTTP2 framework.
75 lines (74 loc) • 3.1 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mimeLimits_1 = __importDefault(require("./mimeLimits"));
const utils_1 = __importDefault(require("./utils"));
class UploadLimits {
#_controller;
#_mimeLimits;
constructor(controller) {
this.#_controller = controller;
this.#_mimeLimits = new mimeLimits_1.default(controller);
}
/**
* Gets the current file stream limit for uploads.
* This limit defines the maximum size at which file uploads will be stored in a stream
* rather than in memory.
*
* @returns {number} The file stream limit in bytes.
*/
get fileStream() { return this.#_controller.fileStream.get(); }
/**
* Sets a new file stream limit for uploads.
* If the provided limit is a `StorageSize`, it will be converted to bytes.
* This limit determines when uploads are stored in a stream rather than in memory.
*
* @param {number | StorageSize} limit - The new file stream limit, either as a number in bytes or a `StorageSize` object.
*/
set fileStream(limit) {
const limitValue = utils_1.default.getLimit(limit);
this.#_controller.fileStream.set(limitValue);
}
/**
* Get the maximum allowed size for images.
* @returns {number} - The maximum file size limit for images in bytes.
*/
get images() { return this.#_controller.images.get(); }
/**
* Set the maximum allowed size for images, or set it
* to `0` to remove the limit.
* @param {number|StorageSize} limit - The maximum allowed file size of images in bytes.
* @throws {TypeError} - Throws if limit is not a number.
* @throws {RangeError} - Throws if limit is negative.
*/
set images(limit) {
const limitValue = utils_1.default.getLimit(limit);
this.#_controller.images.set(limitValue);
}
/**
* Get the maximum allowed size for videos.
* @returns {number} - The maximum file size limit for videos in bytes.
*/
get videos() { return this.#_controller.videos.get(); }
/**
* Set the maximum allowed size for videos, or set it
* to `0` to remove the limit.
* @param {number|StorageSize} limit - The maximum allowed file size of videos in bytes.
* @throws {TypeError} - Throws if limit is not a number.
* @throws {RangeError} - Throws if limit is negative.
*/
set videos(limit) {
const limitValue = utils_1.default.getLimit(limit);
this.#_controller.videos.set(limitValue);
}
/**
* Set or get the maximum allowed file size for specific MIME types.
* This allows for finer-grained control over upload limits based on MIME type.
* The MIME type-specific limit takes precedence over the general image or video limits.
* Use `0` to remove the limit for a specific MIME type.
*/
get mime() { return this.#_mimeLimits; }
}
exports.default = UploadLimits;