/**
* Copyright (C) 2024 Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
/**
* Launches a download process for an item, tracking its progress and handling success or error states.
* The function returns a promise that resolves with the downloaded item or rejects in case of an error.
* It uses XMLHttpRequest to manage the download and tracks progress both for the individual item and the entire batch it belongs to.
*
* @param {Object} options - Configuration options for the download process.
* @param {string} options.url - The URL from which the item will be downloaded.
* @param {string} options.operation_id - Unique identifier for the download operation, used for progress tracking.
* @param {string} options.item_upload_id - Identifier for the specific item being downloaded, used for individual progress tracking.
* @param {string} [options.name] - Optional name for the item being downloaded.
* @param {string} [options.dest_path] - Destination path for the downloaded item.
* @param {string} [options.shortcut_to] - Optional shortcut path for the item.
* @param {boolean} [options.dedupe_name=false] - Flag to enable or disable deduplication of item names.
* @param {boolean} [options.overwrite=false] - Flag to enable or disable overwriting of existing items.
* @param {function} [options.success] - Optional callback function that is executed on successful download.
* @param {function} [options.error] - Optional callback function that is executed in case of an error.
* @param {number} [options.return_timeout=500] - Optional timeout in milliseconds before resolving the download.
* @returns {Promise