Skip to content

Commit 58a33e4

Browse files
committed
Reading from file works
1 parent 22b21f7 commit 58a33e4

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@prefix dct: <http://purl.org/dc/terms/>.
2+
@prefix pim: <http://www.w3.org/ns/pim/space#>.
13
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
24
@prefix unit: <http://www.w3.invalid/ns#>.
35

@@ -6,6 +8,6 @@
68

79
dct:description "Administrative settings for the server that are only readable to the user." .
810

9-
<{{webId}}>
11+
</>
1012
solid:storageQuota "25"^^unit:megabyte .
1113

lib/utils.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ module.exports.debrack = debrack
1313
module.exports.stripLineEndings = stripLineEndings
1414
module.exports.fullUrlForReq = fullUrlForReq
1515
module.exports.routeResolvedFile = routeResolvedFile
16+
module.exports.getQuota = getQuota
1617

1718
const fs = require('fs-extra')
1819
const path = require('path')
1920
const $rdf = require('rdflib')
2021
const from = require('from2')
2122
const url = require('url')
23+
var ns = require('solid-namespace')($rdf)
2224

2325
/**
2426
* Returns a fully qualified URL from an Express.js Request object.
@@ -245,9 +247,27 @@ function routeResolvedFile (router, path, file, appendFileName = true) {
245247
* may store or Infinity if no limit
246248
*/
247249

248-
/* function getQuota (req) {
249-
// const path = reqToPath(req)
250-
var quota = 25
250+
function getQuota (root, serverUri) {
251+
const filename = path.join(root, 'settings/serverSide.ttl')
252+
const prefs = fs.readFileSync(filename, 'utf8')
253+
var graph = $rdf.graph()
254+
const storageUri = serverUri + '/'
255+
$rdf.parse(prefs, graph, storageUri, 'text/turtle')
256+
const lit = graph.each($rdf.sym(storageUri), ns.solid('storageQuota'), undefined)[0]
257+
var quota = lit.value
258+
const unitUri = 'http://www.w3.invalid/ns#'
259+
// The following should be encoded in the ontology
260+
switch (lit.datatype.value) {
261+
case unitUri + 'kilobyte':
262+
quota *= 1000
263+
break
264+
case unitUri + 'megabyte':
265+
quota *= 1000000
266+
break
267+
case unitUri + 'gigabyte':
268+
quota *= 1000000000
269+
break
270+
}
251271
return quota
252272
}
253273

test/integration/quota-test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
var expect = require('chai').expect
2-
// var getQuota = require('../../lib/utils').getQuota
2+
var getQuota = require('../../lib/utils').getQuota
33
const path = require('path')
44
const read = require('../utils').read
5-
const host = 'localhost:3457'
6-
var domain = host.split(':')[0]
5+
const root = 'accounts-acl/config/templates/new-account/'
6+
// const $rdf = require('rdflib')
77

88
describe('Quota', function () {
9-
it('Check that the file is readable', function () {
10-
var prefs = read(path.join('accounts/nicola.' + domain, 'settings/serverSide.ttl'))
11-
expect(prefs).to.be.true()
9+
var prefs = read(path.join(root, 'settings/serverSide.ttl'))
10+
it('Check that the file is readable and has predicate', function () {
11+
expect(prefs).to.be.a('string')
12+
expect(prefs).to.match(/storageQuota/)
13+
})
14+
it('Get the quota', function () {
15+
expect(getQuota(path.join('test/resources/', root), 'https://localhost')).to.equal(2000)
1216
})
1317
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@prefix dct: <http://purl.org/dc/terms/>.
2+
@prefix pim: <http://www.w3.org/ns/pim/space#>.
3+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
4+
@prefix unit: <http://www.w3.invalid/ns#>.
5+
6+
<>
7+
a pim:ConfigurationFile;
8+
9+
dct:description "Administrative settings for the server that are only readable to the user." .
10+
11+
</>
12+
solid:storageQuota "2"^^unit:kilobyte .
13+

0 commit comments

Comments
 (0)