Merge pull request #72 from Moonlight-Panel/FixBackupDelete
Fix backup delete
This commit is contained in:
@@ -5,7 +5,7 @@ namespace Moonlight.App.Exceptions;
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class DaemonException : Exception
|
public class DaemonException : Exception
|
||||||
{
|
{
|
||||||
public int StatusCode { private get; set; }
|
public int StatusCode { get; set; }
|
||||||
|
|
||||||
public DaemonException()
|
public DaemonException()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace Moonlight.App.Exceptions;
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class PleskException : Exception
|
public class PleskException : Exception
|
||||||
{
|
{
|
||||||
public int StatusCode { private get; set; }
|
public int StatusCode { get; set; }
|
||||||
|
|
||||||
public PleskException()
|
public PleskException()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace Moonlight.App.Exceptions;
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class WingsException : Exception
|
public class WingsException : Exception
|
||||||
{
|
{
|
||||||
public int StatusCode { private get; set; }
|
public int StatusCode { get; set; }
|
||||||
|
|
||||||
public WingsException()
|
public WingsException()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -186,8 +186,20 @@ public class ServerService
|
|||||||
.Include(x => x.Backups)
|
.Include(x => x.Backups)
|
||||||
.First(x => x.Id == server.Id);
|
.First(x => x.Id == server.Id);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
await WingsApiHelper.Delete(serverData.Node, $"api/servers/{serverData.Uuid}/backup/{serverBackup.Uuid}",
|
await WingsApiHelper.Delete(serverData.Node, $"api/servers/{serverData.Uuid}/backup/{serverBackup.Uuid}",
|
||||||
null);
|
null);
|
||||||
|
}
|
||||||
|
catch (WingsException e)
|
||||||
|
{
|
||||||
|
// when a backup is not longer there we can
|
||||||
|
// safely delete the backup so we ignore this error
|
||||||
|
if (e.StatusCode != 404)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var backup = serverData.Backups.First(x => x.Uuid == serverBackup.Uuid);
|
var backup = serverData.Backups.First(x => x.Uuid == serverBackup.Uuid);
|
||||||
serverData.Backups.Remove(backup);
|
serverData.Backups.Remove(backup);
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ else
|
|||||||
SmartTranslateService.Translate("Error from daemon"),
|
SmartTranslateService.Translate("Error from daemon"),
|
||||||
wingsException.Message
|
wingsException.Message
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//TODO: Error log service
|
||||||
|
|
||||||
|
Logger.Warn($"Wings exception status code: {wingsException.StatusCode}");
|
||||||
}
|
}
|
||||||
else if (exception is PleskException pleskException)
|
else if (exception is PleskException pleskException)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -185,25 +185,26 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task Download(ServerBackup serverBackup)
|
private async Task Download(ServerBackup serverBackup)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
var url = await ServerService.DownloadBackup(CurrentServer, serverBackup);
|
var url = await ServerService.DownloadBackup(CurrentServer, serverBackup);
|
||||||
|
|
||||||
NavigationManager.NavigateTo(url);
|
NavigationManager.NavigateTo(url);
|
||||||
await ToastService.Success(SmartTranslateService.Translate("Backup download successfully started"));
|
await ToastService.Success(SmartTranslateService.Translate("Backup download successfully started"));
|
||||||
|
|
||||||
|
/*
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Warn("Error starting backup download");
|
Logger.Warn("Error starting backup download");
|
||||||
Logger.Warn(e);
|
Logger.Warn(e);
|
||||||
await ToastService.Error(SmartTranslateService.Translate("Backup download failed"));
|
await ToastService.Error(SmartTranslateService.Translate("Backup download failed"));
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CopyUrl(ServerBackup serverBackup)
|
private async Task CopyUrl(ServerBackup serverBackup)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
var url = await ServerService.DownloadBackup(CurrentServer, serverBackup);
|
var url = await ServerService.DownloadBackup(CurrentServer, serverBackup);
|
||||||
|
|
||||||
@@ -211,61 +212,68 @@
|
|||||||
await AlertService.Success(
|
await AlertService.Success(
|
||||||
SmartTranslateService.Translate("Success"),
|
SmartTranslateService.Translate("Success"),
|
||||||
SmartTranslateService.Translate("Backup URL successfully copied to your clipboard"));
|
SmartTranslateService.Translate("Backup URL successfully copied to your clipboard"));
|
||||||
|
|
||||||
|
/*
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Warn("Error copying backup url");
|
Logger.Warn("Error copying backup url");
|
||||||
Logger.Warn(e);
|
Logger.Warn(e);
|
||||||
await ToastService.Error(SmartTranslateService.Translate("An unknown error occured while generating backup url"));
|
await ToastService.Error(SmartTranslateService.Translate("An unknown error occured while generating backup url"));
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Delete(ServerBackup serverBackup)
|
private async Task Delete(ServerBackup serverBackup)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
await ToastService.Info(SmartTranslateService.Translate("Backup deletion started"));
|
await ToastService.Info(SmartTranslateService.Translate("Backup deletion started"));
|
||||||
await ServerService.DeleteBackup(CurrentServer, serverBackup);
|
await ServerService.DeleteBackup(CurrentServer, serverBackup);
|
||||||
|
|
||||||
|
/*
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Warn("Error deleting backup");
|
Logger.Warn("Error deleting backup");
|
||||||
Logger.Warn(e);
|
Logger.Warn(e);
|
||||||
await ToastService.Error(SmartTranslateService.Translate("An unknown error occured while starting backup deletion"));
|
await ToastService.Error(SmartTranslateService.Translate("An unknown error occured while starting backup deletion"));
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Restore(ServerBackup serverBackup)
|
private async Task Restore(ServerBackup serverBackup)
|
||||||
{
|
{
|
||||||
|
await ServerService.RestoreBackup(CurrentServer, serverBackup);
|
||||||
|
await ToastService.Info(SmartTranslateService.Translate("Backup restore started"));
|
||||||
|
|
||||||
|
/*
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await ServerService.RestoreBackup(CurrentServer, serverBackup);
|
|
||||||
|
|
||||||
await ToastService.Info(SmartTranslateService.Translate("Backup restore started"));
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Warn("Error restoring backup");
|
Logger.Warn("Error restoring backup");
|
||||||
Logger.Warn(e);
|
Logger.Warn(e);
|
||||||
await ToastService.Error(SmartTranslateService.Translate("An unknown error occured while restoring a backup"));
|
await ToastService.Error(SmartTranslateService.Translate("An unknown error occured while restoring a backup"));
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Create()
|
private async Task Create()
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
await ToastService.Info(SmartTranslateService.Translate("Started backup creation"));
|
await ToastService.Info(SmartTranslateService.Translate("Started backup creation"));
|
||||||
var backup = await ServerService.CreateBackup(CurrentServer);
|
await ServerService.CreateBackup(CurrentServer);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
try
|
||||||
|
{
|
||||||
// Modify the backup list so no reload needed. Also the create event will work
|
// Modify the backup list so no reload needed. Also the create event will work
|
||||||
var list = AllBackups!.ToList();
|
//var list = AllBackups!.ToList();
|
||||||
list.Add(backup);
|
//list.Add(backup);
|
||||||
AllBackups = list.ToArray();
|
//AllBackups = list.ToArray();
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
await LazyLoader.Reload();
|
await LazyLoader.Reload();
|
||||||
}
|
}
|
||||||
@@ -274,7 +282,7 @@
|
|||||||
Logger.Warn("Error creating backup");
|
Logger.Warn("Error creating backup");
|
||||||
Logger.Warn(e);
|
Logger.Warn(e);
|
||||||
await ToastService.Error(SmartTranslateService.Translate("An unknown error has occured while creating a backup"));
|
await ToastService.Error(SmartTranslateService.Translate("An unknown error has occured while creating a backup"));
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnContextMenuClick(ItemClickEventArgs args)
|
private async Task OnContextMenuClick(ItemClickEventArgs args)
|
||||||
|
|||||||
Reference in New Issue
Block a user