Skip to content

Commit

Permalink
[Issue comixed#73] Return the missing image placeholder when no cover…
Browse files Browse the repository at this point in the history
… is found during import.
  • Loading branch information
mcpierce committed Mar 11, 2020
1 parent 27b3f82 commit 42eaf7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.comixed.adaptors.archive.ArchiveAdaptorException;
import org.comixed.controller.library.ComicController;
import org.comixed.handlers.ComicFileHandlerException;
Expand Down Expand Up @@ -89,15 +90,30 @@ private void getAllFilesUnder(File root, List<FileDetails> result) throws IOExce
}

@RequestMapping(value = "/import/cover", method = RequestMethod.GET)
public byte[] getImportFileCover(@RequestParam("filename") String filename)
throws ComicFileHandlerException, ArchiveAdaptorException {
public byte[] getImportFileCover(@RequestParam("filename") String filename) {
// for some reason, during development, this value ALWAYS had a trailing
// space...
filename = filename.trim();

this.logger.info("Getting cover image for archive: filename={}", filename);

return this.fileService.getImportFileCover(filename);
byte[] result = null;

try {
result = this.fileService.getImportFileCover(filename);
} catch (ComicFileHandlerException | ArchiveAdaptorException error) {
this.logger.error("Failed to load cover from import file", error);
}

if (result == null) {
try {
result = IOUtils.toByteArray(this.getClass().getResourceAsStream("/images/missing.png"));
} catch (IOException error) {
this.logger.error("Failed to load the missing page image", error);
}
}

return result;
}

@RequestMapping(value = "/import/status", method = RequestMethod.GET)
Expand Down
Expand Up @@ -57,7 +57,7 @@ public class FileControllerTest {
@Mock private List<FileDetails> fileDetailsList;

@Test
public void testGetImportFileCover() throws ComicFileHandlerException, ArchiveAdaptorException {
public void testGetImportFileCover() throws ArchiveAdaptorException, ComicFileHandlerException {
Mockito.when(fileService.getImportFileCover(Mockito.anyString())).thenReturn(IMAGE_CONTENT);

final byte[] result = controller.getImportFileCover(COMIC_ARCHIVE);
Expand Down

0 comments on commit 42eaf7f

Please sign in to comment.