(req, res, next, stream = req)
| 55 | |
| 56 | // TODO could be renamed as putResource (it now covers container and non-container) |
| 57 | async 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 |
no test coverage detected