Skip to content

Commit e71d5c3

Browse files
committed
Remove hardcoded default content types where unneeded
1 parent 81df5c6 commit e71d5c3

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/handlers/patch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const PATCH_PARSERS = {
1616
'text/n3': require('./patch/n3-patch-parser.js')
1717
}
1818

19-
const DEFAULT_CONTENT_TYPE = 'text/turtle'
19+
const DEFAULT_PATCH_CONTENT_TYPE = 'text/turtle'
2020

2121
// Handles a PATCH request
2222
async function patchHandler (req, res, next) {
@@ -32,7 +32,7 @@ async function patchHandler (req, res, next) {
3232
} catch (err) {
3333
// If the file doesn't exist, request one to be created with the default content type
3434
({ path, contentType } = await ldp.resourceMapper.mapUrlToFile(
35-
{ url: req, createIfNotExists: true, contentType: DEFAULT_CONTENT_TYPE }))
35+
{ url: req, createIfNotExists: true, contentType: DEFAULT_PATCH_CONTENT_TYPE }))
3636
}
3737
const { url } = await ldp.resourceMapper.mapFileToUrl({ path, hostname: req.hostname })
3838
const resource = { path, contentType, url }

lib/ldp.js

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

19-
const DEFAULT_CONTENT_TYPE = 'text/turtle'
19+
const DEFAULT_REMOTE_CONTENT_TYPE = 'text/turtle'
2020

2121
const RDF_MIME_TYPES = [
2222
'text/turtle', // .ttl
@@ -197,7 +197,7 @@ class LDP {
197197
*
198198
* @return {Promise<Graph>}
199199
*/
200-
async putGraph (graph, uri, contentType = DEFAULT_CONTENT_TYPE) {
200+
async putGraph (graph, uri, contentType) {
201201
const { path } = url.parse(uri)
202202
const content = await serialize(graph, uri, contentType)
203203
let stream = stringToStream(content)
@@ -286,7 +286,7 @@ class LDP {
286286
}
287287
const body = await response.text()
288288

289-
const contentType = options.contentType || DEFAULT_CONTENT_TYPE
289+
const contentType = options.contentType || DEFAULT_REMOTE_CONTENT_TYPE
290290

291291
return promisify(parse)(body, uri, contentType)
292292
}
@@ -309,12 +309,15 @@ class LDP {
309309
*
310310
* @return {Promise<Graph>}
311311
*/
312-
getGraph (uri, contentType = DEFAULT_CONTENT_TYPE) {
312+
getGraph (uri, contentType) {
313313
return this.graph(uri, uri, contentType)
314314
}
315315

316-
async graph (url, baseUri, contentType = DEFAULT_CONTENT_TYPE) {
316+
async graph (url, baseUri, contentType) {
317317
const body = await this.readResource(url)
318+
if (!contentType) {
319+
({ contentType } = await this.resourceMapper.mapUrlToFile({ url }))
320+
}
318321
return new Promise((resolve, reject) => {
319322
const graph = $rdf.graph()
320323
$rdf.parse(body, graph, baseUri, contentType,

0 commit comments

Comments
 (0)