replaced account data singleton with a session model
This commit is contained in:
@@ -6,8 +6,8 @@ import 'package:background_downloader/background_downloader.dart' as bd;
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../api/marianumcloud/webdav/webdav_api.dart';
|
||||
import '../../model/account_data.dart';
|
||||
import '../../notification/notification_service.dart';
|
||||
import '../../session/session_manager.dart';
|
||||
import '../../share_intent/remote_file_ref.dart';
|
||||
import 'download_job.dart';
|
||||
|
||||
@@ -116,7 +116,7 @@ class DownloadManager {
|
||||
final encodedPath = Uri.encodeComponent(remotePath).replaceAll('%2F', '/');
|
||||
final task = bd.DownloadTask(
|
||||
url: '${WebdavApi.buildWebdavUrl()}$encodedPath',
|
||||
headers: AccountData().authHeaders(),
|
||||
headers: SessionManager().requireNextcloud().authHeaders,
|
||||
filename: name,
|
||||
baseDirectory: bd.BaseDirectory.temporary,
|
||||
directory: _directory,
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'dart:math';
|
||||
|
||||
/// Random hex id from a cryptographic RNG, e.g. for per-install identifiers.
|
||||
String randomHexId({int bytes = 16}) {
|
||||
final random = Random.secure();
|
||||
return List<int>.generate(
|
||||
bytes,
|
||||
(_) => random.nextInt(256),
|
||||
).map((b) => b.toRadixString(16).padLeft(2, '0')).join();
|
||||
}
|
||||
|
||||
/// Random RFC 4122 version-4 UUID, for ids a server expects in UUID form.
|
||||
String randomUuidV4() {
|
||||
final hex = randomHexId();
|
||||
final variant = (int.parse(hex[16], radix: 16) & 0x3 | 0x8).toRadixString(16);
|
||||
return '${hex.substring(0, 8)}-${hex.substring(8, 12)}-'
|
||||
'4${hex.substring(13, 16)}-$variant${hex.substring(17, 20)}-'
|
||||
'${hex.substring(20)}';
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import '../model/account_data.dart';
|
||||
import '../session/session_manager.dart';
|
||||
|
||||
/// Joins concurrent calls into the one already running for the same account
|
||||
/// session. A run left over from a signed-out session never blocks the next
|
||||
@@ -8,7 +8,7 @@ class SessionSingleFlight {
|
||||
int? _epoch;
|
||||
|
||||
Future<void> run(Future<void> Function() action) {
|
||||
final epoch = AccountData().sessionEpoch;
|
||||
final epoch = SessionManager().sessionEpoch;
|
||||
final running = _running;
|
||||
if (running != null && _epoch == epoch) return running;
|
||||
_epoch = epoch;
|
||||
|
||||
Reference in New Issue
Block a user