* Builds Veeam file data (XML content + response metadata) for a given request. * * @param {object} request - incoming request * @param {object} bucketMd - bucket metadata from the router * @param {object} log - logger object * @returns {Promise } result with { xmlContent, dataBuffer, mo
(request, bucketMd, log)
| 259 | * @returns {Promise<object>} result with { xmlContent, dataBuffer, modified, bucketData } |
| 260 | */ |
| 261 | async function buildVeeamFileData(request, bucketMd, log) { |
| 262 | let data; |
| 263 | try { |
| 264 | data = await getBucket(request.bucketName, log); |
| 265 | } catch { |
| 266 | log.error('error fetching bucket metadata', { bucket: request.bucketName }); |
| 267 | throw errors.InternalError; |
| 268 | } |
| 269 | |
| 270 | const fileToBuild = getFileToBuild(request, data._capabilities?.VeeamSOSApi); |
| 271 | |
| 272 | if (fileToBuild.error) { |
| 273 | throw fileToBuild.error; |
| 274 | } |
| 275 | |
| 276 | let bucketMetrics; |
| 277 | if (!isSystemXML(request.objectKey)) { |
| 278 | try { |
| 279 | bucketMetrics = await fetchCapacityMetrics(bucketMd, request, log); |
| 280 | } catch { |
| 281 | log.error('error fetching capacity metrics for bucket', { bucket: request.bucketName }); |
| 282 | throw errors.InternalError; |
| 283 | } |
| 284 | } else { |
| 285 | bucketMetrics = { date: new Date() }; |
| 286 | } |
| 287 | |
| 288 | const modified = bucketMetrics.date; |
| 289 | if (bucketMetrics.bytesTotal !== undefined |
| 290 | && fileToBuild.value.CapacityInfo |
| 291 | && !fileToBuild.value.CapacityInfo.Used) { |
| 292 | fileToBuild.value.CapacityInfo.Used = Number(bucketMetrics.bytesTotal); |
| 293 | fileToBuild.value.CapacityInfo.Available = |
| 294 | Number(fileToBuild.value.CapacityInfo.Capacity) - Number(bucketMetrics.bytesTotal); |
| 295 | // TODO CLDSRV-633 when SUR backend supports realtime metrics: it will |
| 296 | // report the real last cseq/date processed by SUR, instead of the current date, |
| 297 | // ensuring no issue in a SOSAPI context. We should use this information. |
| 298 | } |
| 299 | |
| 300 | const xmlContent = buildXML(fileToBuild.value); |
| 301 | const dataBuffer = Buffer.from(xmlContent); |
| 302 | return { xmlContent, dataBuffer, modified, bucketData: data }; |
| 303 | } |
| 304 | |
| 305 | module.exports = { |
| 306 | _decodeURI, |
no test coverage detected