Merge pull request #269 from astubenbord/bugfix/files-not-correctly-consumed

Bugfix/files not correctly consumed
This commit is contained in:
Anton Stubenbord
2023-10-10 01:26:39 +02:00
committed by GitHub
6 changed files with 21 additions and 18 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

@@ -4,12 +4,6 @@ import 'package:paperless_mobile/features/sharing/view/consumption_queue_view.da
import 'package:paperless_mobile/routes/navigation_keys.dart'; import 'package:paperless_mobile/routes/navigation_keys.dart';
import 'package:paperless_mobile/routes/routes.dart'; import 'package:paperless_mobile/routes/routes.dart';
part 'upload_queue_route.g.dart';
@TypedGoRoute<UploadQueueRoute>(
path: "/upload-queue",
name: R.uploadQueue,
)
class UploadQueueRoute extends GoRouteData { class UploadQueueRoute extends GoRouteData {
static final GlobalKey<NavigatorState> $parentNavigatorKey = static final GlobalKey<NavigatorState> $parentNavigatorKey =
outerShellNavigatorKey; outerShellNavigatorKey;

View File

@@ -20,6 +20,7 @@ import 'package:paperless_mobile/routes/typed/branches/inbox_route.dart';
import 'package:paperless_mobile/routes/typed/branches/labels_route.dart'; import 'package:paperless_mobile/routes/typed/branches/labels_route.dart';
import 'package:paperless_mobile/routes/typed/branches/landing_route.dart'; import 'package:paperless_mobile/routes/typed/branches/landing_route.dart';
import 'package:paperless_mobile/routes/typed/branches/scanner_route.dart'; import 'package:paperless_mobile/routes/typed/branches/scanner_route.dart';
import 'package:paperless_mobile/routes/typed/branches/upload_queue_route.dart';
import 'package:paperless_mobile/routes/typed/shells/scaffold_shell_route.dart'; import 'package:paperless_mobile/routes/typed/shells/scaffold_shell_route.dart';
import 'package:paperless_mobile/routes/typed/top_level/settings_route.dart'; import 'package:paperless_mobile/routes/typed/top_level/settings_route.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@@ -34,6 +35,10 @@ part 'authenticated_route.g.dart';
path: "/settings", path: "/settings",
name: R.settings, name: R.settings,
), ),
TypedGoRoute<UploadQueueRoute>(
path: "/upload-queue",
name: R.uploadQueue,
),
TypedStatefulShellRoute<ScaffoldShellRoute>( TypedStatefulShellRoute<ScaffoldShellRoute>(
branches: [ branches: [
TypedStatefulShellBranch<LandingBranch>( TypedStatefulShellBranch<LandingBranch>(

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();