forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser-utils.js
More file actions
28 lines (23 loc) · 993 Bytes
/
user-utils.js
File metadata and controls
28 lines (23 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const $rdf = require('rdflib')
const SOLID = $rdf.Namespace('http://www.w3.org/ns/solid/terms#')
const VCARD = $rdf.Namespace('http://www.w3.org/2006/vcard/ns#')
module.exports.getName = getName
module.exports.getWebId = getWebId
module.exports.isValidUsername = isValidUsername
async function getName (webId, fetchGraph) {
const graph = await fetchGraph(webId)
const nameNode = graph.any($rdf.sym(webId), VCARD('fn'))
return nameNode.value
}
async function getWebId (accountDirectory, accountUrl, suffixMeta, fetchData) {
const metaFilePath = `${accountDirectory}/${suffixMeta}`
const metaFileUri = `${accountUrl}${suffixMeta}`
const metaData = await fetchData(metaFilePath)
const metaGraph = $rdf.graph()
$rdf.parse(metaData, metaGraph, metaFileUri, 'text/turtle')
const webIdNode = metaGraph.any(undefined, SOLID('account'), $rdf.sym(accountUrl))
return webIdNode.value
}
function isValidUsername (username) {
return /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(username)
}