Skip to content

Commit b979ebf

Browse files
author
nicola
committed
removing opts.uri from handlers and acl
1 parent df8e38b commit b979ebf

2 files changed

Lines changed: 85 additions & 50 deletions

File tree

‎container.js‎

Lines changed: 81 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,49 @@ var addUriTriple = function(kb, s, o, p) {
1818

1919
var turtleExtension = ".ttl";
2020

21-
function createRootContainer(options) {
22-
if (!metadata.hasContainerMetadata(options.base)) {
23-
var rootContainer = $rdf.graph();
24-
addUriTriple(rootContainer, options.pathStart,
25-
rdfVocab.type, ldpVocab.Container);
26-
addUriTriple(rootContainer, options.pathStart,
27-
rdfVocab.type, ldpVocab.BasicContainer);
28-
rootContainer.add(rootContainer.sym(options.pathStart),
29-
rootContainer.sym('http://purl.org/dc/terms/title'),
30-
'"Root Container"');
31-
var serializedContainer = $rdf.serialize(undefined, rootContainer,
32-
options.pathStart, 'text/turtle');
33-
metadata.writeContainerMetadata(options.base,
34-
serializedContainer, function(err) {
35-
if (err) {
36-
//TODO handle error
37-
debug("Could not write root container");
38-
} else {
39-
debug("Wrote root container to " + options.base);
40-
}
41-
});
21+
function createRootContainer(fileBase, baseUrl) {
22+
if (metadata.hasContainerMetadata(fileBase)) {
23+
return;
4224
}
25+
26+
var rootContainer = $rdf.graph();
27+
addUriTriple(
28+
rootContainer,
29+
baseUrl,
30+
rdfVocab.type,
31+
ldpVocab.Container);
32+
addUriTriple(
33+
rootContainer,
34+
baseUrl,
35+
rdfVocab.type,
36+
ldpVocab.BasicContainer);
37+
38+
rootContainer.add(
39+
rootContainer.sym(baseUrl),
40+
rootContainer.sym('http://purl.org/dc/terms/title'),
41+
'"Root Container"');
42+
43+
var serializedContainer = $rdf.serialize(
44+
undefined,
45+
rootContainer,
46+
baseUrl,
47+
'text/turtle');
48+
49+
metadata.writeContainerMetadata(
50+
fileBase,
51+
serializedContainer,
52+
function(err) {
53+
if (err) {
54+
//TODO handle error
55+
debug("Could not write root container");
56+
} else {
57+
debug("Wrote root container to " + fileBase);
58+
}
59+
});
60+
4361
}
4462

45-
function createResourceUri(options, containerURI, slug, isBasicContainer) {
63+
function createResourceUri(usedURIs, containerURI, slug, isBasicContainer) {
4664
var newPath;
4765
if (slug) {
4866
if (S(slug).endsWith(turtleExtension)) {
@@ -61,65 +79,81 @@ function createResourceUri(options, containerURI, slug, isBasicContainer) {
6179
newPath = path.join(containerURI, uuid.v1() + turtleExtension);
6280
}
6381
}
64-
if (!(fs.existsSync(newPath) || containerURI in options.usedURIs)) {
65-
options.usedURIs[newPath] = true;
82+
if (!(fs.existsSync(newPath) || containerURI in usedURIs)) {
83+
usedURIs[newPath] = true;
6684
} else {
6785
return null;
6886
}
6987
return newPath;
7088
}
7189

72-
function releaseResourceUri(options, uri) {
73-
delete options.usedURIs[uri];
90+
function releaseResourceUri(usedURIs, uri) {
91+
delete usedURIs[uri];
7492
}
7593

76-
function createNewResource(options, resourcePath, resourceGraph, callback) {
77-
var resourceURI = path.relative(options.base, resourcePath);
94+
function createNewResource(usedURIs, fileBase, uri, resourcePath, resourceGraph, callback) {
95+
var resourceURI = path.relative(fileBase, resourcePath);
7896
//TODO write files with relative URIS.
79-
var rawResource = $rdf.serialize(undefined,
80-
resourceGraph, options.uri + resourceURI, 'text/turtle');
97+
var rawResource = $rdf.serialize(
98+
undefined,
99+
resourceGraph,
100+
uri + resourceURI,
101+
'text/turtle');
102+
81103
debug("Writing new resource to " + resourcePath);
82104
debug("Resource:\n" + rawResource);
83-
fs.writeFile(resourcePath, rawResource, writeResourceCallback);
105+
106+
fs.writeFile(
107+
resourcePath,
108+
rawResource,
109+
writeResourceCallback);
84110

85111
function writeResourceCallback(err) {
86112
if (err) {
87113
debug("Error writing resource: " + err);
88-
module.exports.releaseResourceUri(options, resourcePath);
89-
callback(err);
90-
} else {
114+
releaseResourceUri(usedURIs, resourcePath);
91115
return callback(err);
92116
}
117+
118+
return callback(err);
93119
}
94120
}
95121

96-
function createNewContainer(options, containerPath, containerGraph, callback) {
122+
function createNewContainer(usedURIs, uri, containerPath, containerGraph, callback) {
97123
fs.mkdir(containerPath, mkdirCallback);
98124

99125
function mkdirCallback(err) {
100126
if (err) {
101127
debug("Error creating directory for new container: " + err);
102-
module.exports.releaseResourceUri(options, containerPath);
128+
releaseResourceUri(usedURIs, containerPath);
103129
return callback(err);
104-
} else {
105-
var rawContainer = $rdf.serialize(undefined, containerGraph,
106-
options.uri, 'text/turtle');
107-
debug("rawContainer " + rawContainer);
108-
metadata.writeContainerMetadata(containerPath, rawContainer,
109-
writeContainerCallback);
110130
}
131+
132+
var rawContainer = $rdf.serialize(
133+
undefined,
134+
containerGraph,
135+
uri,
136+
'text/turtle');
137+
138+
debug("rawContainer " + rawContainer);
139+
140+
metadata.writeContainerMetadata(
141+
containerPath,
142+
rawContainer,
143+
writeContainerCallback);
111144
}
112145

113146
function writeContainerCallback(err) {
114147
if (err) {
115148
debug("Error writing container: " + err);
116-
module.exports.releaseResourceUri(options, containerPath);
117-
return callback(err);
118-
} else {
119-
debug("Wrote container to " + containerPath);
120-
module.exports.releaseResourceUri(options, containerPath);
149+
releaseResourceUri(usedURIs, containerPath);
121150
return callback(err);
122151
}
152+
153+
debug("Wrote container to " + containerPath);
154+
releaseResourceUri(usedURIs, containerPath);
155+
return callback(err);
156+
123157
}
124158
}
125159

‎index.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ function ldnode (argv) {
4848
}));
4949

5050
// Creating root container
51-
container.createRootContainer(opts);
51+
// TODO make sure pathStart is where it is mounted
52+
container.createRootContainer(opts.fileBase, opts.pathStart);
5253

5354
// Setting up routes
54-
app.use(opts.pathStart, routes());
55+
app.use('/', routes());
5556

5657
// Adding proxy
5758
if (opts.xssProxy) {
58-
console.log(proxyFilter)
59+
console.log(opts.proxyFilter);
5960
proxy(app, opts.proxyFilter);
6061
}
6162

0 commit comments

Comments
 (0)