Skip to content

Commit 2ec4905

Browse files
committed
Not-yet working code for over quota
1 parent a5c968f commit 2ec4905

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

lib/utils.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ module.exports.stripLineEndings = stripLineEndings
1414
module.exports.fullUrlForReq = fullUrlForReq
1515
module.exports.routeResolvedFile = routeResolvedFile
1616
module.exports.getQuota = getQuota
17+
module.exports.overQuota = overQuota
1718

1819
const fs = require('fs-extra')
1920
const path = require('path')
2021
const $rdf = require('rdflib')
2122
const from = require('from2')
2223
const url = require('url')
2324
const debug = require('./debug').other
25+
const getSize = require('get-folder-size')
2426
var ns = require('solid-namespace')($rdf)
2527

2628
/**
@@ -281,6 +283,19 @@ function getQuota (root, serverUri) {
281283
return quota
282284
}
283285

284-
function overQuota (root, serverUri) {
285-
return getQuota(root, serverUri)
286+
async function overQuota (root, serverUri) {
287+
var actualSize = await _asyncGetSize(root)
288+
let quota = getQuota(root, serverUri)
289+
console.log(root)
290+
console.log(actualSize, quota)
291+
return (actualSize > quota)
292+
}
293+
294+
function _asyncGetSize (root) {
295+
return new Promise((resolve, reject) =>
296+
getSize(root, (size) => {
297+
resolve(size)
298+
}, (err) => {
299+
reject(err)
300+
}))
286301
}

test/integration/quota-test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var expect = require('chai').expect
2-
var getQuota = require('../../lib/utils').getQuota
2+
const getQuota = require('../../lib/utils').getQuota
3+
const overQuota = require('../../lib/utils').overQuota
34
const path = require('path')
45
const read = require('../utils').read
56
const root = 'accounts-acl/config/templates/new-account/'
@@ -21,3 +22,15 @@ describe('Get Quota', function () {
2122
expect(getQuota('test/resources/accounts-acl/quota', 'https://localhost')).to.equal(Infinity)
2223
})
2324
})
25+
26+
describe('Check if over Quota', function () {
27+
it('Check the quota', function () {
28+
expect(overQuota(path.join('test/resources/', root), 'https://localhost')).to.be.false()
29+
})
30+
it('Check the quota with non-existant file', function () {
31+
expect(overQuota(path.join('nowhere/', root), 'https://localhost')).to.be.false()
32+
})
33+
it('Check the quota when the predicate is not present', function () {
34+
expect(overQuota('test/resources/accounts-acl/quota', 'https://localhost')).to.be.false()
35+
})
36+
})

0 commit comments

Comments
 (0)