#1460 Added the Updater, it all seems to be working correctly. #865

pull/1514/head
Jamie.Rees 7 years ago
parent f6e0c25127
commit ce62606000

@ -6,5 +6,7 @@ namespace Ombi.Schedule.Ombi
public interface IOmbiAutomaticUpdater
{
Task Update(PerformContext context);
string[] GetVersion();
Task<bool> UpdateAvailable(string branch, string currentVersion);
}
}

@ -5,10 +5,8 @@ using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Threading.Tasks;
using Hangfire.Console;
using Hangfire.Server;
@ -16,29 +14,53 @@ using Microsoft.Extensions.Logging;
using Ombi.Api.Service;
using Ombi.Api.Service.Models;
using Ombi.Core.Settings;
using Ombi.Helpers;
using Ombi.Schedule.Ombi;
using Ombi.Settings.Settings.Models;
namespace Ombi.Schedule.Jobs.Ombi
{
public class OmbiAutomaticUpdater : IOmbiAutomaticUpdater
{
public OmbiAutomaticUpdater(ILogger<OmbiAutomaticUpdater> log, IOmbiService service)
public OmbiAutomaticUpdater(ILogger<OmbiAutomaticUpdater> log, IOmbiService service,
ISettingsService<UpdateSettings> s)
{
Logger = log;
OmbiService = service;
Settings = s;
}
private ILogger<OmbiAutomaticUpdater> Logger { get; }
private IOmbiService OmbiService { get; }
private ISettingsService<UpdateSettings> Settings { get;s }
private static PerformContext Ctx { get; set; }
public string[] GetVersion()
{
var productVersion = AssemblyHelper.GetRuntimeVersion();
var productArray = productVersion.Split('-');
return productArray;
}
public async Task<bool> UpdateAvailable(string branch, string currentVersion)
{
var updates = await OmbiService.GetUpdates(branch);
var serverVersion = updates.UpdateVersionString;
return !serverVersion.Equals(currentVersion, StringComparison.CurrentCultureIgnoreCase);
}
public async Task Update(PerformContext c)
{
Ctx = c;
Ctx.WriteLine("Starting the updater");
// IF AutoUpdateEnabled =>
// ELSE Return;
var settings = await Settings.GetSettingsAsync();
if (!settings.AutoUpdateEnabled)
{
Ctx.WriteLine("Auto update is not enabled");
return;
}
var currentLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
Ctx.WriteLine("Path: {0}", currentLocation);
@ -48,7 +70,7 @@ namespace Ombi.Schedule.Jobs.Ombi
try
{
var productArray = productVersion.Split('-');
var productArray = GetVersion();
var version = productArray[0];
Ctx.WriteLine("Version {0}", version);
var branch = productArray[1];

@ -0,0 +1,7 @@
namespace Ombi.Settings.Settings.Models
{
public class UpdateSettings : Settings
{
public bool AutoUpdateEnabled { get; set; }
}
}

@ -17,6 +17,10 @@ export interface IOmbiSettings extends ISettings {
allowExternalUsersToAuthenticate: boolean;
}
export interface IUpdateSettings extends ISettings {
autoUpdateEnabled: boolean;
}
export interface IEmbySettings extends ISettings {
enable: boolean;
servers: IEmbyServer[];

@ -9,3 +9,4 @@ export * from "./search.service";
export * from "./service.helpers";
export * from "./settings.service";
export * from "./status.service";
export * from "./update.service";

@ -18,6 +18,7 @@ import {
IRadarrSettings,
ISlackNotificationSettings,
ISonarrSettings,
IUpdateSettings
} from "../interfaces";
import { ServiceAuthHelpers } from "./service.helpers";
@ -166,4 +167,14 @@ export class SettingsService extends ServiceAuthHelpers {
.post(`${this.url}/notifications/slack`, JSON.stringify(settings), { headers: this.headers })
.map(this.extractData).catch(this.handleError);
}
public getUpdateSettings(): Observable<IUpdateSettings> {
return this.httpAuth.get(`${this.url}/update`).map(this.extractData).catch(this.handleError);
}
public saveUpdateSettings(settings: IUpdateSettings): Observable<boolean> {
return this.httpAuth
.post(`${this.url}/update`, JSON.stringify(settings), { headers: this.headers })
.map(this.extractData).catch(this.handleError);
}
}

@ -0,0 +1,20 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { AuthHttp } from "angular2-jwt";
import { Observable } from "rxjs/Rx";
import { ServiceAuthHelpers } from "./service.helpers";
@Injectable()
export class UpdateService extends ServiceAuthHelpers {
constructor(http: AuthHttp, private regularHttp: Http) {
super(http, "/api/v1/Jobs/");
}
public forceUpdate(): Observable<boolean> {
return this.regularHttp.post(`${this.url}update/`, { headers: this.headers }).map(this.extractData);
}
public checkForNewUpdate(): Observable<boolean> {
return this.http.get(`${this.url}update/`).map(this.extractData);
}
}

@ -0,0 +1,36 @@

<settings-menu></settings-menu>
<div *ngIf="form">
<fieldset>
<legend>Update Settings</legend>
<form novalidate [formGroup]="form" (ngSubmit)="onSubmit(form)" style="padding-top:5%;">
<div class="col-md-6">
<div class="form-group">
<div class="checkbox">
<input type="checkbox" id="autoUpdateEnabled" formControlName="autoUpdateEnabled">
<label for="autoUpdateEnabled">Enable Automatic Update</label>
</div>
</div>
<div class="form-group" *ngIf="!updateAvailable">
<div>
<button (click)="checkForUpdate()" class="btn btn-primary-outline">Check For Update</button>
</div>
</div>
<div class="form-group" *ngIf="updateAvailable">
<div>
<button (click)="update()" class="btn btn-success-outline">Update</button>
</div>
</div>
<div class="form-group">
<div>
<button type="submit" class="btn btn-primary-outline ">Submit</button>
</div>
</div>
</div>
</form>
</fieldset>
</div>

@ -0,0 +1,58 @@
import { Component, OnInit } from "@angular/core";
import { FormBuilder, FormGroup } from "@angular/forms";
import { NotificationService } from "../../services";
import { SettingsService, UpdateService } from "../../services";
@Component({
templateUrl: "./update.component.html",
})
export class UpdateComponent implements OnInit {
public form: FormGroup;
public updateAvailable = false;
constructor(private settingsService: SettingsService,
private notificationService: NotificationService,
private updateService: UpdateService,
private fb: FormBuilder) { }
public ngOnInit() {
this.settingsService.getUpdateSettings()
.subscribe(x => {
this.form = this.fb.group({
autoUpdateEnabled: [x.autoUpdateEnabled],
});
});
}
public checkForUpdate() {
this.updateService.checkForNewUpdate().subscribe(x => {
if (x) {
this.updateAvailable = true;
this.notificationService.success("Update", "There is a new update available");
}
});
}
public update() {
this.updateService.forceUpdate().subscribe();
this.notificationService.success("Update", "We triggered the update job");
}
public onSubmit(form: FormGroup) {
if (form.invalid) {
this.notificationService.error("Validation", "Please check your entered values");
return;
}
this.settingsService.saveUpdateSettings(form.value)
.subscribe(x => {
if (x) {
this.notificationService.success("Settings Saved", "Successfully saved Update settings");
} else {
this.notificationService.error("Settings Saved", "There was an error when saving the Update settings");
}
});
}
}

@ -32,7 +32,6 @@ namespace Ombi.Controllers
/// <summary>
/// The Identity Controller, the API for everything Identity/User related
/// </summary>
/// <seealso cref="Ombi.Controllers.BaseV1ApiController" />
[PowerUser]
[ApiV1]
[Produces("application/json")]

@ -0,0 +1,40 @@
using System.Threading.Tasks;
using Hangfire;
using Microsoft.AspNetCore.Mvc;
using Ombi.Api.Service;
using Ombi.Attributes;
using Ombi.Schedule.Ombi;
namespace Ombi.Controllers
{
[ApiV1]
[Admin]
[Produces("application/json")]
public class JobController : Controller
{
public JobController(IOmbiAutomaticUpdater updater)
{
_updater = updater;
}
private readonly IOmbiAutomaticUpdater _updater;
[HttpPost("update")]
public bool ForceUpdate()
{
BackgroundJob.Enqueue(() => _updater.Update(null));
return true;
}
[HttpGet("update")]
public async Task<bool> CheckForUpdate()
{
var productArray = _updater.GetVersion();
var version = productArray[0];
var branch = productArray[1];
var updateAvailable = await _updater.UpdateAvailable(branch, version);
return updateAvailable;
}
}
}

@ -266,6 +266,28 @@ namespace Ombi.Controllers
return result;
}
/// <summary>
/// Save the Update settings.
/// </summary>
/// <param name="settings">The settings.</param>
/// <returns></returns>
[HttpPost("Update")]
public async Task<bool> UpdateSettings([FromBody]UpdateSettings settings)
{
return await Save(settings);
}
/// <summary>
/// Gets the Update Settings.
/// </summary>
/// <returns></returns>
[HttpGet("Update")]
public async Task<UpdateSettings> UpdateSettings()
{
return await Get<UpdateSettings>();
}
/// <summary>
/// Saves the email notification settings.
/// </summary>

@ -69,7 +69,6 @@
<ItemGroup>
<Folder Include="ClientApp\app\settings\update\" />
<Folder Include="Styles\" />
</ItemGroup>

Loading…
Cancel
Save