mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
fix(pdf): handle a failed cover bake where it happens, lower the eslint baseline
Client types: the overview test used Array.prototype.at, which the client's lib setting does not include; it reads the last cell with slice instead. Client lint: the export swallowed a failed cover bake with .catch(() => null). bakePdfCover now catches a canvas that will not draw or encode itself and says why, so the export calls it plainly. The rewrite also leaves fewer warnings, and the baseline is lowered to the counts the run measured: complexity 216, no-explicit-any 138, no-unused-vars 117, and in the tests no-non-null-assertion 1872.
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
"@typescript-eslint/no-non-null-assertion": 367,
|
||||
"@typescript-eslint/no-misused-promises": 820,
|
||||
"no-console": 88,
|
||||
"complexity": 217,
|
||||
"@typescript-eslint/no-explicit-any": 143,
|
||||
"complexity": 216,
|
||||
"@typescript-eslint/no-explicit-any": 138,
|
||||
"trek/no-swallowed-catch": 126,
|
||||
"max-params": 31,
|
||||
"trek/store-without-selector": 66,
|
||||
@@ -12,7 +12,7 @@
|
||||
"react-hooks/set-state-in-effect": 189,
|
||||
"@typescript-eslint/no-floating-promises": 162,
|
||||
"react-hooks/exhaustive-deps": 113,
|
||||
"@typescript-eslint/no-unused-vars": 120,
|
||||
"@typescript-eslint/no-unused-vars": 117,
|
||||
"react-hooks/immutability": 28,
|
||||
"max-lines-per-function": 127,
|
||||
"react-hooks/static-components": 50,
|
||||
@@ -35,7 +35,7 @@
|
||||
},
|
||||
"tests": {
|
||||
"@typescript-eslint/no-explicit-any": 489,
|
||||
"@typescript-eslint/no-non-null-assertion": 1875,
|
||||
"@typescript-eslint/no-non-null-assertion": 1872,
|
||||
"@typescript-eslint/no-misused-promises": 22,
|
||||
"@typescript-eslint/no-unused-vars": 51,
|
||||
"@typescript-eslint/no-floating-promises": 33,
|
||||
|
||||
@@ -292,7 +292,7 @@ export async function downloadTripPDF({ trip, days, places, assignments: allStor
|
||||
return [day.id, photos.slice(0, 3)]
|
||||
}))
|
||||
// The cover photo and its shade as one picture at print size (null: printed as before).
|
||||
const bakedCover = coverImg ? await bakePdfCover(coverImg, COVER_SHADE, signal).catch(() => null) : null
|
||||
const bakedCover = coverImg ? await bakePdfCover(coverImg, COVER_SHADE, signal) : null
|
||||
const stripCopies = await shrinkPdfImages([...stripPhotos.values()].flat().map(p => p.url), signal, STRIP_PX)
|
||||
.catch(() => new Map<string, string>())
|
||||
|
||||
|
||||
@@ -144,6 +144,10 @@ export async function bakePdfCover(
|
||||
ctx.fillRect(0, 0, COVER_W, COVER_H);
|
||||
const baked = canvas.toDataURL('image/jpeg', COVER_QUALITY);
|
||||
return baked.startsWith('data:image/jpeg') ? baked : null;
|
||||
} catch {
|
||||
// A canvas the browser will not draw or encode (out of memory on a phone, say):
|
||||
// the cover then prints the photo and its shade as separate layers, as before.
|
||||
return null;
|
||||
} finally {
|
||||
bitmap.close();
|
||||
}
|
||||
|
||||
@@ -148,12 +148,12 @@ describe('glanceHtml', () => {
|
||||
expect(texts(without, 'thead th')).toEqual(['pdf.day', 'common.date', 'pdf.plan', 'pdf.stay', '']);
|
||||
expect(texts(without, 'tbody tr:first-child td')).toEqual(['1', 'Sun, Nov 1', 'Tokyo', 'Hotel Gracery', '3']);
|
||||
// A day without stops leaves the cell empty rather than printing a zero.
|
||||
expect(texts(without, 'tbody tr:last-child td').at(-1)).toBe('');
|
||||
expect(texts(without, 'tbody tr:last-child td').slice(-1)[0]).toBe('');
|
||||
expect(without.querySelector('tbody tr')?.getAttribute('style')).toBe('--day:#0a84ff');
|
||||
|
||||
const withCost = parse(glanceHtml([row(), row({ number: 2, cost: '¥3,000' })], tr));
|
||||
expect(texts(withCost, 'thead th').at(-1)).toBe('pdf.costLabel');
|
||||
expect(texts(withCost, 'tbody tr:last-child td').at(-1)).toBe('¥3,000');
|
||||
expect(texts(withCost, 'thead th').slice(-1)[0]).toBe('pdf.costLabel');
|
||||
expect(texts(withCost, 'tbody tr:last-child td').slice(-1)[0]).toBe('¥3,000');
|
||||
|
||||
expect(glanceHtml([], tr)).toBe('');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user