21 lines
759 B
Dart
21 lines
759 B
Dart
import 'dart:convert';
|
|
|
|
import 'package:html/parser.dart' as html;
|
|
|
|
import '../domain/exam_schedule.dart';
|
|
import '../features/school/school_exam_adapter.dart';
|
|
import '../features/school/undergraduate/exam_adapter.dart';
|
|
|
|
class ExamFileImport {
|
|
static ExamSchedule parse(String content) {
|
|
if (utf8.encode(content).length > 2 * 1024 * 1024)
|
|
throw const FormatException('文件不能超过2MB');
|
|
final doc = html.parse(content.replaceFirst('\uFEFF', ''));
|
|
if (doc.querySelector('#stdExamTableForm') != null)
|
|
return UndergraduateExamAdapter.extract(content);
|
|
if (doc.querySelector('#sample-table-1') != null)
|
|
return SchoolExamAdapter.extract(content);
|
|
throw const FormatException('未识别到学校排考页面');
|
|
}
|
|
}
|