public async Task <Score> GetScore( [FromRoute(Name = "score_name")] string scoreName) { var metaFileOperator = new MetaFileOperator(S3Client, BucketName); var urlConvertor = new MinioUrlConvertor(S3Client.Config.ServiceURL, BucketName); var metas = await metaFileOperator.GetScoreMetaAsync(scoreName); Uri CreateVersionUrl(string name, int v) { return(new Uri($"{Request.Scheme}://{Request.Host}/api/v1/score/{name}/version/{v}")); } var meta = metas.GetLastScoreContent(); var score = new Score() { Name = meta.Name, Title = meta.Title, Description = meta.Description, VersionMetaUrls = meta.VersionFileKeys .OrderBy(x => x.Key) .Select(x => int.Parse(x.Key)) .Select(version => new ScoreVersionMetaUrl() { Version = version, Url = CreateVersionUrl(meta.Name, version), }).ToArray(), }; return(score); }
public async Task <ScoreVersion> GetVersion( [FromRoute(Name = "score_name")] string scoreName, [FromRoute(Name = "version")] int version) { var metaFileOperator = new MetaFileOperator(S3Client, BucketName); var scoreMeta = await metaFileOperator.GetScoreMetaAsync(scoreName); var scoreContentMeta = scoreMeta.GetLastScoreContent(); var versionText = version.ToString("00000"); if (scoreContentMeta.VersionFileKeys.TryGetValue(versionText, out var versionFileKey) == false) { throw new InvalidOperationException($"'{scoreName}' にバージョン '{version}' は存在しません"); } var versionMeta = await metaFileOperator.GetVersionMetaAsync(versionFileKey); var urlConvertor = new MinioUrlConvertor(S3Client.Config.ServiceURL, BucketName); var metaConvertor = new ScoreMetaConvertor(); var scoreVersion = metaConvertor.ConvertTo(versionMeta, urlConvertor); return(scoreVersion); }
public ScoreVersion ConvertTo(ScoreVersionMeta meta, MinioUrlConvertor urlConvertor) { var version = new ScoreVersion { Version = meta.Version, }; version.Pages = meta.Pages.Select(x => new ScoreVersionPage() { No = int.Parse(x.Value.No), ImageUrl = urlConvertor.CreateUri(x.Value.ImageFileKey) }).ToArray(); return(version); }
public async IAsyncEnumerable <Score> GetScores() { var metaFileOperator = new MetaFileOperator(S3Client, BucketName); var scoreNames = await metaFileOperator.GetScoreNamesAsync(); var urlConvertor = new MinioUrlConvertor(S3Client.Config.ServiceURL, BucketName); var tasks = scoreNames.AsParallel() .Select(name => metaFileOperator.GetScoreMetaAsync(name)) .ToArray(); var scoreMetas = await Task.WhenAll(tasks); Uri CreateVersionUrl(string name, int v) { return(new Uri($"{Request.Scheme}://{Request.Host}/api/v1/score/{name}/version/{v}")); } var scores = scoreMetas.Select(metas => metas.GetLastScoreContent()) .Select(meta => new Score() { Name = meta.Name, Title = meta.Title, Description = meta.Description, VersionMetaUrls = meta.VersionFileKeys .OrderBy(x => x.Key) .Select(x => int.Parse(x.Key)) .Select(version => new ScoreVersionMetaUrl() { Version = version, Url = CreateVersionUrl(meta.Name, version), }).ToArray(), }); foreach (var score in scores) { yield return(score); } }