Merge pull request #223 from vineeth-vk11/#211

removing storage limit for self hosters
This commit is contained in:
Eric Dubé 2024-04-04 16:12:31 -04:00 committed by GitHub
commit 3e1c7eb434
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 38 additions and 8 deletions

19
package-lock.json generated
View File

@ -12,6 +12,7 @@
"packages/*" "packages/*"
], ],
"dependencies": { "dependencies": {
"diskusage": "^1.2.0",
"uuid": "^9.0.1" "uuid": "^9.0.1"
}, },
"devDependencies": { "devDependencies": {
@ -5244,6 +5245,16 @@
"md5": "^2.3.0" "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": { "node_modules/dom-serializer": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz",
@ -5481,6 +5492,11 @@
"integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",
"dev": true "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": { "node_modules/escalade": {
"version": "3.1.2", "version": "3.1.2",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz",
@ -7889,8 +7905,7 @@
"node_modules/nan": { "node_modules/nan": {
"version": "2.19.0", "version": "2.19.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.19.0.tgz", "resolved": "https://registry.npmjs.org/nan/-/nan-2.19.0.tgz",
"integrity": "sha512-nO1xXxfh/RWNxfd/XPfbIfFk5vgLsAxUR9y5O0cHMJu/AW9U95JLXqthYHjEp+8gQ5p96K9jUp8nbVOxCdRbtw==", "integrity": "sha512-nO1xXxfh/RWNxfd/XPfbIfFk5vgLsAxUR9y5O0cHMJu/AW9U95JLXqthYHjEp+8gQ5p96K9jUp8nbVOxCdRbtw=="
"optional": true
}, },
"node_modules/napi-build-utils": { "node_modules/napi-build-utils": {
"version": "1.0.2", "version": "1.0.2",

View File

@ -39,6 +39,7 @@
] ]
}, },
"dependencies": { "dependencies": {
"diskusage": "^1.2.0",
"uuid": "^9.0.1" "uuid": "^9.0.1"
} }
} }

View File

@ -19,6 +19,7 @@
"use strict" "use strict"
const deep_proto_merge = require('./config/deep_proto_merge'); const deep_proto_merge = require('./config/deep_proto_merge');
// const reserved_words = require('./config/reserved_words'); // const reserved_words = require('./config/reserved_words');
const diskusage = require('diskusage');
let config = {}; let config = {};
@ -53,6 +54,17 @@ config.max_subdomains_per_user = 2000;
config.storage_capacity = 1*1024*1024*1024; config.storage_capacity = 1*1024*1024*1024;
config.static_hosting_domain = '-static.puter.local'; 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_width = 80;
config.thumb_height = 80; config.thumb_height = 80;
config.app_max_icon_size = 5*1024*1024; config.app_max_icon_size = 5*1024*1024;

View File

@ -23,6 +23,7 @@ const { NodePathSelector, RootNodeSelector } = require("../node/selectors");
const { HLFilesystemOperation } = require("./definitions"); const { HLFilesystemOperation } = require("./definitions");
const { MkTree } = require("./hl_mkdir"); const { MkTree } = require("./hl_mkdir");
const { HLRemove } = require("./hl_remove"); const { HLRemove } = require("./hl_remove");
const config = require("../../config");
class HLCopy extends HLFilesystemOperation { class HLCopy extends HLFilesystemOperation {
static DESCRIPTION = ` static DESCRIPTION = `
@ -141,7 +142,7 @@ class HLCopy extends HLFilesystemOperation {
let deset_usage = await sizeService.get_usage(dest_user.id); let deset_usage = await sizeService.get_usage(dest_user.id);
const size = await source.fetchSize(values.user); 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){ if(capacity - deset_usage - size < 0){
throw APIError.create('storage_limit_reached'); throw APIError.create('storage_limit_reached');
} }

View File

@ -24,6 +24,7 @@ const { HLFilesystemOperation } = require("./definitions");
const { MkTree } = require("./hl_mkdir"); const { MkTree } = require("./hl_mkdir");
const { HLRemove } = require("./hl_remove"); const { HLRemove } = require("./hl_remove");
const { TYPE_DIRECTORY } = require("../FSNodeContext"); const { TYPE_DIRECTORY } = require("../FSNodeContext");
const config = require("../../config");
class HLMove extends HLFilesystemOperation { class HLMove extends HLFilesystemOperation {
static MODULES = { static MODULES = {
@ -105,7 +106,7 @@ class HLMove extends HLFilesystemOperation {
dest_user = source_user; dest_user = source_user;
await source.fetchSize(); await source.fetchSize();
const item_size = source.entry.size; 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){ if(capacity - await df(dest_user.id) - item_size < 0){
throw APIError.create('storage_limit_reached'); throw APIError.create('storage_limit_reached');
} }

View File

@ -61,8 +61,8 @@ class WriteCommonTrait {
const { file, user } = this.values; const { file, user } = this.values;
const usage = await sizeService.get_usage(user.id); const usage = await sizeService.get_usage(user.id);
let capacity = user.free_storage == undefined let capacity = config.is_storage_limited ? user.free_storage == undefined
? config.storage_capacity : user.free_storage; ? config.storage_capacity : user.free_storage : config.available_device_storage;
if( capacity - usage - file.size < 0 ) { if( capacity - usage - file.size < 0 ) {
throw APIError.create('storage_limit_reached'); throw APIError.create('storage_limit_reached');
} }

View File

@ -39,7 +39,7 @@ router.post('/df', auth, express.json(), async (req, response, next)=>{
// auth // auth
response.send({ response.send({
used: parseInt(await df(req.user.id)), 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){ }catch(e){
console.log(e) console.log(e)
@ -64,7 +64,7 @@ router.get('/df', auth, express.json(), async (req, response, next)=>{
// auth // auth
response.send({ response.send({
used: parseInt(await df(req.user.id)), 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){ }catch(e){
console.log(e) console.log(e)