(request, response, log, callback)
| 1121 | } |
| 1122 | |
| 1123 | function completeMultipartUpload(request, response, log, callback) { |
| 1124 | const err = _checkMultipleBackendRequest(request, log); |
| 1125 | if (err) { |
| 1126 | return callback(err); |
| 1127 | } |
| 1128 | const storageLocation = request.headers['x-scal-storage-class']; |
| 1129 | const sourceVersionId = request.headers['x-scal-version-id']; |
| 1130 | const uploadId = request.headers['x-scal-upload-id']; |
| 1131 | const userMetadata = request.headers['x-scal-user-metadata']; |
| 1132 | const contentType = request.headers['x-scal-content-type']; |
| 1133 | const cacheControl = request.headers['x-scal-cache-control']; |
| 1134 | const contentDisposition = request.headers['x-scal-content-disposition']; |
| 1135 | const contentEncoding = request.headers['x-scal-content-encoding']; |
| 1136 | const tags = request.headers['x-scal-tags']; |
| 1137 | const data = []; |
| 1138 | let totalLength = 0; |
| 1139 | request.on('data', chunk => { |
| 1140 | totalLength += chunk.length; |
| 1141 | data.push(chunk); |
| 1142 | }); |
| 1143 | request.on('end', () => { |
| 1144 | let parts; |
| 1145 | try { |
| 1146 | parts = JSON.parse(Buffer.concat(data), totalLength); |
| 1147 | } catch { |
| 1148 | // FIXME: add error type MalformedJSON |
| 1149 | return callback(errors.MalformedPOSTRequest); |
| 1150 | } |
| 1151 | const partList = getPartList(parts, request.objectKey, uploadId, storageLocation); |
| 1152 | // Azure client will set user metadata at this point. |
| 1153 | const metaHeaders = { 'x-amz-meta-scal-replication-status': 'REPLICA' }; |
| 1154 | if (sourceVersionId) { |
| 1155 | metaHeaders['x-amz-meta-scal-version-id'] = sourceVersionId; |
| 1156 | } |
| 1157 | if (userMetadata !== undefined) { |
| 1158 | try { |
| 1159 | const metaData = JSON.parse(userMetadata); |
| 1160 | Object.assign(metaHeaders, metaData); |
| 1161 | } catch { |
| 1162 | // FIXME: add error type MalformedJSON |
| 1163 | return callback(errors.MalformedPOSTRequest); |
| 1164 | } |
| 1165 | } |
| 1166 | // Azure does not have a notion of initiating an MPU, so we put any |
| 1167 | // tagging fields during the complete MPU if using Azure. |
| 1168 | let tagging; |
| 1169 | if (tags !== undefined) { |
| 1170 | try { |
| 1171 | const parsedTags = JSON.parse(request.headers['x-scal-tags']); |
| 1172 | tagging = querystring.stringify(parsedTags); |
| 1173 | } catch { |
| 1174 | // FIXME: add error type MalformedJSON |
| 1175 | return callback(errors.MalformedPOSTRequest); |
| 1176 | } |
| 1177 | } |
| 1178 | const contentSettings = { |
| 1179 | contentType: contentType || undefined, |
| 1180 | cacheControl: cacheControl || undefined, |
no test coverage detected