Skip to content

Commit

Permalink
fix: refactor utils and av2bv
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystal-RainSlide committed Jan 26, 2025
1 parent 59b6e69 commit 46d3121
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 142 deletions.
4 changes: 3 additions & 1 deletion src/lib/server/av2bv.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const BASE = 58n;

const data = 'FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf';

/** @type { (aid: string | number) => string } */
export function av2bv(aid) {
const bytes = ['B', 'V', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0'];
let bvIndex = bytes.length - 1;
Expand All @@ -22,11 +23,12 @@ export function av2bv(aid) {
return bytes.join('');
}

/** @type { (bvid: string) => number } */
export function bv2av(bvid) {
const bvidArr = Array.from(bvid);
[bvidArr[3], bvidArr[9]] = [bvidArr[9], bvidArr[3]];
[bvidArr[4], bvidArr[7]] = [bvidArr[7], bvidArr[4]];
bvidArr.splice(0, 3);
const tmp = bvidArr.reduce((pre, bvidChar) => pre * BASE + BigInt(data.indexOf(bvidChar)), 0n);
return Number((tmp & MASK_CODE) ^ XOR_CODE);
}
}
Loading

0 comments on commit 46d3121

Please sign in to comment.