Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #73] Return an image placeholder when one isn't found on the backend #177

Merged
merged 2 commits into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.security.NoSuchAlgorithmException;
import javax.imageio.ImageIO;
import javax.persistence.*;
import org.apache.commons.io.IOUtils;
import org.codehaus.plexus.util.StringUtils;
import org.comixed.adaptors.archive.ArchiveAdaptorException;
import org.comixed.views.View.ComicList;
Expand Down Expand Up @@ -183,9 +184,18 @@ public byte[] getContent() {
return this.comic.archiveType.getArchiveAdaptor().loadSingleFile(this.comic, this.filename);
}
} catch (ArchiveAdaptorException error) {
this.logger.warn(
this.logger.error(
"failed to load entry: " + this.filename + " comic=" + this.comic.getFilename(), error);
}

// if we're here then return the missing page image since we didn't load the one we wanted
try {
return IOUtils.toByteArray(this.getClass().getResourceAsStream("/images/missing.png"));
} catch (IOException error) {
this.logger.error("failed to load missing page image", error);
}

// if we're here, we have nothing to return
return null;
}

Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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