refactor: Make support for file storing optional in database API
This commit is contained in:
parent
ab0ff46900
commit
c387b33e9f
|
|
@ -75,6 +75,9 @@ class Database extends _$Database implements DatabaseApi {
|
||||||
|
|
||||||
Database.connect(DatabaseConnection connection) : super.connect(connection);
|
Database.connect(DatabaseConnection connection) : super.connect(connection);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get supportsFileStoring => true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get schemaVersion => 12;
|
int get schemaVersion => 12;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import '../../famedlysdk.dart';
|
||||||
|
|
||||||
abstract class DatabaseApi {
|
abstract class DatabaseApi {
|
||||||
int get maxFileSize => 1 * 1024 * 1024;
|
int get maxFileSize => 1 * 1024 * 1024;
|
||||||
|
bool get supportsFileStoring => false;
|
||||||
Future<Map<String, dynamic>> getClient(String name);
|
Future<Map<String, dynamic>> getClient(String name);
|
||||||
|
|
||||||
Future updateClient(
|
Future updateClient(
|
||||||
|
|
|
||||||
|
|
@ -590,7 +590,8 @@ void main() {
|
||||||
final client = await getClient();
|
final client = await getClient();
|
||||||
final response = await client.uploadContent(Uint8List(0), 'file.jpeg');
|
final response = await client.uploadContent(Uint8List(0), 'file.jpeg');
|
||||||
expect(response, 'mxc://example.com/AQwafuaFswefuhsfAFAgsw');
|
expect(response, 'mxc://example.com/AQwafuaFswefuhsfAFAgsw');
|
||||||
expect(await client.database.getFile(response) != null, true);
|
expect(await client.database.getFile(response) != null,
|
||||||
|
client.database.supportsFileStoring);
|
||||||
await client.dispose(closeDatabase: true);
|
await client.dispose(closeDatabase: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1263,13 +1263,15 @@ void main() {
|
||||||
expect(await event.isAttachmentInLocalStore(), false);
|
expect(await event.isAttachmentInLocalStore(), false);
|
||||||
var buffer = await event.downloadAndDecryptAttachment(
|
var buffer = await event.downloadAndDecryptAttachment(
|
||||||
downloadCallback: downloadCallback);
|
downloadCallback: downloadCallback);
|
||||||
expect(await event.isAttachmentInLocalStore(), true);
|
expect(await event.isAttachmentInLocalStore(),
|
||||||
|
event.room.client.database.supportsFileStoring);
|
||||||
expect(buffer.bytes, FILE_BUFF);
|
expect(buffer.bytes, FILE_BUFF);
|
||||||
expect(serverHits, 1);
|
expect(serverHits, 1);
|
||||||
buffer = await event.downloadAndDecryptAttachment(
|
buffer = await event.downloadAndDecryptAttachment(
|
||||||
downloadCallback: downloadCallback);
|
downloadCallback: downloadCallback);
|
||||||
expect(buffer.bytes, FILE_BUFF);
|
expect(buffer.bytes, FILE_BUFF);
|
||||||
expect(serverHits, 1);
|
expect(
|
||||||
|
serverHits, event.room.client.database.supportsFileStoring ? 1 : 2);
|
||||||
|
|
||||||
await room.client.dispose(closeDatabase: true);
|
await room.client.dispose(closeDatabase: true);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue