Skip to content

Commit

Permalink
refactor: send request information for bus debug
Browse files Browse the repository at this point in the history
  • Loading branch information
limwa committed Mar 7, 2024
1 parent bc644d1 commit 126188f
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions uni/lib/controller/fetchers/departures_fetcher.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:html/dom.dart';
import 'package:html/parser.dart';
import 'package:http/io_client.dart' as http;
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/entities/bus.dart';
import 'package:uni/model/entities/bus_stop.dart';
Expand All @@ -26,24 +28,39 @@ class DeparturesFetcher {

final response = await _client.get(url.toUri());
final htmlResponse = parse(response.body);
try {
final scriptText = htmlResponse
.querySelectorAll('table script')
.where((element) => element.text.contains(_stopCode))
.map((e) => e.text)
.first;

final callParam = scriptText
.substring(scriptText.indexOf('('))
.split(',')
.firstWhere((element) => element.contains(')'));

final csrfToken = callParam.substring(
callParam.indexOf("'") + 1,
callParam.lastIndexOf("'"),
);

final scriptText = htmlResponse
.querySelectorAll('table script')
.where((element) => element.text.contains(_stopCode))
.map((e) => e.text)
.first;

final callParam = scriptText
.substring(scriptText.indexOf('('))
.split(',')
.firstWhere((element) => element.contains(')'));

final csrfToken = callParam.substring(
callParam.indexOf("'") + 1,
callParam.lastIndexOf("'"),
);

return csrfToken;
return csrfToken;
} catch (e, stackTrace) {
unawaited(
Sentry.captureEvent(
SentryEvent(
throwable: e,
request: SentryRequest(
url: url,
data: response.body,
),
),
stackTrace: stackTrace,
),
);
rethrow;
}
}

void throwCSRFTokenError() {
Expand Down

0 comments on commit 126188f

Please sign in to comment.