Updated naming for hashes
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a0a1e4626b
commit
9517e6d2c9
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
File diff suppressed because one or more lines are too long
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||||
|
@ -73,7 +74,6 @@ export async function optimizeImages() {
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
imagePaths.map(async (imagePath) => {
|
imagePaths.map(async (imagePath) => {
|
||||||
console.log(`Optimizing file ${imagePath}`);
|
|
||||||
const timerName = `File ${imagePath} took: `;
|
const timerName = `File ${imagePath} took: `;
|
||||||
console.time(timerName);
|
console.time(timerName);
|
||||||
|
|
||||||
|
@ -83,18 +83,22 @@ export async function optimizeImages() {
|
||||||
const encoder = GET_ENCODER_FROM_EXTENSION[fileExtension];
|
const encoder = GET_ENCODER_FROM_EXTENSION[fileExtension];
|
||||||
|
|
||||||
if (!encoder) {
|
if (!encoder) {
|
||||||
|
console.log(`Only copying ${imagePath}`);
|
||||||
await fse.copy(sourcePath, destinationPath);
|
await fse.copy(sourcePath, destinationPath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawImageFile = await fse.readFile(sourcePath);
|
const rawImageFile = await fse.readFile(sourcePath);
|
||||||
const fileHash = SparkMD5.hash(rawImageFile.toString());
|
|
||||||
|
// compare hash of file contents so we dont optimize images which have already been optimized before
|
||||||
|
const fileHash = `${imagePath}-${SparkMD5.hash(rawImageFile.toString())}`;
|
||||||
|
|
||||||
if (alreadyOptimizedImageHashes.has(fileHash)) {
|
if (alreadyOptimizedImageHashes.has(fileHash)) {
|
||||||
console.log(`Skipping ${imagePath}`);
|
console.log(`Skipping ${imagePath}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`Optimizing file ${imagePath}`);
|
||||||
const ingestedImage = imagePool.ingestImage(rawImageFile);
|
const ingestedImage = imagePool.ingestImage(rawImageFile);
|
||||||
const { width, height } = getImageDimensions(rawImageFile);
|
const { width, height } = getImageDimensions(rawImageFile);
|
||||||
|
|
||||||
|
@ -126,6 +130,7 @@ export async function optimizeImages() {
|
||||||
await fse.outputFile(destinationPath, encodedImage.binary);
|
await fse.outputFile(destinationPath, encodedImage.binary);
|
||||||
alreadyOptimizedImageHashes.add(fileHash);
|
alreadyOptimizedImageHashes.add(fileHash);
|
||||||
console.timeEnd(timerName);
|
console.timeEnd(timerName);
|
||||||
|
await writeSaveFile(alreadyOptimizedImageHashes);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue