1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-23 12:25:16 +01:00

get rid of version weight

This commit is contained in:
Kyle Spearrin 2017-09-06 23:57:14 -04:00
parent acb6c59e5e
commit 24fe7a9f88
3 changed files with 4 additions and 23 deletions

View File

@ -8,12 +8,9 @@ namespace Bit.Core.Models.Api
public VersionResponseModel()
: base("version")
{
var info = CoreHelpers.GetVersionInfo();
Version = info.version;
VersionWeight = info.versionWeight;
Version = CoreHelpers.GetVersion();
}
public string Version { get; set; }
public int VersionWeight { get; set; }
}
}

View File

@ -375,30 +375,16 @@ namespace Bit.Core.Utilities
return val.ToString();
}
public static (string version, int versionWeight) GetVersionInfo()
public static string GetVersion()
{
if(string.IsNullOrWhiteSpace(_version))
{
_version = Assembly.GetEntryAssembly()
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
.InformationalVersion;
var dashIndex = _version.IndexOf('-');
var trimmedVersion = dashIndex > 0 ? _version.Substring(0, dashIndex) : _version;
var semVerParts = trimmedVersion.Split('.').Reverse().Select(p => Convert.ToInt32(p)).ToList();
if(semVerParts.Count < 4)
{
semVerParts.Insert(0, 0);
}
for(var i = 0; i < semVerParts.Count; i++)
{
_versionWeight += Convert.ToInt32(Math.Pow(100, (i + 1)) * semVerParts[i]);
}
}
return (_version, _versionWeight);
return _version;
}
}
}

View File

@ -290,9 +290,7 @@ namespace Bit.Core.Utilities
{
httpContext.Response.OnStarting((state) =>
{
var info = CoreHelpers.GetVersionInfo();
httpContext.Response.Headers.Append("Server-Version", info.version);
httpContext.Response.Headers.Append("Server-Version-Weight", info.versionWeight.ToString());
httpContext.Response.Headers.Append("Server-Version", CoreHelpers.GetVersion());
return Task.FromResult(0);
}, null);