mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-03-11 21:35:32 +00:00
33 lines
1.1 KiB
Dart
33 lines
1.1 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:mangayomi/main.dart';
|
|
import 'package:mangayomi/models/settings.dart';
|
|
import 'package:mangayomi/services/http_service/cloudflare/providers/cookie_providers.dart';
|
|
import 'package:mangayomi/sources/utils/utils.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
part 'headers.g.dart';
|
|
|
|
@riverpod
|
|
Map<String, String> headers(HeadersRef ref,
|
|
{required String source, required String lang}) {
|
|
final sourceM = getSource(lang, source);
|
|
|
|
if (sourceM == null) return {};
|
|
|
|
if (sourceM.headers!.isEmpty && !sourceM.hasCloudflare!) return {};
|
|
|
|
Map<String, String> newHeaders = {};
|
|
if (sourceM.headers!.isNotEmpty) {
|
|
final headers = jsonDecode(sourceM.headers!) as Map;
|
|
newHeaders =
|
|
headers.map((key, value) => MapEntry(key.toString(), value.toString()));
|
|
}
|
|
|
|
if (sourceM.hasCloudflare!) {
|
|
final userAgent = isar.settings.getSync(227)!.userAgent!;
|
|
final cookie = ref.watch(cookieStateProvider(sourceM.id.toString()));
|
|
|
|
newHeaders.addAll({'User-Agent': userAgent, "Cookie": cookie});
|
|
}
|
|
return newHeaders;
|
|
}
|