mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-02 14:31:35 -05:00
Every installed copy checked GitHub Releases on its own, so a shop's
workstations shared GitHub's 60-requests-per-hour unauthenticated limit
per public address and each downloaded the ~90 MB package over the
internet. Shops large enough to hit that already run the nest server.
The server now mirrors the Velopack feed at /updates/{stable|dev}: one
GitHub API request per 30-minute refresh, each package downloaded once
and checked against the feed's size and SHA-256 before it is served. A
channel is mirrored only while clients ask for it, so stable-only shops
never download development builds. Database-mode clients read the
server first and fall back to GitHub when it has no feed (old server,
mirror off, not mirrored yet), downloading each package from whichever
source listed it. A hand-set feed URL still takes precedence.
OPENNEST_UPDATES=off turns the mirror off.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.5 KiB
C#
62 lines
2.5 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Velopack;
|
|
using Velopack.Logging;
|
|
using Velopack.Sources;
|
|
|
|
namespace OpenNest
|
|
{
|
|
/// <summary>
|
|
/// Reads the update feed the nest server mirrors, falling back to another source (GitHub)
|
|
/// when the server cannot serve one: unreachable, a version without the mirror (404), or a
|
|
/// channel it has not mirrored yet (503). Each package downloads from the source whose feed
|
|
/// listed it, so a fallback feed's package never goes to the server.
|
|
/// </summary>
|
|
internal sealed class ServerFirstUpdateSource : IUpdateSource
|
|
{
|
|
private readonly IUpdateSource _server;
|
|
private readonly IUpdateSource _fallback;
|
|
private readonly ConditionalWeakTable<VelopackAsset, IUpdateSource> _origins = new();
|
|
|
|
public ServerFirstUpdateSource(IUpdateSource server, IUpdateSource fallback)
|
|
{
|
|
_server = server;
|
|
_fallback = fallback;
|
|
}
|
|
|
|
/// <summary>The source that answered the last feed request.</summary>
|
|
public IUpdateSource LastFeedSource { get; private set; }
|
|
|
|
public async Task<VelopackAssetFeed> GetReleaseFeed(IVelopackLogger logger, string appId, string channel,
|
|
Guid? stagingId = null, VelopackAsset latestLocalRelease = null)
|
|
{
|
|
VelopackAssetFeed feed;
|
|
IUpdateSource source = _server;
|
|
try
|
|
{
|
|
feed = await _server.GetReleaseFeed(logger, appId, channel, stagingId, latestLocalRelease);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger?.Warn($"Nest server update feed unavailable ({ex.Message}); checking GitHub instead.");
|
|
source = _fallback;
|
|
feed = await _fallback.GetReleaseFeed(logger, appId, channel, stagingId, latestLocalRelease);
|
|
}
|
|
|
|
foreach (var asset in feed?.Assets ?? Array.Empty<VelopackAsset>())
|
|
_origins.AddOrUpdate(asset, source);
|
|
LastFeedSource = source;
|
|
return feed;
|
|
}
|
|
|
|
public Task DownloadReleaseEntry(IVelopackLogger logger, VelopackAsset releaseEntry, string localFile,
|
|
Action<int> progress, CancellationToken cancelToken = default)
|
|
{
|
|
var source = _origins.TryGetValue(releaseEntry, out var origin) ? origin : LastFeedSource ?? _server;
|
|
return source.DownloadReleaseEntry(logger, releaseEntry, localFile, progress, cancelToken);
|
|
}
|
|
}
|
|
}
|