refactor(app,learn): people's files on the device shared in halkyon_app
ADR 0043's recommendation, for Todo's attachments: what Learn had for its files on the device moves into halkyon_app, unchanged but for its names, and Learn uses it from there. - FileCache, DirectoryFileCache (Learn's AssetFileCache): the files by their SHA-256 in a folder of the person's, and which wait to be uploaded. - FileServerGateway, ServerpodFileServerGateway (Learn's AssetServerGateway): halkyon_base's files endpoint, taking the module's caller rather than Learn's client; FileLimitReached, FileRoom. - Their fakes in halkyon_app's testing: MemoryFileCache, FakeFileServerGateway, sha256Of. - SealedFile: the format every app seals a file in (HLKF, version 1), sealing with halkyon_app's ContentCipher; Learn's Privacy seals and opens its files with it, for the same context as before, so every file sealed so far opens as it did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
b7f0aaaec7
commit
5dd7575dd6
41 changed files with 272 additions and 235 deletions
|
|
@ -1,101 +0,0 @@
|
|||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
/// The files on this device, by their SHA-256, and which of them wait to be
|
||||
/// uploaded.
|
||||
abstract interface class AssetFileCache() {
|
||||
/// The file with [sha256]; null if this device hasn't got it.
|
||||
Future<Uint8List?> read(String sha256);
|
||||
|
||||
/// Keeps [bytes], whose SHA-256 is [sha256].
|
||||
Future<void> write(String sha256, Uint8List bytes);
|
||||
|
||||
/// Where the file with [sha256] is, or would be.
|
||||
String pathOf(String sha256);
|
||||
|
||||
/// The files that wait to be uploaded.
|
||||
Future<Set<String>> pendingUploads();
|
||||
|
||||
/// Notes that the file with [sha256] waits to be uploaded.
|
||||
Future<void> markPending(String sha256);
|
||||
|
||||
/// Notes that the file with [sha256] doesn't wait any more.
|
||||
Future<void> clearPending(String sha256);
|
||||
}
|
||||
|
||||
/// [AssetFileCache] in a folder of the person's: each file named by its hash,
|
||||
/// and an empty file of the same name in `uploads/` for each that waits.
|
||||
///
|
||||
/// A hash is part of a path here, and rows synced from elsewhere carry them,
|
||||
/// so anything but 64 lowercase hex digits is refused.
|
||||
class DirectoryAssetFileCache(final Directory _folder)
|
||||
implements AssetFileCache {
|
||||
Directory get _uploads => Directory(p.join(_folder.path, 'uploads'));
|
||||
|
||||
@override
|
||||
Future<Uint8List?> read(String sha256) async {
|
||||
try {
|
||||
return await File(pathOf(sha256)).readAsBytes();
|
||||
} on PathNotFoundException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> write(String sha256, Uint8List bytes) async {
|
||||
final file = File(pathOf(sha256));
|
||||
if (file.existsSync()) {
|
||||
return;
|
||||
}
|
||||
await _folder.create(recursive: true);
|
||||
// Written aside and renamed, so no half-written file ever has the name.
|
||||
final partial = File('${file.path}.partial');
|
||||
await partial.writeAsBytes(bytes, flush: true);
|
||||
await partial.rename(file.path);
|
||||
}
|
||||
|
||||
@override
|
||||
String pathOf(String sha256) => p.join(_folder.path, checkedSha256(sha256));
|
||||
|
||||
@override
|
||||
Future<Set<String>> pendingUploads() async {
|
||||
if (!_uploads.existsSync()) {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
await for (final entry in _uploads.list())
|
||||
if (entry is File && isSha256(p.basename(entry.path)))
|
||||
p.basename(entry.path),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> markPending(String sha256) async {
|
||||
await _uploads.create(recursive: true);
|
||||
await File(
|
||||
p.join(_uploads.path, checkedSha256(sha256)),
|
||||
).writeAsBytes(const []);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clearPending(String sha256) async {
|
||||
try {
|
||||
await File(p.join(_uploads.path, checkedSha256(sha256))).delete();
|
||||
} on PathNotFoundException {
|
||||
// Not waiting.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether [value] is a SHA-256 as files are named by: 64 lowercase hex
|
||||
/// digits.
|
||||
bool isSha256(String value) => _sha256.hasMatch(value);
|
||||
|
||||
/// [value], if it [isSha256]; throws an [ArgumentError] otherwise.
|
||||
String checkedSha256(String value) => isSha256(value)
|
||||
? value
|
||||
: throw ArgumentError.value(value, 'sha256', 'is no SHA-256 in hex');
|
||||
|
||||
final _sha256 = RegExp(r'^[0-9a-f]{64}$');
|
||||
|
|
@ -3,13 +3,13 @@ import 'dart:developer';
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart'
|
||||
show FileCache, FileLimitReached, FileRoom, FileServerGateway, isSha256;
|
||||
import 'package:halkyon_core/halkyon_core.dart'
|
||||
show CoalescingRunner, SerialQueue;
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_file_cache.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_gateway.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_payload.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_sealing.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_server_gateway.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/model/stored_file.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/privacy/data/tree_files.dart';
|
||||
|
||||
|
|
@ -33,8 +33,8 @@ import 'package:halkyon_learn_flutter/src/core/privacy/data/tree_files.dart';
|
|||
/// trees, is a file per key.
|
||||
class AssetRepository(
|
||||
final AssetGateway _rows,
|
||||
final AssetServerGateway _server,
|
||||
final AssetFileCache _files,
|
||||
final FileServerGateway _server,
|
||||
final FileCache _files,
|
||||
final AssetSealing _sealing, {
|
||||
Stream<void> uploadTriggers = const Stream.empty(),
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
/// How much room the person's files take on the server, and may take, in
|
||||
/// bytes.
|
||||
typedef FileRoom = ({int usedBytes, int limitBytes});
|
||||
|
||||
/// The server keeps no more of the person's files: they would take more
|
||||
/// room than the person may use, or the instance has left ([instanceFull]).
|
||||
class const FileLimitReached({
|
||||
/// Whether the instance is full, rather than the person's own room.
|
||||
required final bool instanceFull,
|
||||
|
||||
/// What the person may keep, in bytes.
|
||||
required final int limitBytes,
|
||||
}) implements Exception {
|
||||
@override
|
||||
String toString() =>
|
||||
'FileLimitReached(instanceFull: $instanceFull, limit: $limitBytes)';
|
||||
}
|
||||
|
||||
/// The server's copy of the person's files.
|
||||
abstract interface class AssetServerGateway() {
|
||||
/// How to upload the file with [sha256] of [byteSize] bytes; null when the
|
||||
/// server has it already. Throws [FileLimitReached] when it doesn't fit.
|
||||
Future<String?> startUpload(
|
||||
String sha256,
|
||||
int byteSize, {
|
||||
bool encrypted = false,
|
||||
});
|
||||
|
||||
/// Uploads [bytes] as [description] says; whether that worked.
|
||||
Future<bool> upload(String description, Uint8List bytes);
|
||||
|
||||
/// Completes the upload of the file with [sha256]; whether the server keeps
|
||||
/// it, which it does only if its content has that hash. Throws
|
||||
/// [FileLimitReached] when it no longer fits.
|
||||
Future<bool> finishUpload(String sha256, {bool encrypted = false});
|
||||
|
||||
/// How much room the person's files take, and may take.
|
||||
Future<FileRoom> room();
|
||||
|
||||
/// The file of the asset [id]; null when the server has none for this
|
||||
/// person (not uploaded yet, or not theirs).
|
||||
Future<Uint8List?> download(String id);
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:halkyon_base_client/halkyon_base_client.dart' as base;
|
||||
import 'package:halkyon_learn_client/halkyon_learn_client.dart' as protocol;
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_server_gateway.dart';
|
||||
|
||||
/// [AssetServerGateway] on halkyon_base's `files` endpoint (Halkyon's ADR
|
||||
/// 0043), uploading through Serverpod's own upload route. Learn's own
|
||||
/// `asset` endpoint stays for released apps alone (D7).
|
||||
class ServerpodAssetServerGateway(final protocol.Client _client)
|
||||
implements AssetServerGateway {
|
||||
@override
|
||||
Future<String?> startUpload(
|
||||
String sha256,
|
||||
int byteSize, {
|
||||
bool encrypted = false,
|
||||
}) => _refusing(
|
||||
() => _client.modules.base.files.startUpload(
|
||||
sha256,
|
||||
byteSize,
|
||||
encrypted: encrypted,
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Future<bool> upload(String description, Uint8List bytes) =>
|
||||
protocol.FileUploader(description)
|
||||
.uploadByteData(ByteData.sublistView(bytes));
|
||||
|
||||
@override
|
||||
Future<bool> finishUpload(String sha256, {bool encrypted = false}) =>
|
||||
_refusing(
|
||||
() => _client.modules.base.files.finishUpload(
|
||||
sha256,
|
||||
encrypted: encrypted,
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Future<FileRoom> room() async {
|
||||
final usage = await _client.modules.base.files.usage();
|
||||
return (usedBytes: usage.usedBytes, limitBytes: usage.limitBytes);
|
||||
}
|
||||
|
||||
/// [call], its refusal for want of room as a [FileLimitReached].
|
||||
Future<T> _refusing<T>(Future<T> Function() call) async {
|
||||
try {
|
||||
return await call();
|
||||
} on base.FileLimitExceededException catch (error) {
|
||||
throw FileLimitReached(
|
||||
instanceFull: error.instanceFull,
|
||||
limitBytes: error.limitBytes,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List?> download(String id) async {
|
||||
try {
|
||||
return Uint8List.sublistView(
|
||||
await _client.modules.base.files.download(
|
||||
protocol.UuidValue.withValidation(id),
|
||||
),
|
||||
);
|
||||
} on base.StoredFileNotFoundException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,9 +5,7 @@ import 'package:flutter/widgets.dart';
|
|||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:halkyon_learn_client/halkyon_learn_client.dart'
|
||||
show Client, PublishRefusal, PublishRefusedException, UuidValue;
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_file_cache.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/serverpod_asset_server_gateway.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/sound_player.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/sync_asset_gateway.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/dependencies/person_dependencies.dart';
|
||||
|
|
@ -541,8 +539,8 @@ Future<PersonDependencies> _openPersonData(
|
|||
)..start(sync.synced);
|
||||
final assets = AssetRepository(
|
||||
SyncAssetGateway(db, sync, privacy),
|
||||
ServerpodAssetServerGateway(client),
|
||||
DirectoryAssetFileCache(Directory(p.join(folder.path, 'files'))),
|
||||
ServerpodFileServerGateway(client.modules.base),
|
||||
DirectoryFileCache(Directory(p.join(folder.path, 'files'))),
|
||||
privacy,
|
||||
uploadTriggers: sync.synced,
|
||||
filesAllowed: () => sync.filesAllowed,
|
||||
|
|
|
|||
|
|
@ -2365,63 +2365,21 @@ class Privacy(
|
|||
? utf8.decode(Uint8List.sublistView(envelope.payload))
|
||||
: base64Encode(Uint8List.sublistView(envelope.payload));
|
||||
|
||||
/// What a sealed file starts with, and its format's version.
|
||||
static final _fileMagic = utf8.encode('HLKF');
|
||||
static const _fileVersion = 1;
|
||||
|
||||
@override
|
||||
Uint8List sealFile(
|
||||
Uint8List plain, {
|
||||
required String keyId,
|
||||
required String assetId,
|
||||
}) {
|
||||
final sealed = keys.cipher.seal(
|
||||
plain,
|
||||
keyId: keyId,
|
||||
context: _fileContext(assetId),
|
||||
);
|
||||
final id = utf8.encode(keyId);
|
||||
return Uint8List.fromList([
|
||||
..._fileMagic,
|
||||
_fileVersion,
|
||||
id.length,
|
||||
...id,
|
||||
...sealed.nonce,
|
||||
...sealed.payload,
|
||||
]);
|
||||
}
|
||||
}) => SealedFile.seal(
|
||||
keys.cipher,
|
||||
plain,
|
||||
keyId: keyId,
|
||||
context: _fileContext(assetId),
|
||||
);
|
||||
|
||||
@override
|
||||
Uint8List? openFile(Uint8List sealed, {required String assetId}) {
|
||||
final header = _fileMagic.length + 2;
|
||||
if (sealed.length < header ||
|
||||
!_startsWith(sealed, _fileMagic) ||
|
||||
sealed[_fileMagic.length] != _fileVersion) {
|
||||
return null;
|
||||
}
|
||||
final idLength = sealed[_fileMagic.length + 1];
|
||||
const nonceLength = 24;
|
||||
if (sealed.length < header + idLength + nonceLength) {
|
||||
return null;
|
||||
}
|
||||
final String keyId;
|
||||
try {
|
||||
keyId = utf8.decode(
|
||||
Uint8List.sublistView(sealed, header, header + idLength),
|
||||
);
|
||||
} on FormatException {
|
||||
return null;
|
||||
}
|
||||
final nonceAt = header + idLength;
|
||||
return keys.cipher.unseal(
|
||||
SealedPayload(
|
||||
keyId: keyId,
|
||||
nonce: Uint8List.sublistView(sealed, nonceAt, nonceAt + nonceLength),
|
||||
payload: Uint8List.sublistView(sealed, nonceAt + nonceLength),
|
||||
),
|
||||
context: _fileContext(assetId),
|
||||
);
|
||||
}
|
||||
Uint8List? openFile(Uint8List sealed, {required String assetId}) =>
|
||||
SealedFile.open(keys.cipher, sealed, context: _fileContext(assetId));
|
||||
|
||||
static List<int> _fileContext(String assetId) =>
|
||||
utf8.encode('asset|$assetId|file');
|
||||
|
|
|
|||
|
|
@ -2,26 +2,26 @@ import 'dart:convert';
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/testing.dart'
|
||||
show FakeFileServerGateway, MemoryFileCache, sha256Of;
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/bloc/sound_bloc.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_repository.dart';
|
||||
|
||||
import '../../../support/fake_asset_gateway.dart';
|
||||
import '../../../support/fake_asset_sealing.dart';
|
||||
import '../../../support/fake_asset_server_gateway.dart';
|
||||
import '../../../support/fake_sound_player.dart';
|
||||
import '../../../support/memory_asset_file_cache.dart';
|
||||
|
||||
void main() {
|
||||
late MemoryAssetFileCache files;
|
||||
late MemoryFileCache files;
|
||||
late AssetRepository assets;
|
||||
late FakeSoundPlayer player;
|
||||
late String sound;
|
||||
|
||||
setUp(() async {
|
||||
files = MemoryAssetFileCache();
|
||||
files = MemoryFileCache();
|
||||
assets = AssetRepository(
|
||||
FakeAssetGateway(),
|
||||
FakeAssetServerGateway(),
|
||||
FakeFileServerGateway(),
|
||||
files,
|
||||
FakeAssetSealing(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,19 +3,19 @@ import 'dart:convert';
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/testing.dart'
|
||||
show FakeFileServerGateway, MemoryFileCache, sha256Of;
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_payload.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/model/stored_file.dart';
|
||||
|
||||
import '../../../support/fake_asset_gateway.dart';
|
||||
import '../../../support/fake_asset_sealing.dart';
|
||||
import '../../../support/fake_asset_server_gateway.dart';
|
||||
import '../../../support/memory_asset_file_cache.dart';
|
||||
|
||||
void main() {
|
||||
late FakeAssetGateway rows;
|
||||
late FakeAssetServerGateway server;
|
||||
late MemoryAssetFileCache cache;
|
||||
late FakeFileServerGateway server;
|
||||
late MemoryFileCache cache;
|
||||
late StreamController<void> triggers;
|
||||
late AssetRepository repository;
|
||||
|
||||
|
|
@ -26,8 +26,8 @@ void main() {
|
|||
|
||||
setUp(() {
|
||||
rows = FakeAssetGateway();
|
||||
server = FakeAssetServerGateway();
|
||||
cache = MemoryAssetFileCache();
|
||||
server = FakeFileServerGateway();
|
||||
cache = MemoryFileCache();
|
||||
triggers = StreamController<void>.broadcast();
|
||||
filesAllowed = true;
|
||||
repository = AssetRepository(
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_file_cache.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
void main() {
|
||||
late Directory folder;
|
||||
late DirectoryAssetFileCache cache;
|
||||
final hash = 'a' * 64;
|
||||
final other = 'b' * 64;
|
||||
|
||||
setUp(() async {
|
||||
folder = await Directory.systemTemp.createTemp('files');
|
||||
cache = DirectoryAssetFileCache(Directory(p.join(folder.path, 'files')));
|
||||
});
|
||||
tearDown(() => folder.delete(recursive: true));
|
||||
|
||||
test('keeps a file by its hash, and has none it was not given', () async {
|
||||
expect(await cache.read(hash), isNull);
|
||||
|
||||
await cache.write(hash, Uint8List.fromList([1, 2, 3]));
|
||||
|
||||
expect(await cache.read(hash), [1, 2, 3]);
|
||||
expect(File(cache.pathOf(hash)).readAsBytesSync(), [1, 2, 3]);
|
||||
expect(
|
||||
Directory(p.join(folder.path, 'files')).listSync().map((e) => e.path),
|
||||
[cache.pathOf(hash)],
|
||||
reason: 'nothing half-written is left beside it',
|
||||
);
|
||||
});
|
||||
|
||||
test('keeps the file it has when given it again', () async {
|
||||
await cache.write(hash, Uint8List.fromList([1]));
|
||||
await cache.write(hash, Uint8List.fromList([2]));
|
||||
|
||||
expect(await cache.read(hash), [1]);
|
||||
});
|
||||
|
||||
test('notes which files wait to be uploaded', () async {
|
||||
expect(await cache.pendingUploads(), isEmpty);
|
||||
|
||||
await cache.markPending(hash);
|
||||
await cache.markPending(other);
|
||||
await cache.clearPending(hash);
|
||||
await cache.clearPending('c' * 64);
|
||||
|
||||
expect(await cache.pendingUploads(), {other});
|
||||
});
|
||||
|
||||
test('refuses anything but a SHA-256 in a path', () async {
|
||||
for (final forged in ['../sync.sqlite', 'A' * 64, '${'a' * 63}/', '']) {
|
||||
expect(() => cache.pathOf(forged), throwsArgumentError);
|
||||
await expectLater(cache.markPending(forged), throwsArgumentError);
|
||||
await expectLater(
|
||||
cache.write(forged, Uint8List.fromList([1])),
|
||||
throwsArgumentError,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -2,19 +2,19 @@ import 'dart:convert';
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/testing.dart'
|
||||
show FakeFileServerGateway, MemoryFileCache, sha256Of;
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_payload.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_repository.dart';
|
||||
|
||||
import '../../../support/fake_asset_gateway.dart';
|
||||
import '../../../support/fake_asset_sealing.dart';
|
||||
import '../../../support/fake_asset_server_gateway.dart';
|
||||
import '../../../support/memory_asset_file_cache.dart';
|
||||
|
||||
/// A private studyset's files (ADR 0019, D5): sealed with its tree's key for
|
||||
/// their row before they are hashed, uploaded and kept.
|
||||
void main() {
|
||||
late FakeAssetGateway rows;
|
||||
late FakeAssetServerGateway server;
|
||||
late FakeFileServerGateway server;
|
||||
late FakeAssetSealing sealing;
|
||||
late AssetRepository device;
|
||||
final image = Uint8List.fromList(utf8.encode('a private picture'));
|
||||
|
|
@ -26,7 +26,7 @@ void main() {
|
|||
final repository = AssetRepository(
|
||||
rows,
|
||||
server,
|
||||
MemoryAssetFileCache(),
|
||||
MemoryFileCache(),
|
||||
keys,
|
||||
);
|
||||
addTearDown(repository.dispose);
|
||||
|
|
@ -35,7 +35,7 @@ void main() {
|
|||
|
||||
setUp(() {
|
||||
rows = FakeAssetGateway();
|
||||
server = FakeAssetServerGateway();
|
||||
server = FakeFileServerGateway();
|
||||
sealing = FakeAssetSealing(keys: {'diary': 'key-diary'});
|
||||
device = deviceWith(sealing);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import 'package:material_ui/material_ui.dart';
|
|||
import '../../support/fake_asset_gateway.dart';
|
||||
import '../../support/fake_note_gateway.dart';
|
||||
import '../../support/fake_studyset_gateway.dart';
|
||||
import '../../support/memory_asset_file_cache.dart';
|
||||
import '../../support/pump_app.dart';
|
||||
import '../../support/test_dependencies.dart';
|
||||
|
||||
|
|
@ -44,7 +43,7 @@ void main() {
|
|||
noteGateway: FakeNoteGateway(),
|
||||
files: files,
|
||||
assetGateway: assets,
|
||||
assetFiles: MemoryAssetFileCache(),
|
||||
assetFiles: MemoryFileCache(),
|
||||
),
|
||||
location: RoutePaths.newNote('japanese'),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ import 'dart:typed_data';
|
|||
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/testing.dart'
|
||||
show FakeFileServerGateway, MemoryFileCache, sha256Of;
|
||||
import 'package:halkyon_editor/halkyon_editor.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_payload.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_repository.dart';
|
||||
|
|
@ -17,11 +19,9 @@ import 'package:material_ui/material_ui.dart';
|
|||
|
||||
import '../../support/fake_asset_gateway.dart';
|
||||
import '../../support/fake_asset_sealing.dart';
|
||||
import '../../support/fake_asset_server_gateway.dart';
|
||||
import '../../support/fake_card_gateway.dart';
|
||||
import '../../support/fake_sound_player.dart';
|
||||
import '../../support/fake_studyset_gateway.dart';
|
||||
import '../../support/memory_asset_file_cache.dart';
|
||||
import '../../support/pump_app.dart';
|
||||
import '../../support/test_dependencies.dart';
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ void main() {
|
|||
late FakeCardGateway cardGateway;
|
||||
late CardRepository cards;
|
||||
late FakeAssetGateway assetGateway;
|
||||
late MemoryAssetFileCache files;
|
||||
late MemoryFileCache files;
|
||||
late AssetRepository assets;
|
||||
late FakeSoundPlayer sounds;
|
||||
|
||||
|
|
@ -37,10 +37,10 @@ void main() {
|
|||
cardGateway = FakeCardGateway();
|
||||
cards = CardRepository(cardGateway);
|
||||
assetGateway = FakeAssetGateway();
|
||||
files = MemoryAssetFileCache();
|
||||
files = MemoryFileCache();
|
||||
assets = AssetRepository(
|
||||
assetGateway,
|
||||
FakeAssetServerGateway(),
|
||||
FakeFileServerGateway(),
|
||||
files,
|
||||
FakeAssetSealing(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/testing.dart'
|
||||
show FakeFileServerGateway, MemoryFileCache;
|
||||
import 'package:halkyon_editor/halkyon_editor.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/work/work_progress.dart';
|
||||
|
|
@ -22,7 +24,6 @@ import 'package:halkyon_learn_flutter/src/feature/tag/data/tag_repository.dart';
|
|||
|
||||
import '../../../support/fake_asset_gateway.dart';
|
||||
import '../../../support/fake_asset_sealing.dart';
|
||||
import '../../../support/fake_asset_server_gateway.dart';
|
||||
import '../../../support/fake_card_gateway.dart';
|
||||
import '../../../support/fake_learning_path_gateway.dart';
|
||||
import '../../../support/fake_note_gateway.dart';
|
||||
|
|
@ -30,7 +31,6 @@ import '../../../support/fake_pdf_source_gateway.dart';
|
|||
import '../../../support/fake_review_gateway.dart';
|
||||
import '../../../support/fake_studyset_gateway.dart';
|
||||
import '../../../support/fake_tag_gateway.dart';
|
||||
import '../../../support/memory_asset_file_cache.dart';
|
||||
import 'anki_package_test.dart' show fixture;
|
||||
|
||||
void main() {
|
||||
|
|
@ -55,8 +55,8 @@ void main() {
|
|||
assetRows = FakeAssetGateway();
|
||||
assets = AssetRepository(
|
||||
assetRows,
|
||||
FakeAssetServerGateway(),
|
||||
MemoryAssetFileCache(),
|
||||
FakeFileServerGateway(),
|
||||
MemoryFileCache(),
|
||||
FakeAssetSealing(),
|
||||
);
|
||||
importer = AnkiImporter(
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import 'package:halkyon_learn_flutter/src/feature/studyset/data/studyset_reposit
|
|||
import 'package:halkyon_learn_flutter/src/feature/studyset/model/studyset_content.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../../../support/fake_asset_server_gateway.dart';
|
||||
import '../../../support/fake_card_gateway.dart';
|
||||
import '../../../support/fake_note_gateway.dart';
|
||||
import '../../../support/fake_studyset_gateway.dart';
|
||||
|
|
@ -26,13 +25,13 @@ import '../data/anki_package_test.dart' show fixture;
|
|||
void main() {
|
||||
late FakeCardGateway cardGateway;
|
||||
late FakeFilePicker files;
|
||||
late FakeAssetServerGateway server;
|
||||
late FakeFileServerGateway server;
|
||||
late FakeNoteGateway noteGateway;
|
||||
|
||||
setUp(() {
|
||||
cardGateway = FakeCardGateway();
|
||||
files = FakeFilePicker();
|
||||
server = FakeAssetServerGateway();
|
||||
server = FakeFileServerGateway();
|
||||
noteGateway = FakeNoteGateway();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ import 'dart:typed_data';
|
|||
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/testing.dart'
|
||||
show FakeFileServerGateway, MemoryFileCache;
|
||||
import 'package:halkyon_editor/halkyon_editor.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/model/stored_file.dart';
|
||||
|
|
@ -40,7 +42,6 @@ import 'package:halkyon_ui/halkyon_ui.dart';
|
|||
|
||||
import '../../support/fake_asset_gateway.dart';
|
||||
import '../../support/fake_asset_sealing.dart';
|
||||
import '../../support/fake_asset_server_gateway.dart';
|
||||
import '../../support/fake_card_gateway.dart';
|
||||
import '../../support/fake_device_dictionaries.dart';
|
||||
import '../../support/fake_dictionary_gateway.dart';
|
||||
|
|
@ -51,7 +52,6 @@ import '../../support/fake_pdf_source_gateway.dart';
|
|||
import '../../support/fake_review_gateway.dart';
|
||||
import '../../support/fake_studyset_gateway.dart';
|
||||
import '../../support/fake_tag_gateway.dart';
|
||||
import '../../support/memory_asset_file_cache.dart';
|
||||
|
||||
/// One person's repositories, on fake gateways of their own.
|
||||
final class _Person() {
|
||||
|
|
@ -63,8 +63,8 @@ final class _Person() {
|
|||
final reviews = ReviewRepository(FakeReviewGateway());
|
||||
final assets = AssetRepository(
|
||||
FakeAssetGateway(),
|
||||
FakeAssetServerGateway(),
|
||||
MemoryAssetFileCache(),
|
||||
FakeFileServerGateway(),
|
||||
MemoryFileCache(),
|
||||
FakeAssetSealing(),
|
||||
);
|
||||
late final tags = TagRepository(
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import 'dart:typed_data';
|
|||
import 'package:archive/archive.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/testing.dart'
|
||||
show FakeFileServerGateway, MemoryFileCache;
|
||||
import 'package:halkyon_editor/halkyon_editor.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/work/work_progress.dart';
|
||||
|
|
@ -33,7 +35,6 @@ import 'package:halkyon_learn_flutter/src/feature/tag/data/tag_repository.dart';
|
|||
|
||||
import '../../support/fake_asset_gateway.dart';
|
||||
import '../../support/fake_asset_sealing.dart';
|
||||
import '../../support/fake_asset_server_gateway.dart';
|
||||
import '../../support/fake_card_gateway.dart';
|
||||
import '../../support/fake_device_dictionaries.dart';
|
||||
import '../../support/fake_dictionary_gateway.dart';
|
||||
|
|
@ -44,7 +45,6 @@ import '../../support/fake_pdf_source_gateway.dart';
|
|||
import '../../support/fake_review_gateway.dart';
|
||||
import '../../support/fake_studyset_gateway.dart';
|
||||
import '../../support/fake_tag_gateway.dart';
|
||||
import '../../support/memory_asset_file_cache.dart';
|
||||
|
||||
/// The JSON a synced [payload] holds.
|
||||
Map<String, Object?> json(ByteData payload) =>
|
||||
|
|
@ -280,8 +280,8 @@ void main() {
|
|||
assetRows = FakeAssetGateway();
|
||||
assets = AssetRepository(
|
||||
assetRows,
|
||||
FakeAssetServerGateway(),
|
||||
MemoryAssetFileCache(),
|
||||
FakeFileServerGateway(),
|
||||
MemoryFileCache(),
|
||||
FakeAssetSealing(),
|
||||
);
|
||||
pdfs = PdfSourceRepository(FakePdfSourceGateway(), assets);
|
||||
|
|
|
|||
|
|
@ -20,13 +20,11 @@ import 'package:material_ui/material_ui.dart' hide Card;
|
|||
|
||||
import '../../support/fake_asset_gateway.dart';
|
||||
import '../../support/fake_asset_sealing.dart';
|
||||
import '../../support/fake_asset_server_gateway.dart';
|
||||
import '../../support/fake_card_gateway.dart';
|
||||
import '../../support/fake_note_gateway.dart';
|
||||
import '../../support/fake_pdf_engine.dart';
|
||||
import '../../support/fake_pdf_source_gateway.dart';
|
||||
import '../../support/fake_studyset_gateway.dart';
|
||||
import '../../support/memory_asset_file_cache.dart';
|
||||
import '../../support/pump_app.dart';
|
||||
import '../../support/test_dependencies.dart';
|
||||
|
||||
|
|
@ -74,7 +72,7 @@ void main() {
|
|||
late FakeNoteGateway noteGateway;
|
||||
late FakePdfSourceGateway pdfGateway;
|
||||
late FakeAssetGateway assetGateway;
|
||||
late MemoryAssetFileCache files;
|
||||
late MemoryFileCache files;
|
||||
late FakePdfEngine engine;
|
||||
|
||||
setUp(() {
|
||||
|
|
@ -95,7 +93,7 @@ void main() {
|
|||
noteGateway = FakeNoteGateway();
|
||||
pdfGateway = FakePdfSourceGateway();
|
||||
assetGateway = FakeAssetGateway();
|
||||
files = MemoryAssetFileCache();
|
||||
files = MemoryFileCache();
|
||||
engine = FakePdfEngine();
|
||||
});
|
||||
|
||||
|
|
@ -240,7 +238,7 @@ void main() {
|
|||
'selected, tied to the page', (tester) async {
|
||||
final assets = AssetRepository(
|
||||
assetGateway,
|
||||
FakeAssetServerGateway(),
|
||||
FakeFileServerGateway(),
|
||||
files,
|
||||
FakeAssetSealing(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -29,14 +29,12 @@ import 'package:material_ui/material_ui.dart';
|
|||
|
||||
import '../../support/fake_asset_gateway.dart';
|
||||
import '../../support/fake_asset_sealing.dart';
|
||||
import '../../support/fake_asset_server_gateway.dart';
|
||||
import '../../support/fake_card_gateway.dart';
|
||||
import '../../support/fake_conversation_gateway.dart';
|
||||
import '../../support/fake_grammar_gateway.dart';
|
||||
import '../../support/fake_photo_picker.dart';
|
||||
import '../../support/fake_settings_gateway.dart';
|
||||
import '../../support/fake_studyset_gateway.dart';
|
||||
import '../../support/memory_asset_file_cache.dart';
|
||||
import '../../support/memory_device_settings_store.dart';
|
||||
import '../../support/pump_app.dart';
|
||||
import '../../support/test_dependencies.dart';
|
||||
|
|
@ -123,7 +121,7 @@ void main() {
|
|||
late MemoryDeviceSettingsStore store;
|
||||
late List<Uri> searched;
|
||||
late FakeAssetGateway assetGateway;
|
||||
late MemoryAssetFileCache assetFiles;
|
||||
late MemoryFileCache assetFiles;
|
||||
late FakeGrammarGateway grammar;
|
||||
|
||||
setUp(() {
|
||||
|
|
@ -150,7 +148,7 @@ void main() {
|
|||
speech = FakeSpeechInput();
|
||||
searched = [];
|
||||
assetGateway = FakeAssetGateway();
|
||||
assetFiles = MemoryAssetFileCache();
|
||||
assetFiles = MemoryFileCache();
|
||||
grammar = FakeGrammarGateway(
|
||||
found: {
|
||||
'私はりんごは食べる': const [
|
||||
|
|
@ -1469,7 +1467,7 @@ void main() {
|
|||
Future<String> picturedCard() async {
|
||||
final assets = AssetRepository(
|
||||
assetGateway,
|
||||
FakeAssetServerGateway(),
|
||||
FakeFileServerGateway(),
|
||||
assetFiles,
|
||||
FakeAssetSealing(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@ import 'dart:typed_data';
|
|||
import 'dart:ui' show Rect;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/testing.dart'
|
||||
show FakeFileServerGateway, MemoryFileCache;
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/assistant/data/assistant_files.dart';
|
||||
import 'package:halkyon_learn_flutter/src/feature/pdf_source/model/pdf_source.dart';
|
||||
|
||||
import '../../../support/fake_asset_gateway.dart';
|
||||
import '../../../support/fake_asset_sealing.dart';
|
||||
import '../../../support/fake_asset_server_gateway.dart';
|
||||
import '../../../support/fake_pdf_engine.dart';
|
||||
import '../../../support/memory_asset_file_cache.dart';
|
||||
|
||||
// What a model is sent of the person's files (ADR 0021, D12): images every
|
||||
// provider reads, none larger than the smallest limit, and a PDF's pages
|
||||
|
|
@ -25,8 +25,8 @@ void main() {
|
|||
setUp(() {
|
||||
assets = AssetRepository(
|
||||
FakeAssetGateway(),
|
||||
FakeAssetServerGateway(),
|
||||
MemoryAssetFileCache(),
|
||||
FakeFileServerGateway(),
|
||||
MemoryFileCache(),
|
||||
FakeAssetSealing(),
|
||||
);
|
||||
engine = FakePdfEngine();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import 'dart:convert';
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/testing.dart'
|
||||
show FakeFileServerGateway, MemoryFileCache;
|
||||
import 'package:halkyon_editor/halkyon_editor.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/asset/data/asset_repository.dart';
|
||||
import 'package:halkyon_learn_flutter/src/core/content/published_ref.dart';
|
||||
|
|
@ -24,7 +26,6 @@ import 'package:material_ui/material_ui.dart' hide Card;
|
|||
|
||||
import '../../support/fake_asset_gateway.dart';
|
||||
import '../../support/fake_asset_sealing.dart';
|
||||
import '../../support/fake_asset_server_gateway.dart';
|
||||
import '../../support/fake_card_gateway.dart';
|
||||
import '../../support/fake_explore_gateway.dart';
|
||||
import '../../support/fake_learning_path_gateway.dart';
|
||||
|
|
@ -32,7 +33,6 @@ import '../../support/fake_note_gateway.dart';
|
|||
import '../../support/fake_pdf_source_gateway.dart';
|
||||
import '../../support/fake_studyset_gateway.dart';
|
||||
import '../../support/fake_tag_gateway.dart';
|
||||
import '../../support/memory_asset_file_cache.dart';
|
||||
import '../../support/pump_app.dart';
|
||||
import '../../support/test_dependencies.dart';
|
||||
|
||||
|
|
@ -95,8 +95,8 @@ void main() {
|
|||
final paths = LearningPathRepository(FakeLearningPathGateway());
|
||||
final assets = AssetRepository(
|
||||
FakeAssetGateway(),
|
||||
FakeAssetServerGateway(),
|
||||
MemoryAssetFileCache(),
|
||||
FakeFileServerGateway(),
|
||||
MemoryFileCache(),
|
||||
FakeAssetSealing(),
|
||||
);
|
||||
// The person added release 1 to their library before.
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue