37 lines
1.1 KiB
Dart
37 lines
1.1 KiB
Dart
import '../../data/json_schedule_import.dart';
|
|
import 'school_navigation_policy.dart';
|
|
|
|
class UnsupportedSchoolLayout implements Exception {
|
|
@override
|
|
String toString() => '学校课表识别待联调,当前课表保持不变。';
|
|
}
|
|
|
|
class SchoolPageAdapter {
|
|
ImportDraft extract(String html, Uri source) {
|
|
// A real authenticated timetable fixture is required before registering a parser.
|
|
// Unknown HTML must never erase the student's last valid imported timetable.
|
|
throw UnsupportedSchoolLayout();
|
|
}
|
|
}
|
|
|
|
class SchoolReader {
|
|
SchoolReader(this.adapter);
|
|
final SchoolPageAdapter adapter;
|
|
Future<ImportDraft>? _pending;
|
|
bool get busy => _pending != null;
|
|
Future<ImportDraft> read(Uri origin, Future<String> Function() getHtml) {
|
|
if (_pending != null) return _pending!;
|
|
_pending = Future<ImportDraft>(() async {
|
|
try {
|
|
if (!SchoolNavigationPolicy.isTimetable(origin)) {
|
|
throw UnsupportedSchoolLayout();
|
|
}
|
|
return adapter.extract(await getHtml(), origin);
|
|
} finally {
|
|
_pending = null;
|
|
}
|
|
});
|
|
return _pending!;
|
|
}
|
|
}
|