feat: Track storage usage

This commit is contained in:
Maksim Eltyshev
2025-08-23 00:03:20 +02:00
parent 2f4bcb0583
commit 4d77a1f596
89 changed files with 1052 additions and 304 deletions
+8 -2
View File
@@ -8,7 +8,7 @@ const icoToPng = require('ico-to-png');
const sharp = require('sharp');
const FETCH_TIMEOUT = 4000;
const MAX_RESPONSE_LENGTH_IN_BYTES = 1024 * 1024;
const MAX_RESPONSE_LENGTH = 1024 * 1024;
const FAVICON_TAGS_REGEX = /<link [^>]*rel="([^"]* )?icon( [^"]*)?"[^>]*>/gi;
const HREF_REGEX = /href="(.*?)"/i;
@@ -39,7 +39,7 @@ const readResponse = async (response) => {
chunks.push(value);
receivedLength += value.length;
if (receivedLength > MAX_RESPONSE_LENGTH_IN_BYTES) {
if (receivedLength > MAX_RESPONSE_LENGTH) {
reader.cancel();
return {
@@ -133,6 +133,12 @@ module.exports = {
return;
}
const availableStorage = await sails.helpers.utils.getAvailableStorage();
if (availableStorage !== null && readedResponse.buffer.length >= availableStorage) {
return;
}
let image = sharp(readedResponse.buffer);
let metadata;