Skip to content

Commit

Permalink
Merge pull request #45 from OUCC/feat/#44
Browse files Browse the repository at this point in the history
#44 表紙画像作成・小説作成サービスを組み込む
  • Loading branch information
miyaji255 authored May 2, 2024
2 parents 5273779 + de96264 commit 51d161a
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 33 deletions.
13 changes: 0 additions & 13 deletions Epub/KoeBook.Epub/Services/AnalyzerService _CoverFileBytes.cs

This file was deleted.

9 changes: 5 additions & 4 deletions Epub/KoeBook.Epub/Services/AnalyzerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ public partial class AnalyzerService(
IScraperSelectorService scrapingService,
IEpubDocumentStoreService epubDocumentStoreService,
ILlmAnalyzerService llmAnalyzerService,
AiStoryAnalyzerService aiStoryAnalyzerService) : IAnalyzerService
AiStoryAnalyzerService aiStoryAnalyzerService,
ICreateCoverFileService createCoverFileService) : IAnalyzerService
{
private readonly IScraperSelectorService _scrapingService = scrapingService;
private readonly IEpubDocumentStoreService _epubDocumentStoreService = epubDocumentStoreService;
private readonly ILlmAnalyzerService _llmAnalyzerService = llmAnalyzerService;
private readonly AiStoryAnalyzerService _aiStoryAnalyzerService = aiStoryAnalyzerService;
private readonly ICreateCoverFileService _createCoverFileService = createCoverFileService;

public async ValueTask<BookScripts> AnalyzeAsync(BookProperties bookProperties, string tempDirectory, CancellationToken cancellationToken)
{
Directory.CreateDirectory(tempDirectory);
var coverFilePath = Path.Combine(tempDirectory, "Cover.png");
using var fs = File.Create(coverFilePath);
await fs.WriteAsync(CoverFile.ToArray(), cancellationToken);
await fs.FlushAsync(cancellationToken);

var rubyReplaced = false;
EpubDocument document;
Expand All @@ -44,6 +43,8 @@ public async ValueTask<BookScripts> AnalyzeAsync(BookProperties bookProperties,
default:
throw new UnreachableException($"SourceType: {bookProperties.SourceType}, Source: {bookProperties.Source}");
}

_createCoverFileService.Create(document.Title, document.Author, coverFilePath);
}
catch (EbookException) { throw; }
catch (Exception ex)
Expand Down
8 changes: 0 additions & 8 deletions KoeBook.Core/Contracts/Services/ILlmStoryGeneratorService.cs

This file was deleted.

4 changes: 2 additions & 2 deletions KoeBook.Core/Services/ClaudeStoryGeneratorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace KoeBook.Core.Services;

internal class ClaudeStoryGeneratorService(IClaudeService claudeService) : ILlmStoryGeneratorService
public class ClaudeStoryGeneratorService(IClaudeService claudeService) : IStoryCreatorService
{
private readonly IClaudeService _claudeService = claudeService;

public async ValueTask<string> GenerateStoryAsync(StoryGenre storyGenre, string premise, CancellationToken cancellationToken)
public async ValueTask<string> CreateStoryAsync(StoryGenre storyGenre, string premise, CancellationToken cancellationToken)
{
if (_claudeService.Messages is null)
{
Expand Down
7 changes: 6 additions & 1 deletion KoeBook.Test/DiTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using KoeBook.Core;
using KoeBook.Core.Contracts.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

Expand All @@ -17,6 +18,10 @@ protected static IHostBuilder CreateDefaultBuilder()
{
return Microsoft.Extensions.Hosting.Host
.CreateDefaultBuilder()
.UseCoreStartup();
.UseCoreStartup()
.ConfigureServices(services =>
{
services.AddSingleton<ICreateCoverFileService, MockCreateCoverFileService>();
});
}
}
13 changes: 13 additions & 0 deletions KoeBook.Test/MockCreateCoverFileService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using KoeBook.Core.Contracts.Services;

namespace KoeBook.Test;

internal class MockCreateCoverFileService : ICreateCoverFileService
{
public static ReadOnlySpan<byte> CoverFile => [89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x1, 0x2c, 0x0, 0x0, 0x1, 0x90, 0x8, 0x6, 0x0, 0x0, 0x0, 0x14, 0x75, 0x5d, 0x7b, 0x0, 0x0, 0x0, 0x1, 0x73,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, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x32, 0x84, 0x5, 0x64, 0x8, 0xb, 0xc8, 0x10, 0x16, 0x90, 0x21, 0x2c, 0x20, 0x43, 0x58, 0x40, 0x86, 0xb0, 0x80, 0xc, 0x61, 0x1, 0x19, 0xc2, 0x2, 0x22, 0xb6, 0x7, 0x7c, 0x3f, 0x1a, 0x75, 0x8a, 0x71, 0x90, 0x2f, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82];

public void Create(string title, string author, string coverFilePath)
{
File.WriteAllBytes(coverFilePath, CoverFile.ToArray());
}
}
Loading

0 comments on commit 51d161a

Please sign in to comment.