Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update version to 1.0.7 #14

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.0.7
- Fix convert tracker tier empty string to nul

## 1.0.6
- Add `SyncController.subscribeTorrentPeersData`
- Add `TorrentsController.subscribeWebSeeds`
Expand Down
2 changes: 0 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ linter:
rules:
- always_declare_return_types
- always_put_control_body_on_new_line
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_bool_literals_in_conditional_expressions
- avoid_catching_errors
Expand All @@ -24,7 +23,6 @@ linter:
- avoid_relative_lib_imports
- avoid_renaming_method_parameters
- avoid_return_types_on_setters
- avoid_returning_null_for_future
- avoid_returning_null_for_void
- avoid_returning_this
- avoid_setters_without_getters
Expand Down
2 changes: 1 addition & 1 deletion lib/src/v2/qbittorrent_api_v2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:qbittorrent_api/src/v2/transfer/transfer_controller.dart';

class QBittorrentApiV2 {
/// Class for qBittorrent API v2.
/// [baseUrl - The base url of the qBittorrent server.
/// [baseUrl] - The base url of the qBittorrent server.
/// [cookiePath] - The path to the cookie file. Set null for Flutter Web application.
/// [connectTimeout] - Timeout for [ApiClient] to connect to the server.
/// [receiveTimeout] - Timeout for [ApiClient] to receive data.
Expand Down
2 changes: 2 additions & 0 deletions lib/src/v2/torrents/dto/tracker.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:qbittorrent_api/src/v2/torrents/dto/tracker_status.dart';
import 'package:qbittorrent_api/src/v2/utils/empty_string_converter.dart';

part 'tracker.g.dart';

Expand Down Expand Up @@ -32,6 +33,7 @@ class Tracker {
/// Tier numbers are valid when >= 0, < 0 is used as placeholder when tier
/// does not exist for special entries (such as DHT).
@JsonKey(name: 'tier')
@EmptyStringToInt()
final int? tier;

/// Number of peers for current torrent, as reported by the tracker
Expand Down
4 changes: 2 additions & 2 deletions lib/src/v2/torrents/dto/tracker.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions lib/src/v2/utils/empty_string_converter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:json_annotation/json_annotation.dart';

/// Convert empty string to nullable int type.
class EmptyStringToInt implements JsonConverter<int?, dynamic> {
const EmptyStringToInt();

@override
int? fromJson(dynamic json) {
if (json is String) {
return json.isEmpty ? null : int.tryParse(json);
} else if (json is int) {
return json;
}
return null;
}

@override
dynamic toJson(int? object) {
return object;
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: qbittorrent_api
description: This package provides methods for making requests to qBittorrent Web API using Dart.
version: 1.0.6
version: 1.0.7
repository: https://github.com/yosemiteyss/qbittorrent_api

environment:
Expand Down
29 changes: 29 additions & 0 deletions test/v2/torrents/torrents_controller_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,35 @@ void main() {
expect(trackers[0].url, 'udp://tracker.openbittorrent.com:80/announce');
});

test('getTrackers should convert tier empty string to null', () async {
fakeApiClient.setResponse('''
[
{
"msg": "",
"num_downloaded": -1,
"num_leeches": -1,
"num_peers": -1,
"num_seeds": -1,
"status": 1,
"tier": "",
"url": "udp://tracker.openbittorrent.com:80/announce"
}
]
''', isJson: true);
final trackers = await torrentsController.getTrackers(
hash: 'd984f67af9917b214cd8b6048ab5624c7df6a07a',
);
expect(trackers.length, 1);
expect(trackers[0].msg, '');
expect(trackers[0].numDownloaded, -1);
expect(trackers[0].numLeeches, -1);
expect(trackers[0].numPeers, -1);
expect(trackers[0].numSeeds, -1);
expect(trackers[0].status, TrackerStatus.notContacted);
expect(trackers[0].tier, null);
expect(trackers[0].url, 'udp://tracker.openbittorrent.com:80/announce');
});

test('getWebSeeds returns a list of web seeds', () async {
fakeApiClient.setResponse('''
[
Expand Down
9 changes: 9 additions & 0 deletions test/v2/utils/empty_string_converter_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:qbittorrent_api/src/v2/utils/empty_string_converter.dart';
import 'package:test/test.dart';

void main() {
test('fromJson should convert empty string to null', () {
const converter = EmptyStringToInt();
expect(null, converter.fromJson(''));
});
}