(hostname, containerPath, stream, { container, slug, extension, contentType })
| 128 | } |
| 129 | |
| 130 | async post (hostname, containerPath, stream, { container, slug, extension, contentType }) { |
| 131 | // POST without content type is forbidden |
| 132 | if (!contentType) { |
| 133 | throw error(400, |
| 134 | 'POSTrequest requires a content-type via the Content-Type header') |
| 135 | } |
| 136 | |
| 137 | const ldp = this |
| 138 | debug.handlers('POST -- On parent: ' + containerPath) |
| 139 | if (container) { |
| 140 | // Containers should not receive an extension |
| 141 | extension = '' |
| 142 | } |
| 143 | // pepare slug |
| 144 | debug.handlers('POST -- Slug: ' + slug) // alain |
| 145 | if (slug) { |
| 146 | slug = decodeURIComponent(slug) |
| 147 | |
| 148 | if (container) { |
| 149 | // the name of a container cannot be a valid auxiliary resource document |
| 150 | while (this._containsInvalidSuffixes(slug + '/')) { |
| 151 | const idx = slug.lastIndexOf('.') |
| 152 | slug = slug.substr(0, idx) |
| 153 | } |
| 154 | } else if (this.isAuxResource(slug, extension)) throw error(403, 'POST to auxiliary resources is not allowed') |
| 155 | |
| 156 | if (slug.match(/\/|\||:/)) { |
| 157 | throw error(400, 'The name of a POSTed new file may not contain ":" (colon), "|" (pipe), or "/" (slash)') |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | // always return a valid URL. |
| 162 | const resourceUrl = await ldp.getAvailableUrl(hostname, containerPath, { slug, extension, container }) |
| 163 | debug.handlers('POST -- Will create at: ' + resourceUrl) |
| 164 | |
| 165 | await ldp.put(resourceUrl, stream, contentType) |
| 166 | // return urlModule.parse(resourceUrl).path |
| 167 | return new URL(resourceUrl).pathname |
| 168 | } |
| 169 | |
| 170 | isAuxResource (slug, extension) { |
| 171 | let test = false |
no test coverage detected