示例#1
0
        /// <summary>
        /// 検索メタデータをアップロードします。
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private ValueTask UploadMetadataAsync(SearchMetadata metadata, CancellationToken cancellationToken = default)
        {
            var fileName  = $"KK{metadata.Number}.json";
            var json      = JsonSerializer.Serialize(metadata);
            var container = this.BlobClient.GetContainerReference(SearchMetadataContainerName);
            var blob      = container.GetBlockBlobReference(fileName);

            return(blob.UploadFromByteArrayAsync(json, 0, json.Length, cancellationToken).AsValueTask());
        }
示例#2
0
        /// <summary>
        /// 検索データを構築します。
        /// </summary>
        /// <param name="shortCode"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <SearchMetadata> BuildAsync(string shortCode, CancellationToken cancellationToken = default)
        {
            var post = await this.ScrapingService.ExtractPostAsync(shortCode, cancellationToken).ConfigureAwait(false);

            if (post.Owner.UserName != AccountName)
            {
                var message = $"{AccountName} 以外の投稿データを取得しようとしています | AccountName : {post.Owner.UserName}";
                throw new InvalidOperationException(message);
            }

            var result   = CaptionParser.Parse(post.Caption);
            var metadata = new SearchMetadata(post, result);
            var t1       = this.CopyThumbnailAsync(post.Medias[0].ImageUrl, metadata.Number, overwrite: true, cancellationToken);
            var t2       = this.UploadMetadataAsync(metadata, cancellationToken);
            await ValueTaskEx.WhenAll(t1, t2).ConfigureAwait(false);

            return(metadata);
        }
示例#3
0
        /// <summary>
        /// 検索データを構築します。
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask BuildAsync(CancellationToken cancellationToken = default)
        {
            var posts = await this.ScrapingService.ExtractPostSlimsAsync(AccountName, recursive : false, cancellationToken).ConfigureAwait(false);

            foreach (var x in posts)
            {
                try
                {
                    var result   = CaptionParser.Parse(x.Caption);
                    var metadata = new SearchMetadata(x, result);
                    var t1       = this.CopyThumbnailAsync(x.ImageUrl, metadata.Number, overwrite: false, cancellationToken);
                    var t2       = this.UploadMetadataAsync(metadata, cancellationToken);
                    await ValueTaskEx.WhenAll(t1, t2).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    var message = $"検索データの構築中にエラーが発生しました | ShortCode : {x.ShortCode}";
                    this.Logger.LogError(ex, message);
                    throw;
                }
            }
        }