Expand integration coverage and fix settings UI

This commit is contained in:
ajp_anton committed 2026-07-21 00:42:44 +00:00
1 parent 25088ce91d
commit 094d5ad9f0
26 files changed
+1665 -66

No files matched your search

@@ -294,9 +294,7 @@ public sealed class MultilangController : ControllerBase
var cacheTtl = TimeSpan.FromMinutes(Math.Max(1, cfg.ItemsProxyCacheTtlMinutes));
if (!precache && cacheAllowed)
{
var baseUri = new Uri($"{Request.Scheme}://{Request.Host}{Request.PathBase}/");
_itemsProxyPrecacheService.ObserveUserActivity(
baseUri,
userId,
token,
proxyRequest.Controls.ClientLocale,
@@ -259,7 +259,7 @@
function renderJellyfinTitleLanguages() {
var select = document.getElementById("ml-jellyfin-title-language");
var selected = state.config.JellyfinTitleLanguageFallback || state.config.jellyfinTitleLanguageFallback || "";
var selected = M.prop(state.config, "JellyfinTitleLanguageFallback", "jellyfinTitleLanguageFallback", "");
select.replaceChildren();
var defaultOption = make("option", "", "Jellyfin's default");
defaultOption.value = "";
@@ -268,9 +268,9 @@
separator.disabled = true;
select.appendChild(separator);
state.metadataLanguages.forEach(function (language) {
var name = String(language.Name || language.name || "");
var name = String(M.prop(language, "Name", "name", ""));
if (!name) return;
var option = make("option", "", String(language.DisplayName || language.displayName || name) + " (" + name + ")");
var option = make("option", "", String(M.prop(language, "DisplayName", "displayName", name)) + " (" + name + ")");
option.value = name;
select.appendChild(option);
});
@@ -539,13 +539,13 @@
}
entries.forEach(function (entry) {
var url = entry.Url || entry.url || "";
var url = M.prop(entry, "Url", "url", "");
root.appendChild(makeDiagnosticRow(url, [
"cached",
(entry.ItemCount || entry.itemCount || 0) + " items",
(entry.DurationMs || entry.durationMs || 0) + " ms",
((entry.SizeBytes || entry.sizeBytes || 0) / 1024).toFixed(1) + " KiB",
makeAgeChip(entry.AgeSeconds || entry.ageSeconds || 0)
M.prop(entry, "ItemCount", "itemCount", 0) + " items",
M.prop(entry, "DurationMs", "durationMs", 0) + " ms",
(M.prop(entry, "SizeBytes", "sizeBytes", 0) / 1024).toFixed(1) + " KiB",
makeAgeChip(M.prop(entry, "AgeSeconds", "ageSeconds", 0))
]));
});
}
@@ -574,21 +574,21 @@
}
entries.forEach(function (entry) {
var url = entry.Url || entry.url || "";
var cacheState = (entry.CacheHit || entry.cacheHit)
var url = M.prop(entry, "Url", "url", "");
var cacheState = M.prop(entry, "CacheHit", "cacheHit", false)
? "cache hit"
: ((entry.InFlightCoalesced || entry.inFlightCoalesced)
: (M.prop(entry, "InFlightCoalesced", "inFlightCoalesced", false)
? "in-flight hit"
: ((entry.CacheStored || entry.cacheStored) ? "cache miss: cached" : "cache miss"));
: (M.prop(entry, "CacheStored", "cacheStored", false) ? "cache miss: cached" : "cache miss"));
root.appendChild(makeDiagnosticRow(url, [
cacheState,
"HTTP " + (entry.StatusCode || entry.statusCode || 0),
(entry.ItemCount || entry.itemCount || 0) + " items",
"total " + (entry.TotalMs || entry.totalMs || 0) + " ms",
"upstream " + (entry.UpstreamMs || entry.upstreamMs || 0) + " ms",
"transform " + (entry.TransformMs || entry.transformMs || 0) + " ms",
((entry.SizeBytes || entry.sizeBytes || 0) / 1024).toFixed(1) + " KiB",
makeAgeChip(entry.AgeSeconds || entry.ageSeconds || 0)
"HTTP " + M.prop(entry, "StatusCode", "statusCode", 0),
M.prop(entry, "ItemCount", "itemCount", 0) + " items",
"total " + M.prop(entry, "TotalMs", "totalMs", 0) + " ms",
"upstream " + M.prop(entry, "UpstreamMs", "upstreamMs", 0) + " ms",
"transform " + M.prop(entry, "TransformMs", "transformMs", 0) + " ms",
(M.prop(entry, "SizeBytes", "sizeBytes", 0) / 1024).toFixed(1) + " KiB",
makeAgeChip(M.prop(entry, "AgeSeconds", "ageSeconds", 0))
]));
});
}
@@ -1260,7 +1260,10 @@
}
});
$("ml-reset-user").addEventListener("click", load);
$("ml-sort-locale").addEventListener("change", renderSortLocaleAutoText);
$("ml-sort-locale").addEventListener("change", function () {
state.rules.SortLocale = $("ml-sort-locale").value || "Auto";
renderSortLocaleAutoText();
});
$("ml-user-export").addEventListener("click", function () {
downloadUserExport().catch(function (err) { M.setStatus(status, String(err), true); });
});
@@ -163,13 +163,13 @@ DELETE FROM assets WHERE item_id = $item_id;";
public bool TryNormalizeLocalAssetPath(string path, out string fullPath)
{
fullPath = string.Empty;
if (string.IsNullOrWhiteSpace(path) || Uri.TryCreate(path, UriKind.Absolute, out _))
if (string.IsNullOrWhiteSpace(path))
return false;
var relative = path;
if (relative.StartsWith(LocalAssetUrlPrefix, StringComparison.OrdinalIgnoreCase))
relative = relative[LocalAssetUrlPrefix.Length..];
else if (Path.IsPathRooted(relative))
else if (Uri.TryCreate(relative, UriKind.Absolute, out _) || Path.IsPathRooted(relative))
return false;
var candidate = Path.GetFullPath(Path.Combine(_assetsDir, relative));
@@ -1,4 +1,7 @@
using System.Text.Json.Nodes;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.Multilang.Services;
@@ -6,20 +9,27 @@ namespace Jellyfin.Plugin.Multilang.Services;
public sealed class ItemsProxyPrecacheService
{
private static readonly TimeSpan IdleThreshold = TimeSpan.FromMinutes(30);
private readonly IServerApplicationHost _applicationHost;
private readonly IConfigurationManager _configurationManager;
private readonly IHttpClientFactory _httpClientFactory;
private readonly ILogger<ItemsProxyPrecacheService> _logger;
private readonly object _lock = new();
private readonly Dictionary<string, DateTimeOffset> _lastSeen = new(StringComparer.Ordinal);
private readonly HashSet<string> _pendingUsers = new(StringComparer.Ordinal);
public ItemsProxyPrecacheService(IHttpClientFactory httpClientFactory, ILogger<ItemsProxyPrecacheService> logger)
public ItemsProxyPrecacheService(
IServerApplicationHost applicationHost,
IConfigurationManager configurationManager,
IHttpClientFactory httpClientFactory,
ILogger<ItemsProxyPrecacheService> logger)
{
_applicationHost = applicationHost;
_configurationManager = configurationManager;
_httpClientFactory = httpClientFactory;
_logger = logger;
}
public void ObserveUserActivity(
Uri baseUri,
string userId,
string token,
string clientLocale,
@@ -38,11 +48,10 @@ public sealed class ItemsProxyPrecacheService
return;
}
_ = PrecacheAsync(baseUri, userId, token, clientLocale, precacheMovieLibraries, precacheTvShowLibraries);
_ = PrecacheAsync(userId, token, clientLocale, precacheMovieLibraries, precacheTvShowLibraries);
}
private async Task PrecacheAsync(
Uri baseUri,
string userId,
string token,
string clientLocale,
@@ -51,6 +60,8 @@ public sealed class ItemsProxyPrecacheService
{
try
{
var port = _configurationManager.GetNetworkConfiguration().InternalHttpPort;
var baseUri = new Uri(_applicationHost.GetLocalApiUrl("127.0.0.1", "http", port).TrimEnd('/') + "/");
var views = await GetJsonAsync(new Uri(baseUri, $"Users/{userId}/Views"), token).ConfigureAwait(false);
var items = views["Items"]?.AsArray() ?? [];
var targets = items
@@ -82,26 +82,25 @@ public static class ItemsProxySorting
public static string[] GetSortArticles(
SortArticleCatalog articleCatalog,
IEnumerable<SortArticleEntry> configuredArticles,
IReadOnlyList<SortArticleEntry> configuredArticles,
string? titleLanguage,
bool ignoreArticles = true)
{
if (!ignoreArticles)
return [];
var configured = configuredArticles.ToArray();
var always = configured
var always = configuredArticles
.Where(e => e.AlwaysApply == true)
.SelectMany(e => SplitArticles(e.Articles));
return always
.Concat(GetLanguageArticles(articleCatalog, configured, titleLanguage))
.Concat(GetLanguageArticles(articleCatalog, configuredArticles, titleLanguage))
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToArray();
}
private static string[] GetLanguageArticles(
SortArticleCatalog articleCatalog,
SortArticleEntry[] configured,
IReadOnlyList<SortArticleEntry> configured,
string? titleLanguage)
{
var language = (titleLanguage ?? string.Empty).Trim();
@@ -84,6 +84,7 @@ public sealed class ItemsProxyTransformer
? ApplyRules(items, ids, rules, controls.ClientLocale, factsByItem)
: new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var jellyfinTitleLanguages = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var sortArticlesByLanguage = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
ItemsProxySorting.Apply(root, controls, sortCulture, item =>
{
@@ -91,7 +92,13 @@ public sealed class ItemsProxyTransformer
var language = itemId is not null && titleLanguages.TryGetValue(itemId, out var translatedLanguage)
? translatedLanguage
: ResolveJellyfinTitleLanguage(itemId, config, jellyfinTitleLanguages);
return ItemsProxySorting.GetSortArticles(_articleCatalog, config.ArticleEntries, language, config.IgnoreArticlesWhenSorting);
if (!sortArticlesByLanguage.TryGetValue(language, out var articles))
{
articles = ItemsProxySorting.GetSortArticles(_articleCatalog, config.ArticleEntries, language, config.IgnoreArticlesWhenSorting);
sortArticlesByLanguage[language] = articles;
}
return articles;
});
return new ItemsProxyTransformResult(root.ToJsonString(new JsonSerializerOptions { WriteIndented = false }), ids);
}
@@ -221,6 +221,7 @@
event?.preventDefault?.();
event?.stopPropagation?.();
event?.stopImmediatePropagation?.();
document.querySelector("#app-user-menu .MuiBackdrop-root")?.click();
history.pushState({}, "", userRulesHref());
scheduleUserRulesPageRender();
}