Replaces the deploy.py approach (which sed-patched index.html inside the
container, and was therefore lost on every jellyfin/jellyfin upgrade) with a
proper plugin installable from a Jellyfin plugin repository.
The web bundle is unchanged: the same src/*.js -> dist/jfvr.js is now embedded
in Jellyfin.Plugin.JFVR.dll and served from /JFVR/jfvr.js with a content-hash
cache key. index.html is rewritten at request time by an IStartupFilter
middleware, so nothing on disk is touched.
Verified before this commit:
- dotnet build: 0 warnings, 0 errors (net10.0, Jellyfin.Controller 12.1.0)
- the DLL embeds dist/jfvr.js byte for byte
- 19/19 checks on the rewrite logic (injection, idempotency, legacy-tag
takeover, no </body> safety, other scripts preserved, URL override)
- manifest.json passes Jellyfin's PackageInfo/VersionInfo expectations
- the packaged zip's MD5 matches the checksum the manifest advertises
Details that were checked against the Jellyfin source rather than assumed:
- a catalog version survives when targetAbi <= serverVersion, so a single
targetAbi 12.0.0.0 package covers all of 12.x (server is 12.1.0)
- Jellyfin writes meta.json itself at install time, so the zip needs only
the DLL
- Jellyfin verifies the MD5 at install time
Also adds pack.py (build -> package -> manifest -> Gitea release) and documents
the plugin route in README/HANDOFF, keeping deploy.py as a fallback.
56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Security.Cryptography;
|
|
|
|
namespace Jellyfin.Plugin.JFVR.Services;
|
|
|
|
/// <summary>
|
|
/// Loads the JFVR web bundle that is embedded in this assembly and exposes it
|
|
/// together with a short content hash.
|
|
///
|
|
/// The hash is the cache-busting token in the injected
|
|
/// <c><script src="../JFVR/jfvr.js?v=HASH"></c> tag, so a new plugin build
|
|
/// always forces browsers to refetch the bundle. It is also the same
|
|
/// <c>md5[:6]</c> version string the in-page HUD reports, which makes "which JS
|
|
/// is the Quest actually running?" answerable from both sides.
|
|
/// </summary>
|
|
public sealed class BundleProvider
|
|
{
|
|
/// <summary>
|
|
/// Logical name of the embedded resource, set explicitly in the .csproj so it
|
|
/// does not depend on the project's folder layout.
|
|
/// </summary>
|
|
internal const string ResourceName = "Jellyfin.Plugin.JFVR.Web.jfvr.js";
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="BundleProvider"/> class.
|
|
/// </summary>
|
|
/// <exception cref="InvalidOperationException">
|
|
/// Thrown when the bundle was not embedded, which means the build is broken.
|
|
/// </exception>
|
|
public BundleProvider()
|
|
{
|
|
using var stream = typeof(BundleProvider).Assembly.GetManifestResourceStream(ResourceName);
|
|
if (stream is null)
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"Embedded resource '{ResourceName}' is missing from {typeof(BundleProvider).Assembly.FullName}.");
|
|
}
|
|
|
|
using var buffer = new MemoryStream();
|
|
stream.CopyTo(buffer);
|
|
Bytes = buffer.ToArray();
|
|
Hash = Convert.ToHexString(MD5.HashData(Bytes)).ToLowerInvariant()[..8];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the raw bundle bytes.
|
|
/// </summary>
|
|
public byte[] Bytes { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the short (8 hex chars) MD5 of <see cref="Bytes"/>.
|
|
/// </summary>
|
|
public string Hash { get; }
|
|
}
|