1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-07 05:58:13 -05: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() public VersionResponseModel()
: base("version") : base("version")
{ {
var info = CoreHelpers.GetVersionInfo(); Version = CoreHelpers.GetVersion();
Version = info.version;
VersionWeight = info.versionWeight;
} }
public string Version { get; set; } public string Version { get; set; }
public int VersionWeight { get; set; }
} }
} }

View File

@ -375,30 +375,16 @@ namespace Bit.Core.Utilities
return val.ToString(); return val.ToString();
} }
public static (string version, int versionWeight) GetVersionInfo() public static string GetVersion()
{ {
if(string.IsNullOrWhiteSpace(_version)) if(string.IsNullOrWhiteSpace(_version))
{ {
_version = Assembly.GetEntryAssembly() _version = Assembly.GetEntryAssembly()
.GetCustomAttribute<AssemblyInformationalVersionAttribute>() .GetCustomAttribute<AssemblyInformationalVersionAttribute>()
.InformationalVersion; .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++) return _version;
{
_versionWeight += Convert.ToInt32(Math.Pow(100, (i + 1)) * semVerParts[i]);
}
}
return (_version, _versionWeight);
} }
} }
} }

View File

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