Пример #1
0
        public async Task <DownloadAssetResult> Handle(DownloadAssetQuery request, CancellationToken cancellationToken)
        {
            var asset = await _db.Assets.SingleOrDefaultAsync(e => e.Uuid == request.Id && e.ReleaseId != null);

            if (asset is null)
            {
                throw new AppException(AppErrorCode.NotFound);
            }

            cancellationToken.ThrowIfCancellationRequested();

            string url = _objectStorage.SupportsDownloadUrl
                ? await _objectStorage.GetDownloadUrl(asset.StoragePath, expiry : _downloadUrlExpiry, contentType : _contentType, fileName : asset.Name, cancellationToken : cancellationToken)
                : null;

            cancellationToken.ThrowIfCancellationRequested();

            var stream = _objectStorage.SupportsDownloadStream
                ? await _objectStorage.GetDownloadStream(asset.StoragePath, cancellationToken : cancellationToken)
                : null;

            cancellationToken.ThrowIfCancellationRequested();

            _logger.LogInformation("URL for downloading asset with UUID {0}: {1}", asset.Uuid, url);

            return(new DownloadAssetResult {
                Url = url,
                Name = asset.Name,
                Stream = stream
            });
        }