-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
54 lines (47 loc) · 1.58 KB
/
app.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { app, errorHandler } from 'mu';
import { querySudo as query } from '@lblod/mu-auth-sudo';
const PUBLIC_GRAPH = process.env.PUBLIC_GRAPH || 'http://mu.semte.ch/graphs/themis-public';
app.get('/files', async function( req, res ) {
const since = req.query.since || new Date().toISOString();
const files = await getDeltaFiles(since);
res.json({ data: files });
} );
/**
* Get all delta files produced by the ttl-to-delta service since a given timestamp
*
* @param since {string} ISO date time
* @private
*/
async function getDeltaFiles(since) {
console.log(`Retrieving delta files since ${since}`);
const result = await query(`
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#>
PREFIX nie: <http://www.semanticdesktop.org/ontologies/2007/01/19/nie#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?uuid ?filename ?created
WHERE {
GRAPH <${PUBLIC_GRAPH}> {
?s a nfo:FileDataObject ;
mu:uuid ?uuid ;
nfo:fileName ?filename ;
dct:creator <http://redpencil.data.gift/services/ttl-to-delta-service> ;
dct:created ?created .
?file nie:dataSource ?s .
FILTER (?created > "${since}"^^xsd:dateTime)
}
} ORDER BY ?created
`);
return result.results.bindings.map(b => {
return {
type: 'files',
id: b['uuid'].value,
attributes: {
name: b['filename'].value,
created: b['created'].value
}
};
});
}
app.use(errorHandler);