mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-11 17:50:29 +03:00
Fix crash on malformed blurhash (#2331)
This commit is contained in:
parent
5964eee833
commit
df391968d8
3 changed files with 15 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { encode } from 'blurhash';
|
||||
import { encode, isBlurhashValid } from 'blurhash';
|
||||
|
||||
export const encodeBlurHash = (
|
||||
img: HTMLImageElement | HTMLVideoElement,
|
||||
|
|
@ -17,3 +17,13 @@ export const encodeBlurHash = (
|
|||
const data = context.getImageData(0, 0, canvas.width, canvas.height);
|
||||
return encode(data.data, data.width, data.height, 4, 4);
|
||||
};
|
||||
|
||||
export const validBlurHash = (hash?: string): string | undefined => {
|
||||
if (typeof hash === 'string') {
|
||||
const validity = isBlurhashValid(hash);
|
||||
|
||||
return validity.result ? hash : undefined;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue