Skip to content

Commit 25c77c6

Browse files
authored
Merge pull request #20 from CCExtractor/develop
Added ability to check torrent hash
2 parents 780c911 + 9a61f94 commit 25c77c6

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

lib/Api/torrent_api.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,34 @@ class TorrentApi {
302302
print(e.toString());
303303
}
304304
}
305+
306+
static Future<void> checkTorrentHash(
307+
{List<String> hashes, BuildContext context}) async {
308+
try {
309+
String url = Provider.of<ApiProvider>(context, listen: false).baseUrl +
310+
ApiProvider.checkHash;
311+
print('---CHECK TORRENT HASH---');
312+
print(url);
313+
Response response;
314+
Dio dio = new Dio();
315+
//Headers
316+
dio.options.headers['Accept'] = "application/json";
317+
dio.options.headers['Content-Type'] = "application/json";
318+
dio.options.headers['Connection'] = "keep-alive";
319+
dio.options.headers['Cookie'] =
320+
Provider.of<UserDetailProvider>(context, listen: false).token;
321+
Map<String, dynamic> mp = Map();
322+
mp['hashes'] = hashes;
323+
String rawBody = json.encode(mp);
324+
response = await dio.post(
325+
url,
326+
data: rawBody,
327+
);
328+
if (response.statusCode == 200) {
329+
} else {}
330+
} catch (e) {
331+
print('--ERROR--');
332+
print(e.toString());
333+
}
334+
}
305335
}

lib/Components/torrent_tile.dart

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,6 @@ class _TorrentTileState extends State<TorrentTile> {
6161
menuItemExtent: 60,
6262
onPressed: () {},
6363
menuItems: [
64-
FocusedMenuItem(
65-
title: Text(
66-
'Torrent Details',
67-
style: TextStyle(
68-
color: Colors.black,
69-
),
70-
),
71-
trailingIcon: Icon(
72-
Icons.info_outline,
73-
color: Colors.black,
74-
),
75-
onPressed: () {},
76-
),
7764
FocusedMenuItem(
7865
title: Text(
7966
'Set Tags',
@@ -99,7 +86,10 @@ class _TorrentTileState extends State<TorrentTile> {
9986
Icons.tag,
10087
color: Colors.black,
10188
),
102-
onPressed: () {},
89+
onPressed: () {
90+
TorrentApi.checkTorrentHash(
91+
hashes: [widget.model.hash], context: context);
92+
},
10393
),
10494
FocusedMenuItem(
10595
backgroundColor: Colors.redAccent,

lib/Provider/api_provider.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ApiProvider extends ChangeNotifier {
2828

2929
//api/notifications?id=notification-tooltip&limit=10&start=0
3030
static String notifications = '/api/notifications';
31+
static String checkHash = '/api/torrents/check-hash';
3132

3233
Future<void> setBaseUrl(String url) async {
3334
baseUrl = url;

0 commit comments

Comments
 (0)