refactor: remove announcement workaround for links

This commit is contained in:
Gauthier Roebroeck 2023-12-15 15:37:03 +08:00
parent a4ffbc2b49
commit c4d686898c
2 changed files with 1 additions and 28 deletions

View file

@ -38,7 +38,7 @@ class AnnouncementController(
fun getAnnouncements(
@AuthenticationPrincipal principal: KomgaPrincipal,
): JsonFeedDto {
return cache.get("announcements") { fetchWebsiteAnnouncements()?.let { replaceLinks(it) } }
return cache.get("announcements") { fetchWebsiteAnnouncements() }
?.let { feed ->
val read = userRepository.findAnnouncementIdsReadByUserId(principal.user.id)
feed.copy(items = feed.items.map { item -> item.copy(komgaExtension = JsonFeedDto.KomgaExtensionDto(read.contains(item.id))) })
@ -63,14 +63,4 @@ class AnnouncementController(
.block()
return response?.body
}
// while waiting for https://github.com/facebook/docusaurus/issues/9136
fun replaceLinks(feed: JsonFeedDto): JsonFeedDto = feed.copy(
items = feed.items.map {
it.copy(
contentHtml =
it.contentHtml?.replace("""<a href="/""", """<a href="$website/"""),
)
},
)
}

View file

@ -3,7 +3,6 @@ package org.gotson.komga.interfaces.api.rest
import com.ninjasquad.springmockk.SpykBean
import io.mockk.every
import io.mockk.verify
import org.assertj.core.api.Assertions.assertThat
import org.gotson.komga.domain.model.ROLE_ADMIN
import org.gotson.komga.interfaces.api.rest.dto.JsonFeedDto
import org.junit.jupiter.api.Test
@ -72,20 +71,4 @@ class AnnouncementControllerTest(
verify(exactly = 1) { announcementController.fetchWebsiteAnnouncements() }
}
@Test
fun `given json feed with relative links when replacing then links are replaced`() {
val feed = announcementController.replaceLinks(mockFeed)
assertThat(feed.items.first().contentHtml)
.contains(
"""<a href="https://komga.org/docs/installation/""",
"""<a href="https://komga.org/blog/post/">here</a>""",
"""<a href="https://google.com">link</a>""",
)
.doesNotContain(
"""<a href="/docs/installation/""",
"""<a href="/blog/post/>here</a>""",
)
}
}