mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-08-21 20:41:50 +00:00
- Separate response success from business logic operation success - Remove ApiResponse, replace with GenericResult - Make GenericMutationResult inherit GenericResult - Add generic error message for when a response couldn't be sent or received
100 lines
3.1 KiB
Dart
100 lines
3.1 KiB
Dart
part of 'server.dart';
|
|
|
|
mixin VolumeApi on ApiMap {
|
|
Future<List<ServerDiskVolume>> getServerDiskVolumes() async {
|
|
QueryResult response;
|
|
List<ServerDiskVolume> volumes = [];
|
|
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
response = await client.query$GetServerDiskVolumes();
|
|
if (response.hasException) {
|
|
print(response.exception.toString());
|
|
}
|
|
volumes = response.data!['storage']['volumes']
|
|
.map<ServerDiskVolume>((final e) => ServerDiskVolume.fromJson(e))
|
|
.toList();
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
|
|
return volumes;
|
|
}
|
|
|
|
Future<void> mountVolume(final String volumeName) async {
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
final variables = Variables$Mutation$MountVolume(name: volumeName);
|
|
final mountVolumeMutation =
|
|
Options$Mutation$MountVolume(variables: variables);
|
|
await client.mutate$MountVolume(mountVolumeMutation);
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
}
|
|
|
|
Future<void> unmountVolume(final String volumeName) async {
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
final variables = Variables$Mutation$UnmountVolume(name: volumeName);
|
|
final unmountVolumeMutation =
|
|
Options$Mutation$UnmountVolume(variables: variables);
|
|
await client.mutate$UnmountVolume(unmountVolumeMutation);
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
}
|
|
|
|
Future<void> resizeVolume(final String volumeName) async {
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
final variables = Variables$Mutation$ResizeVolume(name: volumeName);
|
|
final resizeVolumeMutation =
|
|
Options$Mutation$ResizeVolume(variables: variables);
|
|
await client.mutate$ResizeVolume(resizeVolumeMutation);
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
}
|
|
|
|
Future<GenericMutationResult<String?>> migrateToBinds(
|
|
final Map<String, String> serviceToDisk,
|
|
) async {
|
|
GenericMutationResult<String?>? mutation;
|
|
|
|
try {
|
|
final GraphQLClient client = await getClient();
|
|
final input = Input$MigrateToBindsInput(
|
|
bitwardenBlockDevice: serviceToDisk['bitwarden']!,
|
|
emailBlockDevice: serviceToDisk['mailserver']!,
|
|
giteaBlockDevice: serviceToDisk['gitea']!,
|
|
nextcloudBlockDevice: serviceToDisk['nextcloud']!,
|
|
pleromaBlockDevice: serviceToDisk['pleroma']!,
|
|
);
|
|
final variables = Variables$Mutation$MigrateToBinds(input: input);
|
|
final migrateMutation =
|
|
Options$Mutation$MigrateToBinds(variables: variables);
|
|
final QueryResult<Mutation$MigrateToBinds> result =
|
|
await client.mutate$MigrateToBinds(
|
|
migrateMutation,
|
|
);
|
|
mutation = mutation = GenericMutationResult(
|
|
success: true,
|
|
code: result.parsedData!.migrateToBinds.code,
|
|
message: result.parsedData!.migrateToBinds.message,
|
|
data: result.parsedData!.migrateToBinds.job?.uid,
|
|
);
|
|
} catch (e) {
|
|
print(e);
|
|
mutation = GenericMutationResult(
|
|
success: false,
|
|
code: 0,
|
|
message: e.toString(),
|
|
data: null,
|
|
);
|
|
}
|
|
|
|
return mutation;
|
|
}
|
|
}
|