Refactor file download logic to improve authentication handling and code readability
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user