// Copyright (C) 2024 Intro-Skipper contributors // SPDX-License-Identifier: GPL-3.0-only. using System; using System.Net.Mime; using System.Text; using MediaBrowser.Common; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; namespace ConfusedPolarBear.Plugin.IntroSkipper.Controllers; /// /// Troubleshooting controller. /// [Authorize(Policy = "RequiresElevation")] [ApiController] [Produces(MediaTypeNames.Application.Json)] [Route("IntroSkipper")] public class TroubleshootingController : ControllerBase { private readonly IApplicationHost _applicationHost; private readonly ILogger _logger; /// /// Initializes a new instance of the class. /// /// Application host. /// Logger. public TroubleshootingController( IApplicationHost applicationHost, ILogger logger) { _applicationHost = applicationHost; _logger = logger; } /// /// Gets a Markdown formatted support bundle. /// /// Support bundle created. /// Support bundle. [HttpGet("SupportBundle")] [Produces(MediaTypeNames.Text.Plain)] public ActionResult GetSupportBundle() { var config = Plugin.Instance!.Configuration; var bundle = new StringBuilder(); bundle.Append("* Jellyfin version: "); bundle.Append(_applicationHost.ApplicationVersionString); bundle.Append('\n'); var version = Plugin.Instance!.Version.ToString(3); try { var commit = Plugin.Instance!.GetCommit(); if (!string.IsNullOrWhiteSpace(commit)) { version += string.Concat("+", commit.AsSpan(0, 12)); } } catch (Exception ex) { _logger.LogWarning("Unable to append commit to version: {Exception}", ex); } bundle.Append("* Plugin version: "); bundle.Append(version); bundle.Append('\n'); bundle.Append("* Queue contents: "); bundle.Append(Plugin.Instance!.TotalQueued); bundle.Append(" episodes, "); bundle.Append(Plugin.Instance!.TotalSeasons); bundle.Append(" seasons\n"); bundle.Append("* Warnings: `"); bundle.Append(WarningManager.GetWarnings()); bundle.Append("`\n"); bundle.Append(FFmpegWrapper.GetChromaprintLogs()); return bundle.ToString(); } }