Skip to content

Commit 76fee39

Browse files
author
nicola
committed
cleaning code and commenting handlers/put
1 parent 23a656d commit 76fee39

4 files changed

Lines changed: 14 additions & 20 deletions

File tree

‎handlers/post.js‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ function handler(req, res) {
3838
contentType != 'application/nquads' &&
3939
contentType != 'application/n-quads') {
4040
debug("POST -- Invalid Content Type: " + contentType);
41-
return res.status(415).send("Invalid Content Type");
41+
return res
42+
.status(415)
43+
.send("Invalid Content Type");
4244
}
4345

4446

@@ -48,26 +50,29 @@ function handler(req, res) {
4850
// Not a container
4951
if (containerPath[containerPath.length - 1] != '/') {
5052
debug("POST -- Requested resource is not a container");
51-
return res.set('Allow', 'GET,HEAD,PUT,DELETE')
53+
return res
54+
.set('Allow', 'GET,HEAD,PUT,DELETE')
5255
.sendStatus(405);
5356
}
5457

5558
debug("POST -- Content Type: " + contentType);
5659

5760
var resourceMetadata = header.parseMetadataFromHeader(req.get('Link'));
5861

59-
// Create resource
62+
// Create resource URI
6063
var resourcePath = ldp.createResourceUri(
6164
containerPath,
6265
req.get('Slug'),
6366
resourceMetadata.isBasicContainer);
6467

68+
// Check if URI is already in use
6569
if (resourcePath === null) {
6670
ldp.releaseResourceUri(resourcePath);
6771
debug("POST -- URI already exists or in use");
6872
return res.sendStatus(400);
6973
}
7074

75+
// Creating a graph and add the req text
7176
var resourceGraph = $rdf.graph();
7277
var requestText = req.convertedText || req.text;
7378
var uri = file.uriBase(req);
@@ -88,8 +93,10 @@ function handler(req, res) {
8893
return res.sendStatus(400);
8994
}
9095

96+
// Add header link to the resource
9197
header.addLinks(res, resourceMetadata);
9298

99+
// Finally, either create the new resource or container
93100
if (resourceMetadata.isBasicContainer) {
94101
resourcePath += '/';
95102
resourceBaseUri += '/';
@@ -100,7 +107,6 @@ function handler(req, res) {
100107
containerCallback);
101108
} else {
102109
ldp.createNewResource(
103-
ldp.root,
104110
uri,
105111
resourcePath,
106112
resourceGraph,

‎ldp.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ LDP.prototype.releaseResourceUri = function (uri) {
324324
delete this.usedURIs[uri];
325325
};
326326

327-
LDP.prototype.createNewResource = function(fileBase, uri, resourcePath, resourceGraph, callback) {
327+
LDP.prototype.createNewResource = function(uri, resourcePath, resourceGraph, callback) {
328328
var ldp = this;
329-
var resourceURI = path.relative(fileBase, resourcePath);
329+
var resourceURI = path.relative(ldp.root, resourcePath);
330330
//TODO write files with relative URIS.
331331
var rawResource = $rdf.serialize(
332332
undefined,
@@ -396,7 +396,6 @@ LDP.prototype.writeContainerMetadata = function (directory, container, callback)
396396
fs.writeFile(directory + metaExtension, container, callback);
397397
};
398398

399-
400399
LDP.prototype.isMetadataFile = function (filename) {
401400
if (path.extname(filename) === metaExtension)
402401
return true;

‎login.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var webid = require('webid');
55
var debug = require('./logging').login;
66

77
function loginHandler(req, res, next) {
8-
var options = req.app.locals.ldp;
9-
if (!options.webid) {
8+
var ldp = req.app.locals.ldp;
9+
if (!ldp.webid) {
1010
setEmptySession(req);
1111
return next();
1212
}

‎metadata.js‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
/*jslint node: true*/
22
"use strict";
33

4-
var fs = require('fs');
5-
var path = require('path');
6-
var S = require('string');
7-
var debug = require('./logging');
8-
9-
var file = require('./fileStore.js');
10-
var header = require('./header.js');
11-
var ldpVocab = require('./vocab/ldp.js');
12-
13-
var metadataExtension = ".meta";
14-
154
function Metadata() {
165
this.filename = "";
176
this.isResource = false;

0 commit comments

Comments
 (0)