Refactor logging configuration and enhance URI handling in attachment upload process

feat/add-thumbnail-router
John Niang 2025-09-30 00:46:15 +08:00
parent b6ab744d15
commit 0fc9b3bbc2
No known key found for this signature in database
GPG Key ID: D7363C015BBCAA59
4 changed files with 11 additions and 8 deletions

View File

@ -317,7 +317,6 @@ class LocalAttachmentUploadHandler implements AttachmentHandler {
return Optional.empty(); return Optional.empty();
} }
var uriStr = annotations.get(Constant.URI_ANNO_KEY); var uriStr = annotations.get(Constant.URI_ANNO_KEY);
// the uriStr is encoded before.
var uri = UriComponentsBuilder.fromUri(externalUrl.get()) var uri = UriComponentsBuilder.fromUri(externalUrl.get())
// The URI has been encoded before, so there is no need to encode it again. // The URI has been encoded before, so there is no need to encode it again.
.path(uriStr) .path(uriStr)

View File

@ -7,6 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.params.provider.Arguments.arguments; import static org.junit.jupiter.params.provider.Arguments.arguments;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.net.URI;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.Clock; import java.time.Clock;
@ -34,6 +35,7 @@ import run.halo.app.core.extension.attachment.Attachment;
import run.halo.app.core.extension.attachment.Policy; import run.halo.app.core.extension.attachment.Policy;
import run.halo.app.core.extension.attachment.endpoint.UploadOption; import run.halo.app.core.extension.attachment.endpoint.UploadOption;
import run.halo.app.extension.ConfigMap; import run.halo.app.extension.ConfigMap;
import run.halo.app.infra.ExternalUrlSupplier;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class LocalAttachmentUploadHandlerTest { class LocalAttachmentUploadHandlerTest {
@ -44,6 +46,9 @@ class LocalAttachmentUploadHandlerTest {
@Mock @Mock
AttachmentRootGetter attachmentRootGetter; AttachmentRootGetter attachmentRootGetter;
@Mock
ExternalUrlSupplier externalUrlSupplier;
@TempDir @TempDir
Path tempDir; Path tempDir;
@ -52,6 +57,7 @@ class LocalAttachmentUploadHandlerTest {
@BeforeEach @BeforeEach
void setUp() { void setUp() {
uploadHandler.setClock(clock); uploadHandler.setClock(clock);
when(externalUrlSupplier.get()).thenReturn(URI.create("/"));
} }
public static Stream<Arguments> testUploadWithRenameStrategy() { public static Stream<Arguments> testUploadWithRenameStrategy() {

View File

@ -1,6 +1,5 @@
package run.halo.app.core.endpoint.theme; package run.halo.app.core.endpoint.theme;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.net.URI; import java.net.URI;
@ -13,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import run.halo.app.core.attachment.ThumbnailService; import run.halo.app.core.attachment.ThumbnailService;
import run.halo.app.core.attachment.ThumbnailSize;
/** /**
* Tests for {@link ThumbnailEndpoint}. * Tests for {@link ThumbnailEndpoint}.
@ -39,13 +39,12 @@ class ThumbnailEndpointTest {
@Test @Test
void thumbnailUriNotAccessible() { void thumbnailUriNotAccessible() {
when(thumbnailService.get(any(), any())) when(thumbnailService.get(URI.create("/myavatar.png"), ThumbnailSize.L))
.thenReturn(Mono.just(URI.create("/thumbnail-not-found.png"))); .thenReturn(Mono.empty());
webClient.get() webClient.get()
.uri("/thumbnails/-/via-uri?size=l&uri=/myavatar.png") .uri("/thumbnails/-/via-uri?size=l&uri=/myavatar.png")
.exchange() .exchange()
.expectAll(responseSpec -> responseSpec.expectHeader().location("/myavatar.png")) .expectHeader().location("/myavatar.png")
.expectStatus() .expectStatus().is3xxRedirection();
.is3xxRedirection();
} }
} }

View File

@ -2,7 +2,6 @@ package run.halo.app.theme.finders.impl;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;