Skip to content

Commit afbe557

Browse files
committed
Changes to code based on feedback
1 parent 331dc0c commit afbe557

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

lib/handlers/get.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const translate = require('../utils.js').translate
1515
const error = require('../http-error')
1616

1717
const RDFs = require('../ldp').RDF_MIME_TYPES
18+
// const LDP = require('../ldp')
19+
// const RDFs = LDP.mimeTypesAsArray()
1820

1921
async function handler (req, res, next) {
2022
const ldp = req.app.locals.ldp

lib/ldp.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const parse = require('./utils').parse
1717
const fetch = require('node-fetch')
1818
const { promisify } = require('util')
1919

20+
// TODO: apply new Set
2021
const RDF_MIME_TYPES = [
2122
'text/turtle', // .ttl
2223
'text/n3', // .n3
@@ -28,7 +29,7 @@ const RDF_MIME_TYPES = [
2829
'application/rdf+xml', // .rdf
2930
'application/ld+json', // .jsonld
3031
'application/x-turtle'
31-
]
32+
])
3233

3334
class LDP {
3435
constructor (argv = {}) {
@@ -463,9 +464,12 @@ class LDP {
463464
return ensureNotExists(this, path.join(containerURI, filename))
464465
}
465466

466-
mimetypeIsRdf (mimeType) {
467-
return RDF_MIME_TYPES.indexOf(mimeType) !== -1
467+
static mimeTypeIsRdf (mimeType) {
468+
return RDF_MIME_TYPES.has(mimeType)
469+
}
470+
471+
static mimeTypesAsArray () {
472+
return Array.from(RDF_MIME_TYPES)
468473
}
469474
}
470475
module.exports = LDP
471-
module.exports.RDF_MIME_TYPES = RDF_MIME_TYPES

lib/models/account-template.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const mime = require('mime-types')
55
const recursiveRead = require('recursive-readdir')
66
const fsUtils = require('../common/fs-utils')
77
const templateUtils = require('../common/template-utils')
8+
const LDP = require('../ldp')
89

9-
const RDF_MIME_TYPES = require('../ldp').RDF_MIME_TYPES
1010
const TEMPLATE_EXTENSIONS = [ '.acl', '.meta', '.json', '.hbs', '.handlebars' ]
1111
const TEMPLATE_FILES = [ 'card' ]
1212

@@ -31,7 +31,6 @@ class AccountTemplate {
3131
*/
3232
constructor (options = {}) {
3333
this.substitutions = options.substitutions || {}
34-
this.rdfMimeTypes = options.rdfMimeTypes || RDF_MIME_TYPES
3534
this.templateExtensions = options.templateExtensions || TEMPLATE_EXTENSIONS
3635
this.templateFiles = options.templateFiles || TEMPLATE_FILES
3736
}
@@ -136,11 +135,12 @@ class AccountTemplate {
136135
* @return {boolean}
137136
*/
138137
isTemplate (filePath) {
139-
let parsed = path.parse(filePath)
138+
const parsed = path.parse(filePath)
140139

141-
let isRdf = this.rdfMimeTypes.includes(mime.lookup(filePath))
142-
let isTemplateExtension = this.templateExtensions.includes(parsed.ext)
143-
let isTemplateFile = this.templateFiles.includes(parsed.base) ||
140+
const mimeType = mime.lookup(filePath)
141+
const isRdf = LDP.mimeTypeIsRdf(mimeType)
142+
const isTemplateExtension = this.templateExtensions.includes(parsed.ext)
143+
const isTemplateFile = this.templateFiles.includes(parsed.base) ||
144144
this.templateExtensions.includes(parsed.base) // the '/.acl' case
145145

146146
return isRdf || isTemplateExtension || isTemplateFile

test/integration/http-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,10 @@ describe('HTTP APIs', function () {
473473
.expect(hasHeader('acl', 'baz.ttl' + suffixAcl))
474474
.expect(201, done)
475475
})
476-
it('should return 409 code when trying to put to a container',
476+
it('should fail when trying to put to a container',
477477
function (done) {
478478
server.put('/')
479-
.expect(409, done)
479+
.expect(405, done)
480480
}
481481
)
482482
// Cleanup

0 commit comments

Comments
 (0)