Refactor file download logic to improve authentication handling and code readability

This commit is contained in:
Leon Bösche
2026-01-13 22:42:08 +01:00
parent 03962d5a80
commit 46dd299229

View File

@@ -318,14 +318,14 @@ class _FileExplorerState extends State<FileExplorer> {
try {
final fileService = getIt<FileService>();
// Get token from SessionBloc for authentication
final sessionState = context.read<SessionBloc>().state;
String? token;
if (sessionState is SessionActive) {
token = sessionState.token;
}
if (token == null) {
throw Exception('Not authenticated');
}
@@ -336,7 +336,8 @@ class _FileExplorerState extends State<FileExplorer> {
);
// Build full URL with token for authentication (anchor elements can't send headers)
final fullUrl = '${fileService.baseUrl}$downloadUrl&token=${Uri.encodeComponent(token)}';
final fullUrl =
'${fileService.baseUrl}$downloadUrl&token=${Uri.encodeComponent(token)}';
// Trigger download via anchor element
final anchor = web.HTMLAnchorElement()
@@ -351,7 +352,11 @@ class _FileExplorerState extends State<FileExplorer> {
SnackBar(
content: Row(
children: [
const Icon(Icons.download_done, color: AppTheme.accentColor, size: 20),
const Icon(
Icons.download_done,
color: AppTheme.accentColor,
size: 20,
),
const SizedBox(width: 12),
Expanded(
child: Text(