Ejemplo n.º 1
0
        private async Task <IActionResult> TryServeBuildFileAsync(BuildFile buildFile, string version = null)
        {
            // FIXME: duplicate code
            if (Request.Headers.TryGetValue(HeaderNames.IfNoneMatch, out var etag))
            {
                var resources = await _builds.GetAvailableBuildsAsync(CancellationToken);

                foreach (var hash in etag)
                {
                    if (resources.Contains(hash))
                    {
                        return(StatusCode((int)HttpStatusCode.NotModified));
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(version))
            {
                var versionHash = await _builds.GetBuildByVersionAsync(version, CancellationToken);

                if (versionHash == null)
                {
                    return(NotFound(new { Message = $"Specified build {version} not found." }));
                }

                return(await ServeBuildFileAsync(version, buildFile, CancellationToken));
            }

            var buildHash = await _builds.GetLatestStableBuildAsync(CancellationToken);

            if (buildHash == null)
            {
                return(NotFound(new { Message = "No builds found." }));
            }

            return(await ServeBuildFileAsync(buildHash, buildFile, CancellationToken));
        }