fix: harden school imports and add optional feedback diagnostics
This commit is contained in:
@@ -102,6 +102,7 @@ class FeedbackSubmission {
|
||||
this.contact,
|
||||
this.school,
|
||||
this.attachments = const [],
|
||||
this.diagnosticLog,
|
||||
});
|
||||
|
||||
factory FeedbackSubmission.problem({
|
||||
@@ -110,18 +111,26 @@ class FeedbackSubmission {
|
||||
String? contact,
|
||||
List<FeedbackAttachment> attachments = const [],
|
||||
FeedbackLimits limits = FeedbackLimits.defaults,
|
||||
Uint8List? diagnosticLog,
|
||||
}) {
|
||||
final text = message.trim();
|
||||
if (text.isEmpty) throw const FeedbackException('请填写问题或建议');
|
||||
if (text.length > 5000) throw const FeedbackException('问题或建议不能超过 5000 个字符');
|
||||
_validateContact(contact);
|
||||
validateAttachments(attachments, limits);
|
||||
if (diagnosticLog != null &&
|
||||
(diagnosticLog.isEmpty || diagnosticLog.length > 256 * 1024)) {
|
||||
throw const FeedbackException('日志附件不能超过256 KB');
|
||||
}
|
||||
return FeedbackSubmission._(
|
||||
id: id,
|
||||
kind: FeedbackKind.problem,
|
||||
message: text,
|
||||
contact: _optional(contact),
|
||||
attachments: List.unmodifiable(attachments),
|
||||
diagnosticLog: diagnosticLog == null
|
||||
? null
|
||||
: Uint8List.fromList(diagnosticLog).asUnmodifiableView(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -151,6 +160,7 @@ class FeedbackSubmission {
|
||||
final String? contact;
|
||||
final String? school;
|
||||
final List<FeedbackAttachment> attachments;
|
||||
final Uint8List? diagnosticLog;
|
||||
|
||||
static String newId() {
|
||||
final random = Random.secure();
|
||||
|
||||
Reference in New Issue
Block a user