## 后端安全加固 - 新增 UserUploadPathResolver: 用户上传文件路径安全解析, 防目录穿越 - LocalReportFileStorage: 文件存储路径安全加固 - local_account_file_cleanup: 账号删除时文件清理逻辑增强 - AuthService: 认证逻辑增强 - file_endpoints / report_endpoints: 文件访问接口安全加固 - ai_chat_endpoints / doctor_endpoints: 接口安全调整 - Program.cs: 服务注册调整 ## 前端认证与媒体 - 新增 authenticated_network_image.dart: 带认证的图片加载组件 - auth_provider: 认证状态管理大幅增强(+173) - api_client: 网络客户端增强(+124) - chat_provider: 聊天 provider 重构(+76) - omron_device_provider: 蓝牙设备 provider 增强(+53) - sse_handler: SSE 处理增强(+35) - consultation_provider / data_providers / conversation_history_provider: 调整 ## 页面调整 - remaining_pages: 健康档案/饮食记录等页面增强(+115) - home_page / chat_messages_view: 主页微调 - doctor 端多页微调(consultations/dashboard/followups/patient_detail/profile/report_detail/reports) - report_pages / settings_pages / notification_prefs_page: 微调 - device_scan_page / diet_capture_page / admin_home_page: 微调 ## 测试 - 新增 file_path_security_tests: 文件路径安全测试 - 新增 protected_media_url_test: 媒体URL保护测试 - 新增 user_session_identity_test: 用户会话身份测试 - account_deletion_tests / application_service_tests / auth_tests: 更新
116 lines
3.2 KiB
Dart
116 lines
3.2 KiB
Dart
import '../core/api_client.dart';
|
|
|
|
class InAppNotification {
|
|
final String id;
|
|
final String type;
|
|
final String title;
|
|
final String message;
|
|
final String severity;
|
|
final String? actionType;
|
|
final String? actionTargetId;
|
|
final bool isRead;
|
|
final DateTime createdAt;
|
|
|
|
const InAppNotification({
|
|
required this.id,
|
|
required this.type,
|
|
required this.title,
|
|
required this.message,
|
|
required this.severity,
|
|
this.actionType,
|
|
this.actionTargetId,
|
|
required this.isRead,
|
|
required this.createdAt,
|
|
});
|
|
|
|
factory InAppNotification.fromJson(Map<String, dynamic> json) =>
|
|
InAppNotification(
|
|
id: json['id']?.toString() ?? '',
|
|
type: json['type']?.toString() ?? '',
|
|
title: json['title']?.toString() ?? '健康提醒',
|
|
message: json['message']?.toString() ?? '',
|
|
severity: json['severity']?.toString() ?? 'info',
|
|
actionType: json['actionType']?.toString(),
|
|
actionTargetId: json['actionTargetId']?.toString(),
|
|
isRead: json['isRead'] == true,
|
|
createdAt:
|
|
DateTime.tryParse(json['createdAt']?.toString() ?? '')?.toLocal() ??
|
|
DateTime.now(),
|
|
);
|
|
|
|
InAppNotification copyWith({bool? isRead}) => InAppNotification(
|
|
id: id,
|
|
type: type,
|
|
title: title,
|
|
message: message,
|
|
severity: severity,
|
|
actionType: actionType,
|
|
actionTargetId: actionTargetId,
|
|
isRead: isRead ?? this.isRead,
|
|
createdAt: createdAt,
|
|
);
|
|
}
|
|
|
|
class InAppNotificationHistory {
|
|
final int unreadCount;
|
|
final List<InAppNotification> items;
|
|
|
|
const InAppNotificationHistory({
|
|
required this.unreadCount,
|
|
required this.items,
|
|
});
|
|
}
|
|
|
|
class InAppNotificationService {
|
|
final ApiClient _api;
|
|
|
|
const InAppNotificationService(this._api);
|
|
|
|
Future<List<InAppNotification>> getPending() async {
|
|
final response = await _api.get('/api/notifications/pending');
|
|
final items = response.data['data'] as List? ?? const [];
|
|
return items
|
|
.whereType<Map>()
|
|
.map(
|
|
(item) => InAppNotification.fromJson(Map<String, dynamic>.from(item)),
|
|
)
|
|
.where((item) => item.id.isNotEmpty)
|
|
.toList();
|
|
}
|
|
|
|
Future<int> checkDue() async {
|
|
final response = await _api.post('/api/notifications/check-due');
|
|
final data = response.data['data'] as Map? ?? const {};
|
|
return (data['createdCount'] as num?)?.toInt() ?? 0;
|
|
}
|
|
|
|
Future<void> acknowledge(String id) async {
|
|
await _api.post('/api/notifications/$id/acknowledge');
|
|
}
|
|
|
|
Future<void> markAllRead() async {
|
|
await _api.post('/api/notifications/read-all');
|
|
}
|
|
|
|
Future<InAppNotificationHistory> getHistory() async {
|
|
final response = await _api.get('/api/notifications');
|
|
final data = response.data['data'] as Map? ?? const {};
|
|
final rawItems = data['items'] as List? ?? const [];
|
|
return InAppNotificationHistory(
|
|
unreadCount: data['unreadCount'] as int? ?? 0,
|
|
items: rawItems
|
|
.whereType<Map>()
|
|
.map(
|
|
(item) =>
|
|
InAppNotification.fromJson(Map<String, dynamic>.from(item)),
|
|
)
|
|
.where((item) => item.id.isNotEmpty)
|
|
.toList(),
|
|
);
|
|
}
|
|
|
|
Future<void> delete(String id) async {
|
|
await _api.delete('/api/notifications/$id');
|
|
}
|
|
}
|