missed changes

This commit is contained in:
tidusjar 2022-10-07 20:02:33 +01:00
commit 94da025d28
10 changed files with 121 additions and 189 deletions

View file

@ -14,12 +14,12 @@ namespace Ombi.Api.Discord
Api = api;
}
private const string BaseUrl = "https://discordapp.com/api/";
private const string _baseUrl = "https://discordapp.com/api/";
private IApi Api { get; }
public async Task SendMessage(DiscordWebhookBody body, string webhookId, string webhookToken)
{
var request = new Request($"webhooks/{webhookId}/{webhookToken}", BaseUrl, HttpMethod.Post);
var request = new Request($"webhooks/{webhookId}/{webhookToken}", _baseUrl, HttpMethod.Post);
request.AddJsonBody(body);

View file

@ -67,11 +67,9 @@ namespace Ombi.Schedule.Jobs.Sonarr
var strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await _ctx.Database.BeginTransactionAsync())
{
await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrCache");
tran.Commit();
}
using var tran = await _ctx.Database.BeginTransactionAsync();
await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrCache");
tran.Commit();
});
var sonarrCacheToSave = new HashSet<SonarrCache>();
@ -97,11 +95,9 @@ namespace Ombi.Schedule.Jobs.Sonarr
strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await _ctx.Database.BeginTransactionAsync())
{
await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrEpisodeCache");
tran.Commit();
}
using var tran = await _ctx.Database.BeginTransactionAsync();
await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM SonarrEpisodeCache");
tran.Commit();
});
foreach (var s in ids)
@ -111,7 +107,7 @@ namespace Ombi.Schedule.Jobs.Sonarr
continue;
}
_log.LogDebug("Syncing series: {0}", s.Title);
_log.LogDebug($"Syncing series: {s.Title}");
var episodes = await _api.GetEpisodes(s.Id, settings.ApiKey, settings.FullUri);
var monitoredEpisodes = episodes.Where(x => x.monitored || x.hasFile);
@ -156,13 +152,11 @@ namespace Ombi.Schedule.Jobs.Sonarr
strat = _ctx.Database.CreateExecutionStrategy();
await strat.ExecuteAsync(async () =>
{
using (var tran = await _ctx.Database.BeginTransactionAsync())
{
await _ctx.SonarrEpisodeCache.AddRangeAsync(episodesToAdd);
_log.LogDebug("Commiting the transaction");
await _ctx.SaveChangesAsync();
tran.Commit();
}
using var tran = await _ctx.Database.BeginTransactionAsync();
await _ctx.SonarrEpisodeCache.AddRangeAsync(episodesToAdd);
_log.LogDebug("Commiting the transaction");
await _ctx.SaveChangesAsync();
tran.Commit();
});
}

View file

@ -0,0 +1,6 @@
export enum PlexSyncType {
Full = 0,
RecentlyAdded = 1,
ClearAndReSync = 2,
WatchlistImport = 3,
}

View file

@ -0,0 +1 @@
export * from './PlexSyncType';

View file

@ -0,0 +1,37 @@
// also exported from '@storybook/angular' if you can deal with breaking changes in 6.1
import { APP_BASE_HREF, CommonModule } from '@angular/common';
import { Story, Meta, moduleMetadata } from '@storybook/angular';
import { SharedModule } from '../../../../shared/shared.module';
import { PlexFormComponent } from './plex-form.component';
// More on default export: https://storybook.js.org/docs/angular/writing-stories/introduction#default-export
export default {
title: 'Plex Form Component',
component: PlexFormComponent,
decorators: [
moduleMetadata({
providers: [
{
provide: APP_BASE_HREF,
useValue: ""
},
],
imports: [
CommonModule,
SharedModule
]
})
]
} as Meta;
// More on component templates: https://storybook.js.org/docs/angular/writing-stories/introduction#using-args
const Template: Story<PlexFormComponent> = (args: PlexFormComponent) => ({
props: args,
});
export const Default = Template.bind({});
Default.args = {
};

View file

@ -0,0 +1,25 @@
import { Component, EventEmitter, Input, Output } from "@angular/core";
import { IPlexServer, IPlexServerResponse, IPlexServerViewModel } from "app/interfaces";
import { PlexSyncType } from "../models";
@Component({
templateUrl: "./plex-form.component.html",
styleUrls: ["./plex-form.component.scss"],
selector: "settings-plex-form"
})
export class PlexFormComponent {
@Input() public server: IPlexServer;
@Input() public advancedEnabled: boolean = false;
@Input() public loadedServers: IPlexServerViewModel;
@Output() public loadLibraries = new EventEmitter();
@Output() public loadServers = new EventEmitter();
@Output() public selectServer = new EventEmitter<IPlexServerResponse>();
@Output() public test = new EventEmitter();
@Output() public runSync = new EventEmitter<PlexSyncType>();
public username: string;
public password: string;
public PlexSyncType = PlexSyncType;
}

View file

@ -26,182 +26,31 @@
</div>
</div>
<hr>
<div class="row">
<mat-tab-group #tabGroup [selectedIndex]="selected.value" (selectedTabChange)="addTab($event)"
(selectedIndexChange)="selected.setValue($event)" animationDuration="0ms" style="width:100%;">
<mat-tab *ngFor="let server of settings.servers" [label]="server.name">
<div class="col-md-6 col-6 col-sm-6 align-right">
<button type="button" (click)="removeServer(server)"
class="mat-focus-indicator mat-flat-button mat-button-base mat-warn">Remove Server</button>
</div>
<br />
<br />
<div class="col-md-7 col-8 col-sm-12">
<!-- Main Content -->
<label for="username" class="control-label">
<h3>Plex Server Configuration</h3>
</label>
<div class="md-form-field">
<mat-form-field appearance="outline" floatLabel=auto>
<mat-label>Server Name</mat-label>
<input matInput id="name" name="name"
[(ngModel)]="server.name" value="{{server.name}}">
</mat-form-field>
</div>
<div class="md-form-field">
<mat-form-field appearance="outline" floatLabel=auto>
<mat-label>Hostname or IP</mat-label>
<input matInput id="Ip" name="Ip" [(ngModel)]="server.ip"
value="{{server.ip}}">
</mat-form-field>
<settings-plex-form
[server]="server"
(loadLibraries)="loadLibraries(server)"
(loadServers)="requestServers()"
(test)="testPlex(server)"
(runSync)="runSync($event)"
(selectServer)="selectServer($event, server)"
>
</settings-plex-form>
<mat-form-field appearance="outline" floatLabel=auto>
<mat-label>Port</mat-label>
<input matInput id="portNumber" name="Port"
[(ngModel)]="server.port" value="{{server.port}}">
</mat-form-field>
<mat-slide-toggle id="ssl" [(ngModel)]="server.ssl" [checked]="server.ssl">
SSL
</mat-slide-toggle>
</div>
<div class="md-form-field">
<mat-form-field appearance="outline" floatLabel=auto>
<mat-label>Plex Authorization Token</mat-label>
<input matInput id="authToken"
[(ngModel)]="server.plexAuthToken" value="{{server.plexAuthToken}}">
</mat-form-field>
<mat-form-field appearance="outline" floatLabel=auto>
<mat-label>Machine Identifier</mat-label>
<input matInput id="MachineIdentifier" name="MachineIdentifier"
[(ngModel)]="server.machineIdentifier" value="{{server.machineIdentifier}}">
</mat-form-field>
</div>
<div class="md-form-field">
<mat-form-field appearance="outline" floatLabel=auto>
<mat-label>Externally Facing Hostname</mat-label>
<input matInput placeholder="e.g. https://app.plex.tv" [(ngModel)]="server.serverHostname" value="{{server.serverHostname}}" matTooltip="This will be the external address that users will navigate to when they press the 'View On Plex' button">
</mat-form-field>
<small>
<span *ngIf="server.serverHostname">Current URL: "{{server.serverHostname}}/web/app#!/server/{{server.machineIdentifier}}/details?key=%2flibrary%2Fmetadata%2F53334"</span>
<span *ngIf="!server.serverHostname">Current URL: "https://app.plex.tv/web/app#!/server/{{server.machineIdentifier}}/details?key=%2flibrary%2Fmetadata%2F53334"</span>
</small>
</div>
<div class="md-form-field">
<div class="md-form-field" *ngIf="advanced">
<mat-form-field appearance="outline" floatLabel=auto>
<mat-label for="episodeBatchSize" class="control-label">Episode Batch Size</mat-label>
<input matInput type="number" id="episodeBatchSize" name="episodeBatchSize"
[(ngModel)]="server.episodeBatchSize" value="{{server.episodeBatchSize}}"
matTooltip="This is used when we cache the episodes, we cache in batches of 150 by default, you can configure how many we do at a time here"
matTooltipPosition="right">
</mat-form-field>
</div>
</div>
<div class="md-form-field" *ngIf="loadedServers">
<label for="username" class="control-label">Please select the server</label>
<br />
<div class="btn-group">
<div class="btn-group">
<mat-form-field appearance="outline">
<mat-label>Server</mat-label>
<mat-select>
<mat-option (click)="selectServer(s,server)"
*ngFor="let s of loadedServers.servers.server" [value]="s.server">
{{s.name}}</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>
</div>
<label>Please select the libraries you want Ombi to look in for content</label>
<br />
<small>Note: if nothing is selected, we will monitor all libraries</small>
<div class="md-form-field">
<div>
<button mat-raised-button (click)="loadLibraries(server)"
class="mat-focus-indicator mat-stroked-button mat-button-base">Load Libraries
<i class="fas fa-film"></i>
</button>
</div>
</div>
<br />
<div *ngIf="server.plexSelectedLibraries">
<div *ngFor="let lib of server.plexSelectedLibraries">
<div class="md-form-field">
<div class="checkbox">
<mat-slide-toggle [(ngModel)]="lib.enabled" [checked]="lib.enabled"
for="{{lib.title}}">{{lib.title}}</mat-slide-toggle>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-5 col-4 col-sm-12">
<div class="md-form-field">
<label for="username" class="control-label">
<h3>Plex Credentials</h3>
<small>These fields are optional to automatically fill in your Plex server settings</small>
</label>
<div>
<mat-form-field appearance="outline" floatLabel=auto>
<mat-label>Username</mat-label>
<input matInput id="username" [(ngModel)]="username"
value="{{username}}">
</mat-form-field>
</div>
<div>
<mat-form-field appearance="outline" floatLabel=auto>
<mat-label>Password</mat-label>
<input matInput type="password" id="password"
[(ngModel)]="password" value="{{password}}">
</mat-form-field>
</div>
</div>
<div class="md-form-field">
<div>
<button mat-raised-button id="requestToken" (click)="requestServers(server)"
class="mat-stroked-button">Load Servers
<i class="fas fa-key"></i>
</button>
</div>
</div>
<br />
<div class="form-group">
<div class="form-group">
<button mat-raised-button id="testPlex" type="button" (click)="testPlex(server)"
class="mat-focus-indicator mat-stroked-button mat-button-base">
Test Connectivity
<div id="spinner"></div>
</button>
</div>
<div class="form-group">
<button mat-raised-button (click)="runCacher()" type="button" id="fullSync"
class="mat-focus-indicator mat-stroked-button mat-button-base">Manually Run Full
Sync</button><br />
</div>
<div class="form-group">
<button mat-raised-button (click)="runRecentlyAddedCacher()" type="button" id="recentlyAddedSync"
class="mat-focus-indicator mat-stroked-button mat-button-base">Manually Run Recently
Added Sync</button>
</div>
<div class="form-group">
<button mat-raised-button (click)="clearDataAndResync()" type="button" id="clearData"
class="mat-focus-indicator mat-stroked-button mat-button-base">
Clear Data And Resync
</button>
</div>
<div class="form-group">
<button mat-raised-button (click)="runWatchlistImport()" type="button" id="watchlistImport"
class="mat-focus-indicator mat-stroked-button mat-button-base">
Run Watchlist Import
</button>
</div>
</div>
</div>
</mat-tab>
<mat-tab label="" disabled=true> </mat-tab>
<mat-tab label="Add Server" position=100> </mat-tab>

View file

@ -8,6 +8,7 @@ import { MatTabChangeEvent, MatTabGroup } from "@angular/material/tabs";
import {UntypedFormControl} from '@angular/forms';
import { MatDialog } from "@angular/material/dialog";
import { PlexWatchlistComponent } from "./components/watchlist/plex-watchlist.component";
import { PlexSyncType } from "./components/models";
@Component({
templateUrl: "./plex.component.html",
@ -40,7 +41,7 @@ export class PlexComponent implements OnInit, OnDestroy {
});
}
public requestServers(server: IPlexServer) {
public requestServers() {
this.plexService.getServers(this.username, this.password).pipe(
takeUntil(this.subscriptions),
).subscribe(x => {
@ -151,7 +152,24 @@ export class PlexComponent implements OnInit, OnDestroy {
});
}
public runCacher(): void {
public runSync(type: PlexSyncType) {
switch (type) {
case PlexSyncType.Full:
this.runCacher();
return;
case PlexSyncType.RecentlyAdded:
this.runRecentlyAddedCacher();
return;
case PlexSyncType.ClearAndReSync:
this.clearDataAndResync();
return;
case PlexSyncType.WatchlistImport:
this.runWatchlistImport();
return;
}
}
private runCacher(): void {
this.jobService.runPlexCacher().subscribe(x => {
if (x) {
this.notificationService.success("Triggered the Plex Full Sync");
@ -159,7 +177,7 @@ export class PlexComponent implements OnInit, OnDestroy {
});
}
public runRecentlyAddedCacher(): void {
private runRecentlyAddedCacher(): void {
this.jobService.runPlexRecentlyAddedCacher().subscribe(x => {
if (x) {
this.notificationService.success("Triggered the Plex Recently Added Sync");
@ -167,7 +185,7 @@ export class PlexComponent implements OnInit, OnDestroy {
});
}
public clearDataAndResync(): void {
private clearDataAndResync(): void {
this.jobService.clearMediaserverData().subscribe(x => {
if (x) {
this.notificationService.success("Triggered the Clear MediaServer Resync");
@ -175,7 +193,7 @@ export class PlexComponent implements OnInit, OnDestroy {
});
}
public runWatchlistImport(): void {
private runWatchlistImport(): void {
this.jobService.runPlexWatchlistImport().subscribe(x => {
if (x) {
this.notificationService.success("Triggered the Watchlist Import");

View file

@ -84,6 +84,7 @@ import { WebhookComponent } from "./notifications/webhook.component";
import { WhatsAppComponent } from "./notifications/twilio/whatsapp.component";
import { WikiComponent } from "./wiki.component";
import { PlexWatchlistComponent } from "./plex/components/watchlist/plex-watchlist.component";
import { PlexFormComponent } from "./plex/components/plex-form/plex-form.component";
const routes: Routes = [
{ path: "Ombi", component: OmbiComponent, canActivate: [AuthGuard] },
@ -191,6 +192,7 @@ const routes: Routes = [
CloudMobileComponent,
UpdateDialogComponent,
PlexWatchlistComponent,
PlexFormComponent,
],
exports: [
RouterModule,