updated the sheet

This commit is contained in:
2026-08-28 18:16:28 +05:30
parent 69f4f3e909
commit 074cc0eccf
43 changed files with 2617 additions and 1201 deletions

View File

@@ -1,67 +1,25 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart';
import 'package:http/io_client.dart';
import 'package:http/http.dart' as http;
import 'package:miler/data/api_config.dart';
import 'package:flutter/foundation.dart';
// Combined Deliverylog providers:
/// Hardcoded known-good IPs for hosts where carrier DNS returns broken CDN nodes.
/// Confirmed: 66.116.225.226 = 200 OK, 125.21.240.67 = 404/405.
/// Empty since the delivery line moved to Doormile — see the note on the
/// matching map in `providers/Riderlog/riderlog_provider.dart`. The old entry
/// pinned `queue.workolik.com`, a host nothing calls now, and must not be
/// re-pointed at `api.doormile.com`.
const _knownGoodIPs = <String, String>{};
/// Creates an IOClient that:
/// 1. Bypasses SSL certificate errors
/// 2. Forces known-good IPs to avoid broken CDN nodes from carrier DNS
/// 3. Manually does TLS upgrade with correct SNI (hostname, not IP)
IOClient _buildSslBypassClient() {
final httpClient = HttpClient()
..badCertificateCallback = (X509Certificate cert, String host, int port) =>
true;
httpClient
.connectionFactory = (Uri uri, String? proxyHost, int? proxyPort) async {
final host = uri.host;
final port = uri.port;
InternetAddress? target;
final knownIP = _knownGoodIPs[host];
if (knownIP != null) {
target = InternetAddress(knownIP);
} else {
try {
final addresses = await InternetAddress.lookup(
host,
type: InternetAddressType.IPv4,
);
if (addresses.isNotEmpty) target = addresses.first;
} catch (_) {}
}
if (uri.scheme == 'https') {
final socketFuture = Socket.connect(target ?? InternetAddress(host), port)
.then(
(plain) => SecureSocket.secure(
plain,
host: host,
onBadCertificate: (_) => true,
supportedProtocols: ['http/1.1'],
),
)
.then((s) => s as Socket);
return ConnectionTask.fromSocket<Socket>(socketFuture, () {});
}
return Socket.startConnect(target ?? InternetAddress(host), port);
};
return IOClient(httpClient);
}
/// ── The SSL bypass is gone ──
///
/// This file built its own `IOClient` with `onBadCertificate: (_) => true` and
/// a hand-rolled `SecureSocket` upgrade, so **every certificate was accepted**
/// — a delivery rider's position, his order ids and his session were readable
/// and rewritable by anything on the path. The parcel line deleted the same
/// code (see `providers/Riderlog/riderlog_provider.dart`); the delivery line
/// kept it because nothing in `lib/` imported this file directly.
///
/// It also sent **no `Authorization` header**. The URLs it posts to are v1
/// routes on `api.doormile.com` — resolved through the [DeliveryApi] facade —
/// so every one of these calls could only ever have been answered with a 401.
/// A plain client plus [ApiConfig.authHeaders] fixes both at once.
Future<Map<String, String>> _headers() => ApiConfig.authHeaders();
class CreateDeliveryLogProvider {
Future<Map<String, dynamic>?> createDeliveryLog(
@@ -70,19 +28,12 @@ class CreateDeliveryLogProvider {
bool wrapInArray = true,
}) async {
Map<String, dynamic>? result;
final client = _buildSslBypassClient();
final client = http.Client();
try {
final url = Uri.parse(urldata);
final body = json.encode(wrapInArray ? [data] : data);
final response = await client
.post(
url,
body: body,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
)
.post(url, body: body, headers: await _headers())
.timeout(const Duration(seconds: 10));
debugPrint('createDeliveryLog url $urldata');
debugPrint(body);
@@ -110,18 +61,11 @@ class UpdateDeliveryProvider {
String urldata,
) async {
Map<String, dynamic>? updateDeliveryResponse;
final client = _buildSslBypassClient();
final client = http.Client();
try {
final url = Uri.parse(urldata);
final response = await client
.put(
url,
body: json.encode(data),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
)
.put(url, body: json.encode(data), headers: await _headers())
.timeout(const Duration(seconds: 10));
debugPrint('updateDelivery url $urldata');
debugPrint('updateDelivery status ${response.statusCode}');
@@ -148,18 +92,11 @@ class UpdateDeliveryProvider {
String urldata,
) async {
Map<String, dynamic>? updateDeliveryResponse;
final client = _buildSslBypassClient();
final client = http.Client();
try {
final url = Uri.parse(urldata);
final response = await client
.put(
url,
body: json.encode(data),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
)
.put(url, body: json.encode(data), headers: await _headers())
.timeout(const Duration(seconds: 10));
debugPrint('updateArrived url $urldata');
debugPrint('updateArrived status ${response.statusCode}');
@@ -185,18 +122,11 @@ class UpdateDeliveryProvider {
String urldata,
) async {
Map<String, dynamic>? updateDeliveryResponse;
final client = _buildSslBypassClient();
final client = http.Client();
try {
final url = Uri.parse(urldata);
final response = await client
.put(
url,
body: json.encode(data),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
)
.put(url, body: json.encode(data), headers: await _headers())
.timeout(const Duration(seconds: 10));
debugPrint('updatePicked url $urldata');
debugPrint('updatePicked status ${response.statusCode}');
@@ -222,18 +152,11 @@ class UpdateDeliveryProvider {
String urldata,
) async {
Map<String, dynamic>? updateDeliveryResponse;
final client = _buildSslBypassClient();
final client = http.Client();
try {
final url = Uri.parse(urldata);
final response = await client
.put(
url,
body: json.encode(data),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
)
.put(url, body: json.encode(data), headers: await _headers())
.timeout(const Duration(seconds: 10));
debugPrint('updateActive url $urldata');
debugPrint('updateActive status ${response.statusCode}');
@@ -258,7 +181,7 @@ class UpdateDeliveryProvider {
class GetDeliveryLogProvider {
Future<Map<String, dynamic>?> getDeliveryLog(String urldata) async {
Map<String, dynamic>? result;
final client = _buildSslBypassClient();
final client = http.Client();
try {
final url = Uri.parse(urldata);
final response = await client.get(