This repository has been archived by the owner on Apr 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Text; | ||
using Microsoft.Extensions.Options; | ||
using Wasari.App; | ||
using Wasari.Daemon.Models; | ||
using Wasari.Daemon.Options; | ||
using Wasari.FFmpeg; | ||
|
||
namespace Wasari.Daemon.Handlers; | ||
|
||
public class CheckVideoIntegrityHandler | ||
{ | ||
public async ValueTask Handle(CheckVideoIntegrityRequest request, IOptions<DaemonOptions> daemonOptions, IServiceProvider serviceProvider, FFmpegService fFmpegService, ILogger<CheckVideoIntegrityHandler> logger) | ||
{ | ||
var fileIsValid = await fFmpegService.CheckIfVideoStreamIsValid(request.Path); | ||
logger.LogInformation("File {Path} is {Status}", request.Path, fileIsValid ? "valid" : "invalid"); | ||
|
||
if(fileIsValid) return; | ||
|
||
if (request.DeleteFileIfInvalid) | ||
{ | ||
File.Delete(request.Path); | ||
logger.LogInformation("File {Path} was deleted", request.Path); | ||
} | ||
|
||
if (daemonOptions.Value.NotificationEnabled && serviceProvider.GetService<NotificationService>() is { } notificationService) | ||
{ | ||
var fileName = Path.GetFileName(request.Path); | ||
var sb = new StringBuilder($"File {fileName} was corrupted"); | ||
if(request.DeleteFileIfInvalid) sb.Append(" and was deleted"); | ||
await notificationService.SendNotificationAsync(sb.ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Wasari.Daemon.Models; | ||
|
||
public record CheckVideoIntegrityRequest(string Path, bool DeleteFileIfInvalid); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Wasari.Daemon/Validators/CheckVideoIntegrityRequestValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using FluentValidation; | ||
using Wasari.Daemon.Models; | ||
|
||
// ReSharper disable UnusedType.Global | ||
|
||
namespace Wasari.Daemon.Validators; | ||
|
||
public class CheckVideoIntegrityRequestValidator : AbstractValidator<CheckVideoIntegrityRequest> | ||
{ | ||
public CheckVideoIntegrityRequestValidator() | ||
{ | ||
RuleFor(i => i.Path) | ||
.NotEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters