mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-10 19:27:01 +01:00
Some checks failed
📎 now picks any file (Android: Camera / Gallery / File; desktop: an
unfiltered dialog) and the desktop page accepts any dropped file. Photo and
screenshot formats up to 64 MB are still re-encoded and shown inline;
everything else is stored byte for byte on dufs beside the images and linked
as [name](url), shown as a row with its size that opens in the platform's
app (Android) or a new browser tab (desktop). BACKLOG.md rewrites file links
to ~/data/cloud/todo-images/ like image links.
There is no size cap, so no layer holds a file in memory: uploads and
downloads stream through DufsImageClient, writes land in a .tmp renamed when
whole (an interrupted download no longer leaves a truncated file that looks
done), the desktop page POSTs the browser's own Blob with fetch, and Android's
"File" uses file_picker, because file_selector's Android side reads the whole
file into memory on the UI thread. Verified with a 1 GB file end to end on
desktop (peak RSS +36 MB) and on an API 36 emulator.
The wrapper serves attachments from the origin that holds the GitHub token
and the notes, so only script-free types open inline (nosniff), the rest
download; writes carrying another site's Origin are refused (this also
closes cross-site overwrites of the backup files); and attachment routes run
concurrently so a long upload or a playing video cannot stall the page.
Also: cupertino_icons 2.0.0 (unused, but the freshness gate blocks the
pubspec otherwise), open_file 4.0.0 and file_picker 13.1.0 pinned.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
2.5 KiB
Dart
98 lines
2.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:todo/attachments/image_store_api.dart';
|
|
import 'package:todo/attachments/image_store_scope.dart';
|
|
import 'package:todo/ui/image_attach.dart';
|
|
|
|
import '../fake_image_store.dart';
|
|
|
|
void main() {
|
|
late FakeImageStore store;
|
|
late ImageAttachController target;
|
|
late List<List<String>> inserted;
|
|
|
|
setUp(() {
|
|
store = FakeImageStore();
|
|
target = ImageAttachController();
|
|
inserted = [];
|
|
target.bind(inserted.add);
|
|
});
|
|
|
|
Future<BuildContext> pumpScope(WidgetTester tester) async {
|
|
late BuildContext context;
|
|
await tester.pumpWidget(
|
|
ImageStoreScope(
|
|
store: store,
|
|
child: MaterialApp(
|
|
home: Scaffold(
|
|
body: Builder(
|
|
builder: (c) {
|
|
context = c;
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
return context;
|
|
}
|
|
|
|
testWidgets('files and images attach in order, each as its own line', (
|
|
tester,
|
|
) async {
|
|
final context = await pumpScope(tester);
|
|
await attachFiles(
|
|
context,
|
|
noteId: () => 'n1',
|
|
target: target,
|
|
files: [XFile('/p/a.pdf'), XFile('/p/shot.png')],
|
|
);
|
|
final lines = inserted.single;
|
|
expect(lines.first, startsWith('[a.pdf]('));
|
|
expect(lines.last, startsWith(');
|
|
});
|
|
|
|
testWidgets('a store failure is shown and keeps what came before', (
|
|
tester,
|
|
) async {
|
|
final context = await pumpScope(tester);
|
|
var calls = 0;
|
|
await attachFiles(
|
|
context,
|
|
noteId: () {
|
|
if (++calls == 2) store.failure = const ImageStoreException('full');
|
|
return 'n1';
|
|
},
|
|
target: target,
|
|
files: [XFile('/p/a.pdf'), XFile('/p/b.pdf'), XFile('/p/c.pdf')],
|
|
);
|
|
await tester.pump();
|
|
expect(inserted.single, hasLength(1));
|
|
expect(find.text('full'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('nothing is shown once the screen closed mid-attach', (
|
|
tester,
|
|
) async {
|
|
final context = await pumpScope(tester);
|
|
final gate = Completer<void>();
|
|
store
|
|
..gate = gate.future
|
|
..failure = const ImageStoreException('full');
|
|
final done = attachFiles(
|
|
context,
|
|
noteId: () => 'n1',
|
|
target: target,
|
|
files: [XFile('/p/a.pdf')],
|
|
);
|
|
await tester.pumpWidget(const SizedBox());
|
|
gate.complete();
|
|
await done;
|
|
await tester.pump();
|
|
expect(find.text('full'), findsNothing);
|
|
});
|
|
}
|