OneDrive Backup

OneDrive Backup
This commit is contained in:
2023-07-28 22:36:06 +07:00
parent e1c6e91a0a
commit d70d81ebdf
244 changed files with 75229 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
@page "/about"
<h1>About...</h1>
<h2>Official Repository</h2>
<p>You can find the code and documentation for the addon on the officail <a href="https://github.com/lavinir/hassio-onedrive-backup" target="_blank">GitHub Repo</a></p>
<h2>Open Issues</h2>
<p>If you encounter any bugs or issues with the add-on, please open an issue if needed <a href="https://github.com/lavinir/hassio-onedrive-backup/issues" target="_blank">here</a></p>
<h2>Suggest Features</h2>
<p>If you have any suggestions for new features or improvements to the add-on, please submit them on the offical <a href="https://github.com/lavinir/hassio-onedrive-backup/discussions/categories/ideas" target="_blank">GitHub repository discussions</a>.</p>
<h2>License</h2>
<p>I originally wanted a native cloud backup solution for Home Assistant with OneDrive which is why I created this. It has become a passion project and I am actively maintaining and supporting it. Completely free to use but if you
would like to show support for the project you could <a href="https://www.buymeacoffee.com/snirlavis" target="_blank"><img class="mx-1" src="bmc/bmc-button.svg" alt="Buy Me A Coffee" style="height: 1.8rem !important;"></a> :)
</p>
<div class="d-flex flex-column align-items-center">
<img src="images/Bitcoin-Logo.svg" alt="Bitcoin logo" style="width: 100px; height: auto; transform: scale(0.8);">
<img src="images/bc_address.png" alt="Bitcoin address" style="width: 100px; height: auto;">
<span class="text-center"><strong>Bitcoin Address</strong>: bc1q8htme48sx54gvctk59yxg3ts940ncf6p8377r6</span>
</div>
@code {
}
+24
View File
@@ -0,0 +1,24 @@
@page
@model hassio_onedrive_backup.Pages.ErrorModel
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Error</title>
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" />
</head>
<body>
<div class="main">
<div class="content px-4">
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
</div>
</div>
</body>
</html>
+27
View File
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;
namespace hassio_onedrive_backup.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
private readonly ILogger<ErrorModel> _logger;
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
+73
View File
@@ -0,0 +1,73 @@
@page "/"
@using hassio_onedrive_backup.Contracts;
@using hassio_onedrive_backup.Graph;
@using hassio_onedrive_backup;
@using onedrive_backup.Extensions;
@using onedrive_backup.Hass;
@using onedrive_backup.Models;
@using static hassio_onedrive_backup.Contracts.HassBackupsResponse;
@inject IGraphHelper GraphHelper
@inject Orchestrator Orchestrator
@inject HassContext HassContext;
<div class="container">
<div class="row justify-content-center">
<div class="col-12 d-flex justify-content-center">
<onedrive_backup.Shared.OneDriveSummaryCard />
</div>
</div>
</div>
<div class="container">
<div class="row row-cols-1 row-cols-md-3 g-4">
@foreach (var backup in Backups)
{
<div class="col">
<onedrive_backup.Shared.BackupCard Backup="@backup" />
</div>
}
</div>
</div>
@code
{
private List<BackupModel> Backups => GetBackupModels();
protected override void OnInitialized()
{
base.OnInitialized();
GraphHelper.AuthStatusChangedEventHandler += OnStateChanged;
Orchestrator.BackupManager.OneDriveBackupsUpdated += OnStateChanged;
Orchestrator.BackupManager.LocalBackupsUpdated += OnStateChanged;
}
private List<BackupModel> GetBackupModels()
{
var ret = new List<BackupModel>();
var _localBackups = Orchestrator.BackupManager.LocalBackups?.Select(backup => backup.ToBackupModel(HassContext)) ?? Enumerable.Empty<BackupModel>();
var _onedriveBackups = Orchestrator.BackupManager.OnlineBackups?.Select(backup => backup.ToBackupModel(HassContext)) ?? Enumerable.Empty<BackupModel>();
ret.AddRange(_onedriveBackups);
foreach (var localBackup in _localBackups)
{
if (_onedriveBackups.Any(oneDriveBackup => oneDriveBackup.Slug == localBackup.Slug))
{
var syncedBackup = ret.Find(backup => backup.Slug == localBackup.Slug);
syncedBackup.Location = BackupModel.BackupLocation.Both;
continue;
}
ret.Add(localBackup);
}
ret = ret.OrderByDescending(backup => backup.Date).ToList();
return ret;
}
private async void OnStateChanged()
{
await InvokeAsync(() =>
{
StateHasChanged();
});
}
}
+42
View File
@@ -0,0 +1,42 @@
@page "/"
@using Microsoft.AspNetCore.Components.Web
@using onedrive_backup;
@using onedrive_backup.Hass;
@namespace hassio_onedrive_backup.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@inject HassContext IngressSettings
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="@IngressSettings.IngressUrl" />
<link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
<link href="onedrive-backup.styles.css" rel="stylesheet" />
<link rel="icon" type="image/png" href="favicon.png"/>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
<body style="background: #f4f4f4; background-image: linear-gradient(to bottom, #f4f4f4, #e6e6e6);">
<div id="alertPlaceholder"></div>
<component type="typeof(App)" render-mode="ServerPrerendered" />
<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="lib/jquery/jquery.slim.min.js"></script>
<script src="lib/popper.js/umd/popper.min.js"></script>
<script src="lib/bootstrap/js/bootstrap.min.js"></script>
<script src="scripts/BlazorHelpers.js"></script>
<script src="_framework/blazor.server.js"></script>
</body>
</html>