Compare commits
4
Commits
v1.0.0.0
...
9e38c98da2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e38c98da2
|
||
|
|
ea28ad29ac
|
||
|
|
dea2569fd7
|
||
|
|
9c89852e97
|
+6
-2
@@ -34,14 +34,18 @@ One line per decision, with the reason.
|
||||
## Client injection
|
||||
|
||||
- Registration with File Transformation is done purely by reflection, including building the payload: the `JObject` is created by calling `Parse` on the parameter type of `RegisterTransformation`, so the plugin has no Newtonsoft reference of its own.
|
||||
- The file pattern is `^index\.html$`. File Transformation treats patterns as regular expressions, and the unanchored `index.html` also matched the script chunk `session-login-index-html.<hash>.chunk.js`, which broke the login page. Found in the container test.
|
||||
- The transformer leaves anything without a `</body>` alone, as a second line of defence against touching non-HTML files.
|
||||
- The file pattern is the literal `index.html`, the same string every other plugin registers. File Transformation groups callbacks by pattern string and, for a request, runs only the group whose key equals the requested path; a regex fallback is used only when no key matches exactly. The earlier anchored `^index\.html$` was therefore never called once MediaBar (or any plugin using `index.html`) was installed. Found by reproducing a server with MediaBar and Jellyfin Enhanced.
|
||||
- As a regular expression `index.html` also matches script chunks such as `session-login-index-html.<hash>.chunk.js`, so those are handed to the callback too. The transformer returns anything that is not an HTML page (`<html` and `</body>` present) unchanged.
|
||||
- The script tag uses the relative URL `../Herald/client.js` so it keeps working behind a base URL.
|
||||
- `GET /Herald/client.js` is anonymous: a `<script>` tag cannot send Jellyfin's auth header, and the file holds nothing secret.
|
||||
- Jellyfin 10.11 has **no "Custom HTML" setting** (branding only offers custom CSS, a login disclaimer and the splash screen; checked against `BrandingOptions`). The documented manual fallbacks are therefore the JavaScript Injector plugin and editing `index.html`.
|
||||
- Login and user switches are detected by comparing `ApiClient.getCurrentUserId()` on a 3 s local timer. That costs no request; the server is only asked after a change of user and then at most every 10 minutes. jellyfin-web's own login events are not reachable from an injected script in a stable way.
|
||||
- The modal reuses jellyfin-web's `dialog`, `raised`, `button-submit` and `emby-button` classes so the active theme colours it; own CSS only handles layout.
|
||||
|
||||
## Admin UI
|
||||
|
||||
- The config page is flagged `EnableInMainMenu`, so it has its own entry in the dashboard sidebar under "Plugins". Jellyfin 10.11 draws a fixed icon there; `MenuIcon` is set for versions that honour it.
|
||||
|
||||
## Watch-time stats
|
||||
|
||||
- Time is measured on the **server clock between two reports** of the same playback, not from playback positions: a seek changes the position by minutes without anyone watching, and position deltas also break with playback speed.
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
<!-- Microsoft.Data.Sqlite version shipped with that Jellyfin release (Directory.Packages.props upstream). -->
|
||||
<JellyfinSqliteVersion>9.0.11</JellyfinSqliteVersion>
|
||||
|
||||
<Version>1.0.0.0</Version>
|
||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||
<FileVersion>1.0.0.0</FileVersion>
|
||||
<Version>1.0.1.0</Version>
|
||||
<AssemblyVersion>1.0.1.0</AssemblyVersion>
|
||||
<FileVersion>1.0.1.0</FileVersion>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@@ -31,6 +31,25 @@ public class IndexHtmlTransformerTests
|
||||
Assert.Equal(Script, IndexHtmlTransformer.Inject(Script));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inject_LeavesScriptsThatMentionABodyTagAlone()
|
||||
{
|
||||
const string Script = "(self.webpackChunk=self.webpackChunk||[]).push([[17244],{t:\"<div></div></body>\"}]);";
|
||||
|
||||
Assert.Equal(Script, IndexHtmlTransformer.Inject(Script));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Inject_KeepsTagsOtherPluginsAdded()
|
||||
{
|
||||
const string Other = "<script defer src=\"../MediaBar/slideshowpure.js\"></script>";
|
||||
var page = Page.Replace("</body>", Other + "</body>", StringComparison.Ordinal);
|
||||
|
||||
var result = IndexHtmlTransformer.Inject(page);
|
||||
|
||||
Assert.Contains(Other + IndexHtmlTransformer.ScriptTag + "</body>", result, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Transform_HandlesAnEmptyPayload()
|
||||
{
|
||||
|
||||
@@ -17,9 +17,11 @@ namespace Jellyfin.Plugin.Herald.Injection;
|
||||
public class FileTransformationRegistrar : IHostedService
|
||||
{
|
||||
private const string InterfaceTypeName = "Jellyfin.Plugin.FileTransformation.PluginInterface";
|
||||
// File Transformation treats this as a regular expression. Unanchored, "index.html" would also
|
||||
// match script chunks such as "session-login-index-html.<hash>.chunk.js".
|
||||
private const string IndexHtmlPattern = @"^index\.html$";
|
||||
// Has to be the literal "index.html" every other plugin registers. File Transformation groups
|
||||
// callbacks by pattern string and, for a request, only runs the group whose key equals the path;
|
||||
// a differently spelled pattern is skipped as soon as another plugin uses the plain one.
|
||||
// The pattern is also used as a regex and matches some script chunks, which the transformer ignores.
|
||||
private const string IndexHtmlPattern = "index.html";
|
||||
private static readonly Guid _transformationId = Guid.Parse("bf6fabc9-721c-46d9-9e13-3cc415a9ae1b");
|
||||
|
||||
private readonly ILogger<FileTransformationRegistrar> _logger;
|
||||
|
||||
@@ -37,7 +37,7 @@ public static class IndexHtmlTransformer
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts the script tag before the closing body tag. Content without one is not a page and is left alone.
|
||||
/// Inserts the script tag before the closing body tag. Anything that is not an HTML page is left alone.
|
||||
/// </summary>
|
||||
/// <param name="html">The page.</param>
|
||||
/// <returns>The page with the script tag.</returns>
|
||||
@@ -50,6 +50,12 @@ public static class IndexHtmlTransformer
|
||||
return html;
|
||||
}
|
||||
|
||||
// File Transformation also hands over script chunks whose name happens to match the pattern.
|
||||
if (!html.Contains("<html", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return html;
|
||||
}
|
||||
|
||||
var index = html.LastIndexOf("</body>", StringComparison.OrdinalIgnoreCase);
|
||||
return index < 0 ? html : html.Insert(index, ScriptTag);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
new PluginPageInfo
|
||||
{
|
||||
Name = Name,
|
||||
DisplayName = Name,
|
||||
EnableInMainMenu = true,
|
||||
MenuIcon = "campaign",
|
||||
EmbeddedResourcePath = string.Format(CultureInfo.InvariantCulture, "{0}.Configuration.configPage.html", GetType().Namespace)
|
||||
}
|
||||
];
|
||||
|
||||
@@ -28,7 +28,7 @@ Watch-time stats are collected on the server and cover all clients.
|
||||
2. Unpack it into `plugins/Herald_<version>/` inside the Jellyfin data directory, for example `/config/plugins/Herald_1.0.0.0/` in the official container. The folder holds `Jellyfin.Plugin.Herald.dll` and `meta.json`.
|
||||
3. Restart Jellyfin. The log shows `Loaded plugin: Herald`.
|
||||
|
||||
The settings page is under **Dashboard → Plugins → Herald**.
|
||||
Herald has its own entry in the dashboard sidebar, in the **Plugins** section. The same page opens from **Dashboard → Plugins → Herald**.
|
||||
|
||||
## Getting the popup into the web client
|
||||
|
||||
@@ -52,6 +52,8 @@ The File Transformation plugin is not installed, so the Herald client script is
|
||||
|
||||
File Transformation releases are tied to exact Jellyfin versions, so pick the build that matches your server.
|
||||
|
||||
To check the result, open `http://<server>/web/index.html` and look for `data-herald-client` in the source. Other plugins that use File Transformation (MediaBar, Home Screen Sections, Jellyfin Enhanced and so on) can be installed alongside.
|
||||
|
||||
### Fallback: JavaScript Injector
|
||||
|
||||
With the [JavaScript Injector](https://github.com/n00bcodr/Jellyfin-JavaScript-Injector) plugin, add a script with this content and enable it:
|
||||
|
||||
+5
-5
@@ -8,14 +8,14 @@
|
||||
- **Client injection**: registered with the File Transformation plugin by reflection at startup; a warning is logged when that plugin is missing. Manual fallbacks are documented.
|
||||
- **Watch-time stats**: playback start/progress/stop events are turned into daily per-user aggregates; `GET /Herald/Stats` and a sortable "Stats" tab show them; a daily scheduled task drops rows older than 90 days.
|
||||
- **Storage**: one SQLite database in Jellyfin's data directory, using the `Microsoft.Data.Sqlite` that the server ships. Versioned migrations, serialized writes.
|
||||
- **Project plumbing**: xUnit test project (56 tests), `build.yaml` for jprm, a Gitea Actions workflow (build, test, package; tags and releases automatically when the version changes), a sample `manifest.json`, `README.md`, `DECISIONS.md`.
|
||||
- **Project plumbing**: xUnit test project (58 tests), `build.yaml` for jprm, a Gitea Actions workflow (build, test, package; tags and releases automatically when the version changes), a sample `manifest.json`, `README.md`, `DECISIONS.md`.
|
||||
|
||||
## What was verified, and how
|
||||
|
||||
| Check | Result |
|
||||
| --- | --- |
|
||||
| `dotnet build -c Release` | Succeeds, 0 warnings, 0 errors (template analyzers kept, warnings as errors). |
|
||||
| `dotnet test -c Release` | 56 passed. Covers watch-time deltas (pause, seek, gaps, stale sessions, midnight incl. a non-UTC zone), pending-notice selection (revision bump, targeting, disabled), ack validation, the SQLite stores incl. concurrent writes and migrations, and the index.html transformer. |
|
||||
| `dotnet test -c Release` | 58 passed. Covers watch-time deltas (pause, seek, gaps, stale sessions, midnight incl. a non-UTC zone), pending-notice selection (revision bump, targeting, disabled), ack validation, the SQLite stores incl. concurrent writes and migrations, and the index.html transformer. |
|
||||
| `jprm plugin build` | Produces `artifacts/herald_1.0.0.0.zip` containing only `Jellyfin.Plugin.Herald.dll` and `meta.json`. `jprm repo add` accepted it and generated a manifest. |
|
||||
| Docker, `jellyfin/jellyfin:10.11.11` + File Transformation 3.0.3.0 (its 10.11.11 build) | The zip from jprm was unpacked into `plugins/Herald_1.0.0.0/`. Log: `Loaded plugin: Herald 1.0.0.0`, `Registered the Herald client script with File Transformation 3.0.3.0`, scheduled task registered, no `[ERR]` lines. `/Plugins` reports both plugins as `Active`. |
|
||||
| Injection | `GET /web/index.html` and `GET /web/` contain the `<script data-herald-client … src="../Herald/client.js">` tag; script chunks are untouched. |
|
||||
@@ -25,14 +25,14 @@
|
||||
| Popup (headless Chromium, logged in as a normal user) | Must-accept notice shows only "Accept", Escape and outside click do nothing; next notice shows "Close" and Escape dismisses it; one `Pending` request after login and none on navigation; HTML and `javascript:` links in a notice are rendered as text. |
|
||||
| Stats end to end | A playback was reported through `/Sessions/Playing*` for a generated test video: 5 s + 5 s playing, 6 s paused, 4 s + 3 s playing with a seek in between. Stored: 17.15 s, 1 play. |
|
||||
|
||||
Two bugs were found and fixed through the container test: the unanchored File Transformation pattern also matched a JavaScript chunk and broke the login page, and jellyfin-web's `document.createElement` shim rejected the element-options form used by the admin page.
|
||||
Two bugs were found and fixed through the container test: the transformer touched a JavaScript chunk that File Transformation also matches against the `index.html` pattern, which broke the login page, and jellyfin-web's `document.createElement` shim rejected the element-options form used by the admin page.
|
||||
|
||||
## Known gaps
|
||||
|
||||
- Notices only appear in clients built on jellyfin-web. Native clients are not covered and cannot be from a plugin.
|
||||
- The popup was tested against the default dark theme in Chromium. Other themes, the TV layout and real mobile wrappers were not tried.
|
||||
- The popup was tested in Chromium against the default dark theme and NeutralFin, at desktop and phone size. The TV layout and real mobile wrappers were not tried.
|
||||
- The JavaScript Injector fallback and the manual `index.html` edit are documented but were not run.
|
||||
- File Transformation was tested in version 3.0.3.0 only. Its registration API is found by reflection, so a rename on their side turns into the logged warning, not a crash.
|
||||
- File Transformation was tested in version 3.0.3.0 only, alone and together with MediaBar 3.0.2.0 and Jellyfin Enhanced 12.15.0.0. Its registration API is found by reflection, so a rename on their side turns into the logged warning, not a crash.
|
||||
- Stats were verified with simulated reports, not with a real player. The systematic inaccuracies are listed in the README.
|
||||
- The UI is English only.
|
||||
- Must-accept is a record of consent, not an access gate: nothing on the server is blocked for users who have not accepted.
|
||||
|
||||
+4
-2
@@ -1,7 +1,7 @@
|
||||
---
|
||||
name: "Herald"
|
||||
guid: "006114bd-2c46-407b-8b31-57199a10fb1c"
|
||||
version: "1.0.0.0"
|
||||
version: "1.0.1.0"
|
||||
# Jellyfin 10.11.x. Built against Jellyfin.Controller / Jellyfin.Model 10.11.11
|
||||
# (see Directory.Build.props). Plugins built for 10.11 do not load on 10.10 or 12.x.
|
||||
targetAbi: "10.11.0.0"
|
||||
@@ -22,4 +22,6 @@ owner: "JoshiCodes"
|
||||
artifacts:
|
||||
- "Jellyfin.Plugin.Herald.dll"
|
||||
changelog: >
|
||||
Initial release: notices with acknowledgement tracking, watch-time stats.
|
||||
Notices now show up when other plugins (MediaBar, Home Screen Sections, ...)
|
||||
also change index.html through File Transformation. Herald has its own entry
|
||||
in the dashboard sidebar.
|
||||
|
||||
Reference in New Issue
Block a user