MCPcopy Index your code
hub / github.com/nodeSolidServer/node-solid-server / putStream

Function putStream

lib/handlers/put.mjs:57–82  ·  view source on GitHub ↗
(req, res, next, stream = req)

Source from the content-addressed store, hash-verified

55
56// TODO could be renamed as putResource (it now covers container and non-container)
57async function putStream (req, res, next, stream = req) {
58 const ldp = req.app.locals.ldp
59 // Obtain details of the target resource
60 let resourceExists = true
61 try {
62 // First check if the file already exists
63 await ldp.resourceMapper.mapUrlToFile({ url: req })
64 // Fails on if-none-match asterisk precondition
65 if ((req.headers['if-none-match'] === '*') && !req.path.endsWith('/')) {
66 res.sendStatus(412)
67 return next()
68 }
69 } catch (err) {
70 resourceExists = false
71 }
72 try {
73 // Fails with Append on existing resource
74 if (!req.originalUrl.endsWith('.acl')) await checkPermission(req, resourceExists)
75 await ldp.put(req, stream, getContentType(req.headers))
76 res.sendStatus(resourceExists ? 204 : 201)
77 return next()
78 } catch (err) {
79 err.message = 'Can\'t write file/folder: ' + err.message
80 return next(err)
81 }
82}
83
84// needed to avoid breaking access with bad acl
85// or breaking containement triples for meta

Callers 2

handlerFunction · 0.85
putValidRdfFunction · 0.85

Calls 4

getContentTypeFunction · 0.90
mapUrlToFileMethod · 0.80
putMethod · 0.80
checkPermissionFunction · 0.70

Tested by

no test coverage detected