fix: Use correct files to discard after local consumption

This commit is contained in:
Anton Stubenbord
2023-10-10 01:26:14 +02:00
parent f3df4c2685
commit 8dadaa42e3
4 changed files with 16 additions and 12 deletions

View File

@@ -44,6 +44,7 @@ class DocumentUploadCubit extends Cubit<DocumentUploadState> {
Iterable<int> tags = const [], Iterable<int> tags = const [],
DateTime? createdAt, DateTime? createdAt,
int? asn, int? asn,
void Function(double)? onProgressChanged,
}) async { }) async {
final taskId = await _documentApi.create( final taskId = await _documentApi.create(
bytes, bytes,
@@ -54,6 +55,7 @@ class DocumentUploadCubit extends Cubit<DocumentUploadState> {
tags: tags, tags: tags,
createdAt: createdAt, createdAt: createdAt,
asn: asn, asn: asn,
onProgressChanged: onProgressChanged,
); );
if (taskId != null) { if (taskId != null) {
_tasksNotifier.listenToTaskChanges(taskId); _tasksNotifier.listenToTaskChanges(taskId);

View File

@@ -23,27 +23,28 @@ class ConsumptionChangeNotifier extends ChangeNotifier {
} }
/// Creates a local copy of all shared files and reloads all files /// Creates a local copy of all shared files and reloads all files
/// from the user's consumption directory. /// from the user's consumption directory. Returns the newly added files copied to the consumption directory.
Future<void> addFiles({ Future<List<File>> addFiles({
required List<File> files, required List<File> files,
required String userId, required String userId,
}) async { }) async {
if (files.isEmpty) { if (files.isEmpty) {
return; return [];
} }
final consumptionDirectory = final consumptionDirectory =
await FileService.getConsumptionDirectory(userId: userId); await FileService.getConsumptionDirectory(userId: userId);
final List<File> localFiles = [];
for (final file in files) { for (final file in files) {
File localFile; if (!file.path.startsWith(consumptionDirectory.path)) {
if (file.path.startsWith(consumptionDirectory.path)) { final localFile = await file
localFile = file; .copy(p.join(consumptionDirectory.path, p.basename(file.path)));
localFiles.add(localFile);
} else { } else {
final fileName = p.basename(file.path); localFiles.add(file);
localFile = File(p.join(consumptionDirectory.path, fileName));
await file.copy(localFile.path);
} }
} }
return loadFromConsumptionDirectory(userId: userId); await loadFromConsumptionDirectory(userId: userId);
return localFiles;
} }
/// Marks a file as processed by removing it from the queue and deleting the local copy of the file. /// Marks a file as processed by removing it from the queue and deleting the local copy of the file.

View File

@@ -141,13 +141,13 @@ class _EventListenerShellState extends State<EventListenerShell>
if (files.isNotEmpty) { if (files.isNotEmpty) {
final userId = context.read<LocalUserAccount>().id; final userId = context.read<LocalUserAccount>().id;
final notifier = context.read<ConsumptionChangeNotifier>(); final notifier = context.read<ConsumptionChangeNotifier>();
await notifier.addFiles( final addedLocalFiles = await notifier.addFiles(
files: files, files: files,
userId: userId, userId: userId,
); );
consumeLocalFiles( consumeLocalFiles(
context, context,
files: files, files: addedLocalFiles,
userId: userId, userId: userId,
exitAppAfterConsumed: true, exitAppAfterConsumed: true,
); );

View File

@@ -14,6 +14,7 @@ abstract class PaperlessDocumentsApi {
int? correspondent, int? correspondent,
Iterable<int> tags = const [], Iterable<int> tags = const [],
int? asn, int? asn,
void Function(double progress)? onProgressChanged,
}); });
Future<DocumentModel> update(DocumentModel doc); Future<DocumentModel> update(DocumentModel doc);
Future<int> findNextAsn(); Future<int> findNextAsn();