implemented content blocking

This commit is contained in:
Fabian Freund
2024-06-19 21:08:18 +02:00
parent 2f6ae2684d
commit 2bacbbffd2
18 changed files with 1301 additions and 0 deletions
@@ -0,0 +1,44 @@
import 'dart:convert';
import 'package:bang_navigator/core/http_error_handler.dart';
import 'package:collection/collection.dart';
import 'package:exceptions/exceptions.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'source.g.dart';
@Riverpod()
class HostSourceService extends _$HostSourceService {
late http.Client _client;
@override
void build() {
_client = http.Client();
}
Future<Result<Set<String>>> getHosts(Uri url) async {
return Result.fromAsync(
() async {
final response = await _client.get(url);
return await compute(
(args) {
final hostRegex = RegExp(
r'^\s*([0-9a-fA-F:.]+)\s+(\S+)',
multiLine: true,
);
final matches = hostRegex.allMatches(utf8.decode(args[0]));
return matches
.map((match) => match.group(2))
.whereNotNull()
.toSet();
},
[response.bodyBytes],
);
},
exceptionHandler: handleHttpError,
);
}
}
@@ -0,0 +1,26 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'source.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
String _$hostSourceServiceHash() => r'26ac09fcd34cc37440eb643075984707e0e9bba3';
/// See also [HostSourceService].
@ProviderFor(HostSourceService)
final hostSourceServiceProvider =
AutoDisposeNotifierProvider<HostSourceService, void>.internal(
HostSourceService.new,
name: r'hostSourceServiceProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$hostSourceServiceHash,
dependencies: null,
allTransitiveDependencies: null,
);
typedef _$HostSourceService = AutoDisposeNotifier<void>;
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member