HTTP / HTTPS Vault Provider

NuGet Package : Nodsoft.MoltenObsidian.Vaults.Http

Description

This provider supports serving a MoltenObsidian vault hosted on a remote Web server, through HTTP or HTTPS. By targeting a Vault manifest file (generated by the CLI Tool), you can serve a Molten Obsidian over the wire, which is considered out of bounds of the reference Obsidian implementation.

Applications for this provider vary greatly, as you can now host your Molten Obsidian repository on several platforms :

Relying on the Vault Manifest allows for the vault elements to only be downloaded/streamed on a need basis, instead of prematurely transferring a vault of potentially significant size over the wire. This comes at a cost of immutability, until the manifest is updated.

Example Usage

Declare an HTTP/HTTPS vault in Dependency Injection:

using Microsoft.Extensions.DependencyInjection; 

public void ConfigureServices(IServiceCollection services) 
{
	// Declare a HTTP vault from Web root path.
	// This will internally declare and use its own HttpClient. You'll usually avoid this in production-grade scenarions.
	services.AddMoltenObsidianHttpVault(new DirectoryInfo("https://path.to/vault"));
	
	// Alternatively you can declare from an IServiceProvider delegate, returning a HttpClient.
	// This use case is usually coupled with the use of an IHttpClientFactory to manage the lifetime of the client.
	services.AddHttpClient("MoltenObsidian", client => client.BaseAddress = new("https://path.to/vault"));
	services.AddMoltenObsidianHttpVault(s => s.GetRequiredService<IHttpClientFactory>().CreateClient("MoltenObsidian"));
}

Alternatively you can instantiate your own HTTP/HTTPS vault like so:

using Nodsoft.MoltenObsidian.Vaults.Http;

// Instantiate the HttpClient.
// Please note that the client's lifetime must follow that of the Vault itself, 
// as it will be reused for retrieving the vault's contents on-demand.
HttpClient httpClient = new() { BaseAddress = new("https://path.to/vault") };

// Get the vault manifest from the server.
RemoteVaultManifest manifest = await httpClient.GetFromJsonAsync<RemoteVaultManifest>("moltenobsidian.manifest.json") 
	?? throw new InvalidOperationException("Failed to retrieve the vault manifest from the server.");

// Instantiate the vault.
IVault vault = HttpRemoteVault.FromManifest(manifest, httpClient);

Please note that the example path used in the above examples reflect the HTTP/HTTPS path preceding the Manifest's moltenobsidian.manifest.json. This means the actual manifest link would be https://path.to/vault/moltenobsidian.manifest.json.

Known Limitations (Potential future features?)

If any of those features are considered a necessity in your use case, feel free to voice your need by raising an issue.