2023-06-29 09:52:09 +00:00
|
|
|
part of 'server_api.dart';
|
|
|
|
|
|
|
|
mixin BackupsApi on GraphQLApiMap {
|
|
|
|
Future<List<Backup>> getBackups() async {
|
|
|
|
List<Backup> backups;
|
|
|
|
QueryResult<Query$AllBackupSnapshots> response;
|
|
|
|
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
|
|
|
response = await client.query$AllBackupSnapshots();
|
|
|
|
if (response.hasException) {
|
|
|
|
final message = response.exception.toString();
|
|
|
|
print(message);
|
|
|
|
backups = [];
|
|
|
|
}
|
|
|
|
final List<Backup> parsed = response.parsedData!.backup.allSnapshots
|
|
|
|
.map(
|
|
|
|
(
|
|
|
|
final Query$AllBackupSnapshots$backup$allSnapshots snapshot,
|
|
|
|
) =>
|
|
|
|
Backup.fromGraphQL(snapshot),
|
|
|
|
)
|
|
|
|
.toList();
|
|
|
|
backups = parsed;
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
backups = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return backups;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<BackupConfiguration?> getBackupsConfiguration() async {
|
|
|
|
BackupConfiguration? backupConfiguration;
|
|
|
|
QueryResult<Query$BackupConfiguration> response;
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
|
|
|
response = await client.query$BackupConfiguration();
|
|
|
|
if (response.hasException) {
|
|
|
|
final message = response.exception.toString();
|
|
|
|
print(message);
|
|
|
|
backupConfiguration = null;
|
|
|
|
}
|
|
|
|
final BackupConfiguration parsed = BackupConfiguration.fromGraphQL(
|
|
|
|
response.parsedData!.backup.configuration,
|
|
|
|
);
|
|
|
|
backupConfiguration = parsed;
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
backupConfiguration = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return backupConfiguration;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<GenericResult> forceBackupListReload() async {
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
|
|
|
await client.mutate$ForceSnapshotsReload();
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
return GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: e.toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GenericResult(
|
|
|
|
success: true,
|
|
|
|
data: null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-29 18:38:46 +00:00
|
|
|
Future<GenericResult<ServerJob?>> startBackup(final String serviceId) async {
|
2023-06-29 09:52:09 +00:00
|
|
|
QueryResult<Mutation$StartBackup> response;
|
2023-06-29 18:38:46 +00:00
|
|
|
GenericResult<ServerJob?>? result;
|
2023-06-29 09:52:09 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
|
|
|
final variables = Variables$Mutation$StartBackup(serviceId: serviceId);
|
|
|
|
final options = Options$Mutation$StartBackup(variables: variables);
|
|
|
|
response = await client.mutate$StartBackup(options);
|
|
|
|
if (response.hasException) {
|
|
|
|
final message = response.exception.toString();
|
|
|
|
print(message);
|
|
|
|
result = GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: message,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
result = GenericResult(
|
|
|
|
success: true,
|
2023-06-29 18:38:46 +00:00
|
|
|
data: ServerJob.fromGraphQL(
|
|
|
|
response.parsedData!.backup.startBackup.job!,
|
|
|
|
),
|
2023-06-29 09:52:09 +00:00
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
result = GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: e.toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<GenericResult> setAutobackupPeriod({final int? period}) async {
|
|
|
|
QueryResult<Mutation$SetAutobackupPeriod> response;
|
|
|
|
GenericResult? result;
|
|
|
|
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
|
|
|
final variables = Variables$Mutation$SetAutobackupPeriod(period: period);
|
|
|
|
final options =
|
|
|
|
Options$Mutation$SetAutobackupPeriod(variables: variables);
|
|
|
|
response = await client.mutate$SetAutobackupPeriod(options);
|
|
|
|
if (response.hasException) {
|
|
|
|
final message = response.exception.toString();
|
|
|
|
print(message);
|
|
|
|
result = GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: message,
|
|
|
|
);
|
2023-09-09 18:13:27 +00:00
|
|
|
}
|
|
|
|
result = GenericResult(
|
|
|
|
success: true,
|
|
|
|
data: null,
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
result = GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: e.toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<GenericResult> setAutobackupQuotas(
|
|
|
|
final AutobackupQuotas quotas,
|
|
|
|
) async {
|
|
|
|
QueryResult<Mutation$setAutobackupQuotas> response;
|
|
|
|
GenericResult? result;
|
|
|
|
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
|
|
|
final variables = Variables$Mutation$setAutobackupQuotas(
|
|
|
|
quotas: Input$AutobackupQuotasInput(
|
|
|
|
last: quotas.last,
|
|
|
|
daily: quotas.daily,
|
|
|
|
weekly: quotas.weekly,
|
|
|
|
monthly: quotas.monthly,
|
|
|
|
yearly: quotas.yearly,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
final options =
|
|
|
|
Options$Mutation$setAutobackupQuotas(variables: variables);
|
|
|
|
response = await client.mutate$setAutobackupQuotas(options);
|
|
|
|
if (response.hasException) {
|
|
|
|
final message = response.exception.toString();
|
|
|
|
print(message);
|
|
|
|
result = GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: message,
|
|
|
|
);
|
2023-06-29 09:52:09 +00:00
|
|
|
}
|
|
|
|
result = GenericResult(
|
|
|
|
success: true,
|
|
|
|
data: null,
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
result = GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: e.toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<GenericResult> removeRepository() async {
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
|
|
|
await client.mutate$RemoveRepository();
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
return GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: e.toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GenericResult(
|
|
|
|
success: true,
|
|
|
|
data: null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<GenericResult> initializeRepository(
|
|
|
|
final InitializeRepositoryInput input,
|
|
|
|
) async {
|
|
|
|
QueryResult<Mutation$InitializeRepository> response;
|
|
|
|
GenericResult? result;
|
|
|
|
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
|
|
|
final variables = Variables$Mutation$InitializeRepository(
|
|
|
|
repository: Input$InitializeRepositoryInput(
|
|
|
|
locationId: input.locationId,
|
|
|
|
locationName: input.locationName,
|
|
|
|
login: input.login,
|
|
|
|
password: input.password,
|
|
|
|
provider: input.provider.toGraphQL(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
final options =
|
|
|
|
Options$Mutation$InitializeRepository(variables: variables);
|
|
|
|
response = await client.mutate$InitializeRepository(options);
|
|
|
|
if (response.hasException) {
|
|
|
|
final message = response.exception.toString();
|
|
|
|
print(message);
|
|
|
|
result = GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: message,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
result = GenericResult(
|
|
|
|
success: true,
|
|
|
|
data: null,
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
result = GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: e.toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2023-06-29 18:38:46 +00:00
|
|
|
|
|
|
|
Future<GenericResult<ServerJob?>> restoreBackup(
|
|
|
|
final String snapshotId,
|
2023-08-07 12:23:48 +00:00
|
|
|
final BackupRestoreStrategy strategy,
|
2023-06-29 18:38:46 +00:00
|
|
|
) async {
|
|
|
|
QueryResult<Mutation$RestoreBackup> response;
|
|
|
|
GenericResult<ServerJob?>? result;
|
|
|
|
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
2023-08-07 12:23:48 +00:00
|
|
|
final variables = Variables$Mutation$RestoreBackup(
|
|
|
|
snapshotId: snapshotId,
|
|
|
|
strategy: strategy.toGraphQL,
|
|
|
|
);
|
2023-06-29 18:38:46 +00:00
|
|
|
final options = Options$Mutation$RestoreBackup(variables: variables);
|
|
|
|
response = await client.mutate$RestoreBackup(options);
|
|
|
|
if (response.hasException) {
|
|
|
|
final message = response.exception.toString();
|
|
|
|
print(message);
|
|
|
|
result = GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: message,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
result = GenericResult(
|
|
|
|
success: true,
|
|
|
|
data: ServerJob.fromGraphQL(
|
|
|
|
response.parsedData!.backup.restoreBackup.job!,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
result = GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: e.toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2023-08-07 12:44:26 +00:00
|
|
|
|
|
|
|
Future<GenericResult<bool?>> forgetSnapshot(
|
|
|
|
final String snapshotId,
|
|
|
|
) async {
|
|
|
|
QueryResult<Mutation$ForgetSnapshot> response;
|
|
|
|
GenericResult<bool?>? result;
|
|
|
|
|
|
|
|
try {
|
|
|
|
final GraphQLClient client = await getClient();
|
|
|
|
final variables = Variables$Mutation$ForgetSnapshot(
|
|
|
|
snapshotId: snapshotId,
|
|
|
|
);
|
|
|
|
final options = Options$Mutation$ForgetSnapshot(variables: variables);
|
|
|
|
response = await client.mutate$ForgetSnapshot(options);
|
|
|
|
if (response.hasException) {
|
|
|
|
final message = response.exception.toString();
|
|
|
|
print(message);
|
|
|
|
result = GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: message,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
result = GenericResult(
|
|
|
|
success: true,
|
|
|
|
data: response.parsedData!.backup.forgetSnapshot.success,
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
result = GenericResult(
|
|
|
|
success: false,
|
|
|
|
data: null,
|
|
|
|
message: e.toString(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2023-06-29 09:52:09 +00:00
|
|
|
}
|