app/lib/common/rust/api/downloader_api.dart
2025-12-05 17:24:52 +08:00

238 lines
7.7 KiB
Dart

// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.11.1.
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
import '../frb_generated.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
// These functions are ignored because they are not marked as `pub`: `get_session`, `get_task_status`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `clone`, `clone`, `eq`, `fmt`, `fmt`, `fmt`
/// Initialize the download manager session with persistence enabled
///
/// Parameters:
/// - working_dir: The directory to store session data (persistence, DHT, etc.)
/// - default_download_dir: The default directory to store downloads
/// - upload_limit_bps: Upload speed limit in bytes per second (0 = unlimited)
/// - download_limit_bps: Download speed limit in bytes per second (0 = unlimited)
Future<void> downloaderInit({
required String workingDir,
required String defaultDownloadDir,
int? uploadLimitBps,
int? downloadLimitBps,
}) => RustLib.instance.api.crateApiDownloaderApiDownloaderInit(
workingDir: workingDir,
defaultDownloadDir: defaultDownloadDir,
uploadLimitBps: uploadLimitBps,
downloadLimitBps: downloadLimitBps,
);
/// Check if the downloader is initialized
bool downloaderIsInitialized() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderIsInitialized();
/// Add a torrent from bytes (e.g., .torrent file content)
Future<BigInt> downloaderAddTorrent({
required List<int> torrentBytes,
String? outputFolder,
List<String>? trackers,
}) => RustLib.instance.api.crateApiDownloaderApiDownloaderAddTorrent(
torrentBytes: torrentBytes,
outputFolder: outputFolder,
trackers: trackers,
);
/// Add a torrent from a magnet link
Future<BigInt> downloaderAddMagnet({
required String magnetLink,
String? outputFolder,
List<String>? trackers,
}) => RustLib.instance.api.crateApiDownloaderApiDownloaderAddMagnet(
magnetLink: magnetLink,
outputFolder: outputFolder,
trackers: trackers,
);
/// Add a torrent from URL (HTTP download not supported, only torrent file URLs)
Future<BigInt> downloaderAddUrl({
required String url,
String? outputFolder,
List<String>? trackers,
}) => RustLib.instance.api.crateApiDownloaderApiDownloaderAddUrl(
url: url,
outputFolder: outputFolder,
trackers: trackers,
);
/// Pause a download task
Future<void> downloaderPause({required BigInt taskId}) =>
RustLib.instance.api.crateApiDownloaderApiDownloaderPause(taskId: taskId);
/// Resume a download task
Future<void> downloaderResume({required BigInt taskId}) =>
RustLib.instance.api.crateApiDownloaderApiDownloaderResume(taskId: taskId);
/// Remove a download task
Future<void> downloaderRemove({
required BigInt taskId,
required bool deleteFiles,
}) => RustLib.instance.api.crateApiDownloaderApiDownloaderRemove(
taskId: taskId,
deleteFiles: deleteFiles,
);
/// Get information about a specific task
Future<DownloadTaskInfo> downloaderGetTaskInfo({required BigInt taskId}) =>
RustLib.instance.api.crateApiDownloaderApiDownloaderGetTaskInfo(
taskId: taskId,
);
/// Get all tasks
Future<List<DownloadTaskInfo>> downloaderGetAllTasks() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderGetAllTasks();
/// Get global statistics
Future<DownloadGlobalStat> downloaderGetGlobalStats() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderGetGlobalStats();
/// Check if a task with given name exists
Future<bool> downloaderIsNameInTask({required String name}) => RustLib
.instance
.api
.crateApiDownloaderApiDownloaderIsNameInTask(name: name);
/// Pause all tasks
Future<void> downloaderPauseAll() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderPauseAll();
/// Resume all tasks
Future<void> downloaderResumeAll() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderResumeAll();
/// Stop the downloader session (pauses all tasks but keeps session)
Future<void> downloaderStop() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderStop();
/// Shutdown the downloader session completely (allows restart with new settings)
Future<void> downloaderShutdown() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderShutdown();
/// Update global speed limits
/// Note: rqbit Session doesn't support runtime limit changes,
/// this function is a placeholder that returns an error.
/// Speed limits should be set during downloader_init.
Future<void> downloaderUpdateSpeedLimits({
int? uploadLimitBps,
int? downloadLimitBps,
}) => RustLib.instance.api.crateApiDownloaderApiDownloaderUpdateSpeedLimits(
uploadLimitBps: uploadLimitBps,
downloadLimitBps: downloadLimitBps,
);
/// Remove all completed tasks (equivalent to aria2's --seed-time=0 behavior)
Future<int> downloaderRemoveCompletedTasks() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderRemoveCompletedTasks();
/// Check if there are any active (non-completed) tasks
Future<bool> downloaderHasActiveTasks() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderHasActiveTasks();
/// Global statistics
class DownloadGlobalStat {
final BigInt downloadSpeed;
final BigInt uploadSpeed;
final BigInt numActive;
final BigInt numWaiting;
const DownloadGlobalStat({
required this.downloadSpeed,
required this.uploadSpeed,
required this.numActive,
required this.numWaiting,
});
static Future<DownloadGlobalStat> default_() =>
RustLib.instance.api.crateApiDownloaderApiDownloadGlobalStatDefault();
@override
int get hashCode =>
downloadSpeed.hashCode ^
uploadSpeed.hashCode ^
numActive.hashCode ^
numWaiting.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is DownloadGlobalStat &&
runtimeType == other.runtimeType &&
downloadSpeed == other.downloadSpeed &&
uploadSpeed == other.uploadSpeed &&
numActive == other.numActive &&
numWaiting == other.numWaiting;
}
/// Download task information
class DownloadTaskInfo {
final BigInt id;
final String name;
final DownloadTaskStatus status;
final BigInt totalBytes;
final BigInt downloadedBytes;
final BigInt uploadedBytes;
final BigInt downloadSpeed;
final BigInt uploadSpeed;
final double progress;
final BigInt numPeers;
final String outputFolder;
const DownloadTaskInfo({
required this.id,
required this.name,
required this.status,
required this.totalBytes,
required this.downloadedBytes,
required this.uploadedBytes,
required this.downloadSpeed,
required this.uploadSpeed,
required this.progress,
required this.numPeers,
required this.outputFolder,
});
@override
int get hashCode =>
id.hashCode ^
name.hashCode ^
status.hashCode ^
totalBytes.hashCode ^
downloadedBytes.hashCode ^
uploadedBytes.hashCode ^
downloadSpeed.hashCode ^
uploadSpeed.hashCode ^
progress.hashCode ^
numPeers.hashCode ^
outputFolder.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is DownloadTaskInfo &&
runtimeType == other.runtimeType &&
id == other.id &&
name == other.name &&
status == other.status &&
totalBytes == other.totalBytes &&
downloadedBytes == other.downloadedBytes &&
uploadedBytes == other.uploadedBytes &&
downloadSpeed == other.downloadSpeed &&
uploadSpeed == other.uploadSpeed &&
progress == other.progress &&
numPeers == other.numPeers &&
outputFolder == other.outputFolder;
}
/// Download task status
enum DownloadTaskStatus { initializing, live, paused, error, finished }