fix update level migration
This commit is contained in:
parent
2b61894e3c
commit
86bc77fd6a
|
@ -78,6 +78,69 @@ namespace MediaBrowser.Common.Implementations.Updates
|
|||
};
|
||||
}
|
||||
|
||||
private bool MatchesUpdateLevel(RootObject i, PackageVersionClass updateLevel)
|
||||
{
|
||||
if (updateLevel == PackageVersionClass.Beta)
|
||||
{
|
||||
return !i.prerelease || i.name.EndsWith("-beta", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
if (updateLevel == PackageVersionClass.Dev)
|
||||
{
|
||||
return !i.prerelease || i.name.EndsWith("-beta", StringComparison.OrdinalIgnoreCase) ||
|
||||
i.name.EndsWith("-dev", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
// Technically all we need to do is check that it's not pre-release
|
||||
// But let's addititional checks for -beta and -dev to handle builds that might be temporarily tagged incorrectly.
|
||||
return !i.prerelease && !i.name.EndsWith("-beta", StringComparison.OrdinalIgnoreCase) &&
|
||||
!i.name.EndsWith("-dev", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public async Task<List<RootObject>> GetLatestReleases(string organzation, string repository, string assetFilename, CancellationToken cancellationToken)
|
||||
{
|
||||
var list = new List<RootObject>();
|
||||
|
||||
var url = string.Format("https://api.github.com/repos/{0}/{1}/releases", organzation, repository);
|
||||
|
||||
var options = new HttpRequestOptions
|
||||
{
|
||||
Url = url,
|
||||
EnableKeepAlive = false,
|
||||
CancellationToken = cancellationToken,
|
||||
UserAgent = "Emby/3.0"
|
||||
};
|
||||
|
||||
if (_cacheLength.Ticks > 0)
|
||||
{
|
||||
options.CacheMode = CacheMode.Unconditional;
|
||||
options.CacheLength = _cacheLength;
|
||||
}
|
||||
|
||||
using (var stream = await _httpClient.Get(options).ConfigureAwait(false))
|
||||
{
|
||||
var obj = _jsonSerializer.DeserializeFromStream<RootObject[]>(stream);
|
||||
|
||||
obj = obj.Where(i => (i.assets ?? new List<Asset>()).Any(a => IsAsset(a, assetFilename))).ToArray();
|
||||
|
||||
list.AddRange(obj.Where(i => MatchesUpdateLevel(i, PackageVersionClass.Release)).OrderByDescending(GetVersion).Take(1));
|
||||
list.AddRange(obj.Where(i => MatchesUpdateLevel(i, PackageVersionClass.Beta)).OrderByDescending(GetVersion).Take(1));
|
||||
list.AddRange(obj.Where(i => MatchesUpdateLevel(i, PackageVersionClass.Dev)).OrderByDescending(GetVersion).Take(1));
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public Version GetVersion(RootObject obj)
|
||||
{
|
||||
Version version;
|
||||
if (!Version.TryParse(obj.tag_name, out version))
|
||||
{
|
||||
return new Version(1, 0);
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
private CheckForUpdateResult CheckForUpdateResult(RootObject obj, Version minVersion, string assetFilename, string packageName, string targetFilename)
|
||||
{
|
||||
Version version;
|
||||
|
|
|
@ -41,16 +41,7 @@ namespace MediaBrowser.Server.Startup.Common.Migrations
|
|||
{
|
||||
var updateLevel = _config.Configuration.SystemUpdateLevel;
|
||||
|
||||
// Go down a level
|
||||
if (updateLevel == PackageVersionClass.Release)
|
||||
{
|
||||
updateLevel = PackageVersionClass.Beta;
|
||||
}
|
||||
else if (updateLevel == PackageVersionClass.Beta)
|
||||
{
|
||||
updateLevel = PackageVersionClass.Dev;
|
||||
}
|
||||
else if (updateLevel == PackageVersionClass.Dev)
|
||||
if (updateLevel == PackageVersionClass.Dev)
|
||||
{
|
||||
// It's already dev, there's nothing to check
|
||||
return;
|
||||
|
@ -66,32 +57,42 @@ namespace MediaBrowser.Server.Startup.Common.Migrations
|
|||
|
||||
private async Task CheckVersion(Version currentVersion, PackageVersionClass updateLevel, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await new GithubUpdater(_httpClient, _jsonSerializer, TimeSpan.FromMinutes(5))
|
||||
.CheckForUpdateResult("MediaBrowser", "Emby", currentVersion, PackageVersionClass.Beta, _releaseAssetFilename, "MBServer", "Mbserver.zip",
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
var releases = await new GithubUpdater(_httpClient, _jsonSerializer, TimeSpan.FromMinutes(5))
|
||||
.GetLatestReleases("MediaBrowser", "Emby", _releaseAssetFilename, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result != null && result.IsUpdateAvailable)
|
||||
var newUpdateLevel = updateLevel;
|
||||
|
||||
if (releases.Count >= 2)
|
||||
{
|
||||
_config.Configuration.SystemUpdateLevel = updateLevel;
|
||||
var beta = releases[1];
|
||||
Version version;
|
||||
if (Version.TryParse(beta.tag_name, out version))
|
||||
{
|
||||
if (currentVersion >= version)
|
||||
{
|
||||
newUpdateLevel = PackageVersionClass.Beta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (releases.Count >= 3)
|
||||
{
|
||||
var dev = releases[2];
|
||||
Version version;
|
||||
if (Version.TryParse(dev.tag_name, out version))
|
||||
{
|
||||
if (currentVersion >= version)
|
||||
{
|
||||
newUpdateLevel = PackageVersionClass.Dev;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newUpdateLevel != updateLevel)
|
||||
{
|
||||
_config.Configuration.SystemUpdateLevel = newUpdateLevel;
|
||||
_config.SaveConfiguration();
|
||||
return;
|
||||
}
|
||||
|
||||
// Go down a level
|
||||
if (updateLevel == PackageVersionClass.Release)
|
||||
{
|
||||
updateLevel = PackageVersionClass.Beta;
|
||||
}
|
||||
else if (updateLevel == PackageVersionClass.Beta)
|
||||
{
|
||||
updateLevel = PackageVersionClass.Dev;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await CheckVersion(currentVersion, updateLevel, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user