mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2024-09-07 23:31:53 +00:00
xfer
This commit is contained in:
parent
b502bc20a7
commit
3c52931a74
@ -4,4 +4,5 @@ targets:
|
||||
json_serializable:
|
||||
options:
|
||||
explicit_to_json: true
|
||||
generic_argument_factories: true
|
||||
field_rename: snake
|
||||
|
@ -25,10 +25,13 @@ class LocalAccounts extends _$LocalAccounts
|
||||
@override
|
||||
String tableKeyName() => "local_accounts";
|
||||
@override
|
||||
IList<LocalAccount> reviveJson(Object? obj) => obj != null
|
||||
IList<LocalAccount> valueFromJson(Object? obj) => obj != null
|
||||
? IList<LocalAccount>.fromJson(
|
||||
obj, genericFromJson(LocalAccount.fromJson))
|
||||
: IList<LocalAccount>();
|
||||
@override
|
||||
Object? valueToJson(IList<LocalAccount> val) =>
|
||||
val.toJson((la) => la.toJson());
|
||||
|
||||
/// Get all local account information
|
||||
@override
|
||||
|
@ -21,9 +21,11 @@ class Logins extends _$Logins with AsyncTableDBBacked<ActiveLogins> {
|
||||
@override
|
||||
String tableKeyName() => "active_logins";
|
||||
@override
|
||||
ActiveLogins reviveJson(Object? obj) => obj != null
|
||||
ActiveLogins valueFromJson(Object? obj) => obj != null
|
||||
? ActiveLogins.fromJson(obj as Map<String, dynamic>)
|
||||
: ActiveLogins.empty();
|
||||
@override
|
||||
Object? valueToJson(ActiveLogins val) => val.toJson();
|
||||
|
||||
/// Get all local account information
|
||||
@override
|
||||
|
@ -2,5 +2,18 @@ import 'package:veilid/veilid.dart';
|
||||
|
||||
Future<VeilidConfig> getVeilidChatConfig() async {
|
||||
VeilidConfig config = await getDefaultVeilidConfig("VeilidChat");
|
||||
if (const String.fromEnvironment("DELETE_TABLE_STORE") == "1") {
|
||||
config =
|
||||
config.copyWith(tableStore: config.tableStore.copyWith(delete: true));
|
||||
}
|
||||
if (const String.fromEnvironment("DELETE_PROTECTED_STORE") == "1") {
|
||||
config = config.copyWith(
|
||||
protectedStore: config.protectedStore.copyWith(delete: true));
|
||||
}
|
||||
if (const String.fromEnvironment("DELETE_BLOCK_STORE") == "1") {
|
||||
config =
|
||||
config.copyWith(blockStore: config.blockStore.copyWith(delete: true));
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
@ -118,12 +118,12 @@ class DHTRecord {
|
||||
|
||||
Future<T> deleteScope<T>(Future<T> Function(DHTRecord) scopeFunction) async {
|
||||
try {
|
||||
return await scopeFunction(this);
|
||||
final out = await scopeFunction(this);
|
||||
close();
|
||||
return out;
|
||||
} catch (_) {
|
||||
delete();
|
||||
rethrow;
|
||||
} finally {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,13 +34,14 @@ Future<T> transactionScope<T>(
|
||||
abstract mixin class AsyncTableDBBacked<T> {
|
||||
String tableName();
|
||||
String tableKeyName();
|
||||
T reviveJson(Object? obj);
|
||||
T valueFromJson(Object? obj);
|
||||
Object? valueToJson(T val);
|
||||
|
||||
/// Load things from storage
|
||||
Future<T> load() async {
|
||||
final obj = await tableScope(tableName(), (tdb) async {
|
||||
final objJson = await tdb.loadStringJson(0, tableKeyName());
|
||||
return reviveJson(objJson);
|
||||
return valueFromJson(objJson);
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
@ -48,7 +49,7 @@ abstract mixin class AsyncTableDBBacked<T> {
|
||||
/// Store things to storage
|
||||
Future<void> store(T obj) async {
|
||||
await tableScope(tableName(), (tdb) async {
|
||||
await tdb.storeStringJson(0, tableKeyName(), obj);
|
||||
await tdb.storeStringJson(0, tableKeyName(), valueToJson(obj));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user