From 0da9e1fab3663dcaeadfcf3fdf9b2c18849b24da Mon Sep 17 00:00:00 2001 From: vineethvk11 Date: Thu, 4 Apr 2024 22:31:37 +0530 Subject: [PATCH] removing storage limit for self hosters --- package-lock.json | 19 +++++++++++++++++-- package.json | 1 + packages/backend/src/config.js | 12 ++++++++++++ .../src/filesystem/hl_operations/hl_copy.js | 3 ++- .../src/filesystem/hl_operations/hl_move.js | 3 ++- .../src/filesystem/hl_operations/hl_write.js | 4 ++-- packages/backend/src/routers/df.js | 4 ++-- 7 files changed, 38 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0b1c2824..1b557743 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "packages/*" ], "dependencies": { + "diskusage": "^1.2.0", "uuid": "^9.0.1" }, "devDependencies": { @@ -5244,6 +5245,16 @@ "md5": "^2.3.0" } }, + "node_modules/diskusage": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/diskusage/-/diskusage-1.2.0.tgz", + "integrity": "sha512-2u3OG3xuf5MFyzc4MctNRUKjjwK+UkovRYdD2ed/NZNZPrt0lqHnLKxGhlFVvAb4/oufIgQG3nWgwmeTbHOvXA==", + "hasInstallScript": true, + "dependencies": { + "es6-promise": "^4.2.8", + "nan": "^2.18.0" + } + }, "node_modules/dom-serializer": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", @@ -5481,6 +5492,11 @@ "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", "dev": true }, + "node_modules/es6-promise": { + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", + "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==" + }, "node_modules/escalade": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", @@ -7889,8 +7905,7 @@ "node_modules/nan": { "version": "2.19.0", "resolved": "https://registry.npmjs.org/nan/-/nan-2.19.0.tgz", - "integrity": "sha512-nO1xXxfh/RWNxfd/XPfbIfFk5vgLsAxUR9y5O0cHMJu/AW9U95JLXqthYHjEp+8gQ5p96K9jUp8nbVOxCdRbtw==", - "optional": true + "integrity": "sha512-nO1xXxfh/RWNxfd/XPfbIfFk5vgLsAxUR9y5O0cHMJu/AW9U95JLXqthYHjEp+8gQ5p96K9jUp8nbVOxCdRbtw==" }, "node_modules/napi-build-utils": { "version": "1.0.2", diff --git a/package.json b/package.json index 0fd73122..6485976a 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ ] }, "dependencies": { + "diskusage": "^1.2.0", "uuid": "^9.0.1" } } diff --git a/packages/backend/src/config.js b/packages/backend/src/config.js index 816f6ee3..cecd3a89 100644 --- a/packages/backend/src/config.js +++ b/packages/backend/src/config.js @@ -19,6 +19,7 @@ "use strict" const deep_proto_merge = require('./config/deep_proto_merge'); // const reserved_words = require('./config/reserved_words'); +const diskusage = require('diskusage'); let config = {}; @@ -53,6 +54,17 @@ config.max_subdomains_per_user = 2000; config.storage_capacity = 1*1024*1024*1024; config.static_hosting_domain = '-static.puter.local'; +// Storage limiting is set to false by default +// Storage available on the device puter is running is the storage available +config.is_storage_limited = false; +diskusage.check('/', (err, info) => { + if (err) { + config.available_device_storage = 1*1024*1024*1024; + } else{ + config.available_device_storage = info.free; + } +}); + config.thumb_width = 80; config.thumb_height = 80; config.app_max_icon_size = 5*1024*1024; diff --git a/packages/backend/src/filesystem/hl_operations/hl_copy.js b/packages/backend/src/filesystem/hl_operations/hl_copy.js index 1a043054..98b81ac9 100644 --- a/packages/backend/src/filesystem/hl_operations/hl_copy.js +++ b/packages/backend/src/filesystem/hl_operations/hl_copy.js @@ -23,6 +23,7 @@ const { NodePathSelector, RootNodeSelector } = require("../node/selectors"); const { HLFilesystemOperation } = require("./definitions"); const { MkTree } = require("./hl_mkdir"); const { HLRemove } = require("./hl_remove"); +const config = require("../../config"); class HLCopy extends HLFilesystemOperation { static DESCRIPTION = ` @@ -141,7 +142,7 @@ class HLCopy extends HLFilesystemOperation { let deset_usage = await sizeService.get_usage(dest_user.id); const size = await source.fetchSize(values.user); - let capacity = (dest_user.free_storage === undefined || dest_user.free_storage === null) ? config.storage_capacity : dest_user.free_storage + let capacity = config.is_storage_limited ? (dest_user.free_storage === undefined || dest_user.free_storage === null) ? config.storage_capacity : dest_user.free_storage : config.available_device_storage if(capacity - deset_usage - size < 0){ throw APIError.create('storage_limit_reached'); } diff --git a/packages/backend/src/filesystem/hl_operations/hl_move.js b/packages/backend/src/filesystem/hl_operations/hl_move.js index 90177659..a545f517 100644 --- a/packages/backend/src/filesystem/hl_operations/hl_move.js +++ b/packages/backend/src/filesystem/hl_operations/hl_move.js @@ -24,6 +24,7 @@ const { HLFilesystemOperation } = require("./definitions"); const { MkTree } = require("./hl_mkdir"); const { HLRemove } = require("./hl_remove"); const { TYPE_DIRECTORY } = require("../FSNodeContext"); +const config = require("../../config"); class HLMove extends HLFilesystemOperation { static MODULES = { @@ -105,7 +106,7 @@ class HLMove extends HLFilesystemOperation { dest_user = source_user; await source.fetchSize(); const item_size = source.entry.size; - let capacity = (dest_user.free_storage === undefined || dest_user.free_storage === null) ? config.storage_capacity : dest_user.free_storage + let capacity = config.is_storage_limited ? (dest_user.free_storage === undefined || dest_user.free_storage === null) ? config.storage_capacity : dest_user.free_storage : config.available_device_storage; if(capacity - await df(dest_user.id) - item_size < 0){ throw APIError.create('storage_limit_reached'); } diff --git a/packages/backend/src/filesystem/hl_operations/hl_write.js b/packages/backend/src/filesystem/hl_operations/hl_write.js index f11d1491..c36787f5 100644 --- a/packages/backend/src/filesystem/hl_operations/hl_write.js +++ b/packages/backend/src/filesystem/hl_operations/hl_write.js @@ -61,8 +61,8 @@ class WriteCommonTrait { const { file, user } = this.values; const usage = await sizeService.get_usage(user.id); - let capacity = user.free_storage == undefined - ? config.storage_capacity : user.free_storage; + let capacity = config.is_storage_limited ? user.free_storage == undefined + ? config.storage_capacity : user.free_storage : config.available_device_storage; if( capacity - usage - file.size < 0 ) { throw APIError.create('storage_limit_reached'); } diff --git a/packages/backend/src/routers/df.js b/packages/backend/src/routers/df.js index 1c8ddc50..3e6aceac 100644 --- a/packages/backend/src/routers/df.js +++ b/packages/backend/src/routers/df.js @@ -39,7 +39,7 @@ router.post('/df', auth, express.json(), async (req, response, next)=>{ // auth response.send({ used: parseInt(await df(req.user.id)), - capacity: (req.user.free_storage === undefined || req.user.free_storage === null) ? config.storage_capacity : req.user.free_storage, + capacity: config.is_storage_limited ? (req.user.free_storage === undefined || req.user.free_storage === null) ? config.storage_capacity : req.user.free_storage : config.available_device_storage, }); }catch(e){ console.log(e) @@ -64,7 +64,7 @@ router.get('/df', auth, express.json(), async (req, response, next)=>{ // auth response.send({ used: parseInt(await df(req.user.id)), - capacity: (req.user.free_storage === undefined || req.user.free_storage === null) ? config.storage_capacity : req.user.free_storage, + capacity: config.is_storage_limited ? (req.user.free_storage === undefined || req.user.free_storage === null) ? config.storage_capacity : req.user.free_storage : config.available_device_storage, }); }catch(e){ console.log(e)