[FA-misc] Fix issues with novel imports
All checks were successful
CI / build-backend (pull_request) Successful in 1m46s
CI / build-frontend (pull_request) Successful in 44s

This commit is contained in:
gamer147
2026-01-30 12:48:40 -05:00
parent ec967770d3
commit 3c8c8c8707
10 changed files with 86 additions and 21 deletions

View File

@@ -0,0 +1,3 @@
namespace FictionArchive.Service.NovelService.Contracts;
public record ImportNovelResult(Guid ImportId, string NovelUrl);

View File

@@ -16,7 +16,7 @@ public class Mutation
{
[Error<InvalidOperationException>]
[Authorize]
public async Task<NovelImportRequested> ImportNovel(string novelUrl, NovelUpdateService service)
public async Task<ImportNovelResult> ImportNovel(string novelUrl, NovelUpdateService service)
{
return await service.QueueNovelImport(novelUrl);
}

View File

@@ -57,9 +57,10 @@ public class NovelImportSaga : MassTransitStateMachine<NovelImportSagaState>
{
ctx.Saga.NovelId = ctx.Message.NovelId;
ctx.Saga.ExpectedChapters = ctx.Message.ChaptersPendingPull;
ctx.Saga.ExpectedImages += ctx.Message.CoverImageQueued ? 1 : 0;
})
.IfElse(
ctx => ctx.Saga.ExpectedChapters == 0,
ctx => ctx.Saga.ExpectedChapters == 0 && !ctx.Message.CoverImageQueued,
thenBinder => thenBinder
.Then(ctx => ctx.Saga.CompletedAt = _clock.GetCurrentInstant())
.TransitionTo(Completed)

View File

@@ -427,15 +427,18 @@ public class NovelUpdateService
.Where(c => c.Body?.Texts == null || !c.Body.Texts.Any())
.ToList();
var hasCoverToUpload = shouldPublishCoverEvent && novel.CoverImage != null && metadata.CoverImage != null;
// Publish metadata imported event for saga
await _publishEndpoint.Publish<INovelMetadataImported>(new NovelMetadataImported(
importId,
novel.Id,
chaptersNeedingPull.Count
chaptersNeedingPull.Count,
hasCoverToUpload
));
// Publish cover image event if needed
if (shouldPublishCoverEvent && novel.CoverImage != null && metadata.CoverImage != null)
if (hasCoverToUpload)
{
await _publishEndpoint.Publish<IFileUploadRequestCreated>(new FileUploadRequestCreated(
importId,
@@ -568,7 +571,7 @@ public class NovelUpdateService
await _dbContext.SaveChangesAsync();
}
public async Task<NovelImportRequested> QueueNovelImport(string novelUrl)
public async Task<ImportNovelResult> QueueNovelImport(string novelUrl)
{
var importId = Guid.NewGuid();
var activeImport = new ActiveImport
@@ -590,7 +593,7 @@ public class NovelUpdateService
var importNovelRequestEvent = new NovelImportRequested(importId, novelUrl);
await _publishEndpoint.Publish<INovelImportRequested>(importNovelRequestEvent);
return importNovelRequestEvent;
return new ImportNovelResult(importId, novelUrl);
}
public async Task<ChapterPullRequested> QueueChapterPull(Guid importId, uint novelId, uint volumeId, uint chapterOrder)