mangayomi/lib/services/http_service/cloudflare/cookie.dart
2023-07-07 22:38:49 +01:00

31 lines
1.1 KiB
Dart

import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:mangayomi/services/http_service/cloudflare/providers/cookie_providers.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'cookie.g.dart';
@riverpod
Future setCookie(SetCookieRef ref, String sourceId, String url) async {
CookieManager cookie = CookieManager.instance();
final cookies =
await cookie.getCookies(url: WebUri.uri(Uri.parse(url.toString())));
final newCookie =
cookies.where((element) => element.name == "cf_clearance").toList();
if (newCookie.isNotEmpty) {
ref
.read(cookieStateProvider(sourceId).notifier)
.setCookie("cf_clearance=${newCookie.first.value};");
}
}
Future setCookieB(String sourceId, String url) async {
CookieManager cookie = CookieManager.instance();
final cookies =
await cookie.getCookies(url: WebUri.uri(Uri.parse(url.toString())));
final newCookie =
cookies.where((element) => element.name == "cf_clearance").toList();
if (newCookie.isNotEmpty) {
setCookieB("cf_clearance=${newCookie.first.value};", sourceId);
}
}