mirror of
https://github.com/gotson/komga.git
synced 2025-12-25 01:42:44 +01:00
refactor: remove announcement workaround for links
This commit is contained in:
parent
a4ffbc2b49
commit
c4d686898c
2 changed files with 1 additions and 28 deletions
|
|
@ -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/"""),
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>""",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue