Skip to content

Commit

Permalink
Merge branch 'master' of github.com:openzim/mwoffliner
Browse files Browse the repository at this point in the history
  • Loading branch information
ISNIT0 committed Feb 24, 2019
2 parents 5ea6502 + 3c29283 commit 573565e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,14 @@ async function getContent(requestOptions: any, handler: any) {
try {
const resp = await axios(requestOptions);
const responseHeaders = resp.headers;
const compressed = await imagemin.buffer(resp.data, imageminOptions);

const shouldCompress = responseHeaders['content-type'].includes('image/');
const compressed = shouldCompress ? await imagemin.buffer(resp.data, imageminOptions) : resp.data;

const compressionWorked = compressed.length < resp.data.length;
if (compressionWorked) {
logger.info(`Compressed data from [${requestOptions.url}] from [${resp.data.length}] to [${compressed.length}]`);
} else {
} else if (shouldCompress) {
logger.warn(`Failed to reduce file size after optimisation attempt [${requestOptions.url}]... Went from [${resp.data.length}] to [${compressed.length}]`);
}

Expand Down

0 comments on commit 573565e

Please sign in to comment.