mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.4 KiB
40 lines
1.4 KiB
using System.IO.Compression; |
|
using ErsatzTV.Core; |
|
using ErsatzTV.Core.Interfaces.Metadata; |
|
|
|
namespace ErsatzTV.Application.Troubleshooting; |
|
|
|
public class ArchiveTroubleshootingResultsHandler(ILocalFileSystem localFileSystem) |
|
: IRequestHandler<ArchiveTroubleshootingResults, Option<string>> |
|
{ |
|
public Task<Option<string>> Handle(ArchiveTroubleshootingResults request, CancellationToken cancellationToken) |
|
{ |
|
string tempFile = Path.GetTempFileName(); |
|
using ZipArchive zipArchive = ZipFile.Open(tempFile, ZipArchiveMode.Update); |
|
|
|
var hasReport = false; |
|
foreach (string file in localFileSystem.ListFiles(FileSystemLayout.TranscodeTroubleshootingFolder)) |
|
{ |
|
string fileName = Path.GetFileName(file); |
|
|
|
// add to archive |
|
if (fileName.StartsWith("ffmpeg-", StringComparison.OrdinalIgnoreCase)) |
|
{ |
|
hasReport = true; |
|
zipArchive.CreateEntryFromFile(file, fileName); |
|
} |
|
|
|
if (Path.GetExtension(file).Equals(".json", StringComparison.OrdinalIgnoreCase)) |
|
{ |
|
zipArchive.CreateEntryFromFile(file, fileName); |
|
} |
|
|
|
if (fileName.Contains("capabilities", StringComparison.OrdinalIgnoreCase)) |
|
{ |
|
zipArchive.CreateEntryFromFile(file, fileName); |
|
} |
|
} |
|
|
|
return Task.FromResult(hasReport ? tempFile : Option<string>.None); |
|
} |
|
}
|
|
|