forked from open-webui/open-webui
style: run npm run format
This commit is contained in:
parent
a68b95c95f
commit
5694f16624
3 changed files with 27 additions and 16 deletions
|
@ -151,9 +151,12 @@
|
||||||
if (canvasPixelTest()) {
|
if (canvasPixelTest()) {
|
||||||
profileImageUrl = generateInitialsImage(name);
|
profileImageUrl = generateInitialsImage(name);
|
||||||
} else {
|
} else {
|
||||||
toast.error("Canvas pixel test failed, fingerprint evasion likely. Disable fingerprint evasion and try again!", {
|
toast.error(
|
||||||
autoClose: 1000 * 10,
|
'Canvas pixel test failed, fingerprint evasion likely. Disable fingerprint evasion and try again!',
|
||||||
});
|
{
|
||||||
|
autoClose: 1000 * 10
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}}>{$i18n.t('Use Gravatar')}</button
|
}}>{$i18n.t('Use Gravatar')}</button
|
||||||
>
|
>
|
||||||
|
|
|
@ -99,7 +99,7 @@ export const getGravatarURL = (email) => {
|
||||||
export const canvasPixelTest = () => {
|
export const canvasPixelTest = () => {
|
||||||
// Test a 1x1 pixel to potentially identify browser/plugin fingerprint blocking or spoofing
|
// Test a 1x1 pixel to potentially identify browser/plugin fingerprint blocking or spoofing
|
||||||
// Inspiration: https://github.com/kkapsner/CanvasBlocker/blob/master/test/detectionTest.js
|
// Inspiration: https://github.com/kkapsner/CanvasBlocker/blob/master/test/detectionTest.js
|
||||||
const canvas = document.createElement("canvas");
|
const canvas = document.createElement('canvas');
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
canvas.height = 1;
|
canvas.height = 1;
|
||||||
canvas.width = 1;
|
canvas.width = 1;
|
||||||
|
@ -110,8 +110,7 @@ export const canvasPixelTest = () => {
|
||||||
for (let i = 0; i < imageData.data.length; i += 1) {
|
for (let i = 0; i < imageData.data.length; i += 1) {
|
||||||
if (i % 4 !== 3) {
|
if (i % 4 !== 3) {
|
||||||
pixelValues[i] = Math.floor(256 * Math.random());
|
pixelValues[i] = Math.floor(256 * Math.random());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
pixelValues[i] = 255;
|
pixelValues[i] = 255;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,14 +121,21 @@ export const canvasPixelTest = () => {
|
||||||
// Read RGB data and fail if unmatched
|
// Read RGB data and fail if unmatched
|
||||||
for (let i = 0; i < p.length; i += 1) {
|
for (let i = 0; i < p.length; i += 1) {
|
||||||
if (p[i] !== pixelValues[i]) {
|
if (p[i] !== pixelValues[i]) {
|
||||||
console.log("canvasPixelTest: Wrong canvas pixel RGB value detected:", p[i], "at:", i, "expected:", pixelValues[i]);
|
console.log(
|
||||||
console.log("canvasPixelTest: Canvas blocking or spoofing is likely");
|
'canvasPixelTest: Wrong canvas pixel RGB value detected:',
|
||||||
|
p[i],
|
||||||
|
'at:',
|
||||||
|
i,
|
||||||
|
'expected:',
|
||||||
|
pixelValues[i]
|
||||||
|
);
|
||||||
|
console.log('canvasPixelTest: Canvas blocking or spoofing is likely');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const generateInitialsImage = (name) => {
|
export const generateInitialsImage = (name) => {
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
|
@ -138,7 +144,9 @@ export const generateInitialsImage = (name) => {
|
||||||
canvas.height = 100;
|
canvas.height = 100;
|
||||||
|
|
||||||
if (!canvasPixelTest()) {
|
if (!canvasPixelTest()) {
|
||||||
console.log("generateInitialsImage: failed pixel test, fingerprint evasion is likely. Using default image.");
|
console.log(
|
||||||
|
'generateInitialsImage: failed pixel test, fingerprint evasion is likely. Using default image.'
|
||||||
|
);
|
||||||
return '/user.png';
|
return '/user.png';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,8 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!canvasPixelTest()) {
|
if (!canvasPixelTest()) {
|
||||||
toast.error("Canvas pixel test failed, fingerprint evasion likely. Default image used.", {
|
toast.error('Canvas pixel test failed, fingerprint evasion likely. Default image used.', {
|
||||||
autoClose: 1000 * 10,
|
autoClose: 1000 * 10
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue