feat: Optimisation des images
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { createWriteStream, existsSync, mkdirSync } from "fs";
|
||||
import sharp from "sharp";
|
||||
import fs from "fs/promises";
|
||||
import { pipeline } from "stream";
|
||||
import { promisify } from "util";
|
||||
@ -56,15 +57,24 @@ async function fetchData() {
|
||||
for (const answer of question.questions_id.answers) {
|
||||
const uuid = answer.answers_id.image;
|
||||
if (uuid) {
|
||||
console.log(`${folder}/${uuid}`);
|
||||
const response = await fetchAsset(uuid);
|
||||
await streamPipeline(
|
||||
response.body,
|
||||
createWriteStream(`${folder}/${uuid}.png`)
|
||||
);
|
||||
try {
|
||||
const thumbnail = sharp().resize({ height: 200 }).webp();
|
||||
await streamPipeline(
|
||||
response.body,
|
||||
thumbnail,
|
||||
createWriteStream(`${folder}/${uuid}.webp`)
|
||||
);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// await sharp('src/assets/arbre.png').resize({ width: 440, height: 690 }).webp().toFile('public/arbre.webp')
|
||||
}
|
||||
|
||||
fetchData();
|
||||
|
Reference in New Issue
Block a user