Added download option for assignment cards

Export PDF Download to hook
Prevented some NaN's
This commit is contained in:
Joao Ramos
2024-01-09 23:15:13 +00:00
parent 418221427a
commit cc0f9712d6
6 changed files with 111 additions and 88 deletions

View File

@@ -22,22 +22,23 @@ export const getRadialProgressPNG = (
// calculate the percentage of the score
// and round it to the closest available image
const percent = (score / total) * 100;
if (isNaN(percent)) return `public/radial_progress/${color}_0.png`;
const remainder = percent % 10;
const roundedPercent = percent - remainder;
return `public/radial_progress/${color}_${roundedPercent}.png`;
};
export const streamToBuffer = async (
stream: NodeJS.ReadableStream
): Promise<Buffer> => {
return new Promise((resolve, reject) => {
const chunks: Buffer[] = [];
stream.on("data", (data) => {
chunks.push(data);
});
stream.on("end", () => {
resolve(Buffer.concat(chunks));
});
stream.on("error", reject);
stream: NodeJS.ReadableStream
): Promise<Buffer> => {
return new Promise((resolve, reject) => {
const chunks: Buffer[] = [];
stream.on("data", (data) => {
chunks.push(data);
});
};
stream.on("end", () => {
resolve(Buffer.concat(chunks));
});
stream.on("error", reject);
});
};