(req, res, next)
| 39 | } |
| 40 | |
| 41 | export async function linksHandler (req, res, next) { |
| 42 | const ldp = req.app.locals.ldp |
| 43 | let filename |
| 44 | try { |
| 45 | // Hack: createIfNotExists is set to true for PUT or PATCH requests |
| 46 | // because the file might not exist yet at this point. |
| 47 | // But it will be created afterwards. |
| 48 | // This should be improved with the new server architecture. |
| 49 | ({ path: filename } = await ldp.resourceMapper |
| 50 | .mapUrlToFile({ url: req, createIfNotExists: req.method === 'PUT' || req.method === 'PATCH' })) |
| 51 | } catch (e) { |
| 52 | // Silently ignore errors here |
| 53 | // Later handlers will error as well, but they will be able to given a more concrete error message (like 400 or 404) |
| 54 | return next() |
| 55 | } |
| 56 | |
| 57 | if (path.extname(filename) === ldp.suffixMeta) { |
| 58 | debug.metadata('Trying to access metadata file as regular file.') |
| 59 | |
| 60 | return next(HTTPError(404, 'Trying to access metadata file as regular file')) |
| 61 | } |
| 62 | const fileMetadata = new metadata.Metadata() |
| 63 | if (req.path.endsWith('/')) { |
| 64 | // do not add storage header in serverUri |
| 65 | if (req.path === '/') fileMetadata.isStorage = true |
| 66 | fileMetadata.isContainer = true |
| 67 | fileMetadata.isBasicContainer = true |
| 68 | } else { |
| 69 | fileMetadata.isResource = true |
| 70 | } |
| 71 | // Add LDP-required Accept-Post header for OPTIONS request to containers |
| 72 | if (fileMetadata.isContainer && req.method === 'OPTIONS') { |
| 73 | res.header('Accept-Post', '*/*') |
| 74 | } |
| 75 | // Add ACL and Meta Link in header |
| 76 | addLink(res, pathBasename(req.path) + ldp.suffixAcl, 'acl') |
| 77 | addLink(res, pathBasename(req.path) + ldp.suffixMeta, 'describedBy') |
| 78 | // Add other Link headers |
| 79 | addLinks(res, fileMetadata) |
| 80 | next() |
| 81 | } |
| 82 | |
| 83 | export function parseMetadataFromHeader (linkHeader) { |
| 84 | const fileMetadata = new metadata.Metadata() |
nothing calls this directly
no test coverage detected