selfprivacy.org.app/lib/logic/models/hive/backups_credential.dart
2023-06-16 04:28:45 +03:00

52 lines
1.3 KiB
Dart

import 'dart:convert';
import 'package:hive/hive.dart';
import 'package:selfprivacy/logic/api_maps/graphql_maps/schema/schema.graphql.dart';
part 'backups_credential.g.dart';
@HiveType(typeId: 4)
class BackupsCredential {
BackupsCredential({required this.keyId, required this.applicationKey, required this.provider});
@HiveField(0)
final String keyId;
@HiveField(1)
final String applicationKey;
@HiveField(2, defaultValue: BackupsProvider.backblaze)
final BackupsProvider provider;
String get encodedApiKey => encodedBackblazeKey(keyId, applicationKey);
@override
String toString() => '$keyId: $encodedApiKey';
}
String encodedBackblazeKey(final String? keyId, final String? applicationKey) {
final String apiKey = '$keyId:$applicationKey';
final String encodedApiKey = base64.encode(utf8.encode(apiKey));
return encodedApiKey;
}
@HiveType(typeId: 103)
enum BackupsProvider {
@HiveField(0)
none,
@HiveField(1)
memory,
@HiveField(2)
file,
@HiveField(3)
backblaze;
factory BackupsProvider.fromGraphQL(final Enum$BackupProvider provider) => switch (provider) {
Enum$BackupProvider.NONE => none,
Enum$BackupProvider.MEMORY => memory,
Enum$BackupProvider.FILE => file,
Enum$BackupProvider.BACKBLAZE => backblaze,
Enum$BackupProvider.$unknown => none
};
}