export function getStoragePathToExecution()

in packages/synthetics-sdk-broken-links/src/link_utils.ts [338:368]


export function getStoragePathToExecution(
  storageParams: StorageParameters,
  options: BrokenLinksResultV1_BrokenLinkCheckerOptions
) {
  try {
    const storageLocation = options.screenshot_options!.storage_location;
    let writeDestination = '';

    // extract folder name for a given storage location. If there is no '/'
    // present then the storageLocation is just a folder
    const firstSlashIndex = storageLocation.indexOf('/');
    if (firstSlashIndex !== -1) {
      writeDestination = storageLocation.substring(firstSlashIndex + 1);
    }

    // Ensure writeDestination ends with a slash for proper path joining
    if (writeDestination && !writeDestination.endsWith('/')) {
      writeDestination += '/';
    }

    writeDestination = path.join(
      writeDestination,
      storageParams.checkId,
      storageParams.executionId
    );

    return writeDestination;
  } catch (err) {
    return '';
  }
}