fix(route/pubscholar): add x-finger (#20052)

This commit is contained in:
Tony 2025-09-15 03:44:42 +08:00 committed by GitHub
parent 3ea7e1ccc1
commit dd100ccf3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 0 deletions

View File

@ -23,6 +23,18 @@ const generateNonce = (length: number): string => {
return nonce.slice(0, length);
};
/**
* Part of fingerprint2.js shim from uBlock Origin
* Taken from https://github.com/gorhill/uBlock/blob/master/src/web_accessible_resources/fingerprint2.js
* @param len
* @returns
*/
const hex32 = (len) =>
Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)
.toString(16)
.slice(-len)
.padStart(len, '0');
export const getSignedHeaders = () => {
const nonce = generateNonce(6);
const timestamp = Date.now().toString();
@ -31,6 +43,7 @@ export const getSignedHeaders = () => {
nonce,
timestamp,
signature,
'x-finger': `${hex32(8)}${hex32(8)}${hex32(8)}${hex32(8)}`,
};
};