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

Function handler

lib/handlers/copy.mjs:14–35  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

12 * @method handler
13 */
14export default async function handler (req, res, next) {
15 const copyFrom = req.header('Source')
16 if (!copyFrom) {
17 return next(HTTPError(400, 'Source header required'))
18 }
19 const fromExternal = !!parse(copyFrom).hostname
20 const ldp = req.app.locals.ldp
21 const serverRoot = ldp.resourceMapper.resolveUrl(req.hostname)
22 const copyFromUrl = fromExternal ? copyFrom : serverRoot + copyFrom
23 const copyToUrl = res.locals.path || req.path
24 try {
25 await ldpCopy(ldp.resourceMapper, copyToUrl, copyFromUrl)
26 } catch (err) {
27 const statusCode = err.statusCode || 500
28 const errorMessage = err.statusMessage || err.message
29 debug.handlers('Error with COPY request:' + errorMessage)
30 return next(HTTPError(statusCode, errorMessage))
31 }
32 res.set('Location', copyToUrl)
33 res.sendStatus(201)
34 next()
35}

Callers

nothing calls this directly

Calls 3

HTTPErrorFunction · 0.85
resolveUrlMethod · 0.80
parseFunction · 0.50

Tested by

no test coverage detected