From 9a61f948edfeb5ff9504f235973c583395e03616 Mon Sep 17 00:00:00 2001 From: pratikbaid3 Date: Sun, 8 Aug 2021 15:56:23 +0530 Subject: [PATCH] feat: Added ability to check torrent hash --- lib/Api/torrent_api.dart | 30 ++++++++++++++++++++++++++++++ lib/Components/torrent_tile.dart | 18 ++++-------------- lib/Provider/api_provider.dart | 1 + 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/Api/torrent_api.dart b/lib/Api/torrent_api.dart index a3d2b0fe..31f0c984 100644 --- a/lib/Api/torrent_api.dart +++ b/lib/Api/torrent_api.dart @@ -302,4 +302,34 @@ class TorrentApi { print(e.toString()); } } + + static Future checkTorrentHash( + {List hashes, BuildContext context}) async { + try { + String url = Provider.of(context, listen: false).baseUrl + + ApiProvider.checkHash; + print('---CHECK TORRENT HASH---'); + print(url); + Response response; + Dio dio = new Dio(); + //Headers + dio.options.headers['Accept'] = "application/json"; + dio.options.headers['Content-Type'] = "application/json"; + dio.options.headers['Connection'] = "keep-alive"; + dio.options.headers['Cookie'] = + Provider.of(context, listen: false).token; + Map mp = Map(); + mp['hashes'] = hashes; + String rawBody = json.encode(mp); + response = await dio.post( + url, + data: rawBody, + ); + if (response.statusCode == 200) { + } else {} + } catch (e) { + print('--ERROR--'); + print(e.toString()); + } + } } diff --git a/lib/Components/torrent_tile.dart b/lib/Components/torrent_tile.dart index e8d0b3a2..5a87ac06 100644 --- a/lib/Components/torrent_tile.dart +++ b/lib/Components/torrent_tile.dart @@ -61,19 +61,6 @@ class _TorrentTileState extends State { menuItemExtent: 60, onPressed: () {}, menuItems: [ - FocusedMenuItem( - title: Text( - 'Torrent Details', - style: TextStyle( - color: Colors.black, - ), - ), - trailingIcon: Icon( - Icons.info_outline, - color: Colors.black, - ), - onPressed: () {}, - ), FocusedMenuItem( title: Text( 'Set Tags', @@ -99,7 +86,10 @@ class _TorrentTileState extends State { Icons.tag, color: Colors.black, ), - onPressed: () {}, + onPressed: () { + TorrentApi.checkTorrentHash( + hashes: [widget.model.hash], context: context); + }, ), FocusedMenuItem( backgroundColor: Colors.redAccent, diff --git a/lib/Provider/api_provider.dart b/lib/Provider/api_provider.dart index a1432e32..fc0f8dfb 100644 --- a/lib/Provider/api_provider.dart +++ b/lib/Provider/api_provider.dart @@ -28,6 +28,7 @@ class ApiProvider extends ChangeNotifier { //api/notifications?id=notification-tooltip&limit=10&start=0 static String notifications = '/api/notifications'; + static String checkHash = '/api/torrents/check-hash'; Future setBaseUrl(String url) async { baseUrl = url;