mirror of
https://github.com/vega-org/vega-providers.git
synced 2026-04-17 15:41:45 +00:00
fix: multistream
This commit is contained in:
2
dist/autoEmbed/meta.js
vendored
2
dist/autoEmbed/meta.js
vendored
@@ -1 +1 @@
|
|||||||
"use strict";var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){var value;result.done?resolve(result.value):(value=result.value,value instanceof P?value:new P(function(resolve){resolve(value)})).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getMeta=void 0;const getMeta=function(_a){return __awaiter(this,arguments,void 0,function*({link:link,providerContext:providerContext}){var _b,_c,_d,_e,_f,_g,_h,_j,_k,_l,_m;const axios=providerContext.axios;try{const data=(yield axios.get(link)).data,meta={title:"",synopsis:"",image:"",imdbId:(null===(_b=null==data?void 0:data.meta)||void 0===_b?void 0:_b.imdb_id)||"",type:(null===(_c=null==data?void 0:data.meta)||void 0===_c?void 0:_c.type)||"movie"},links=[];let directLinks=[],season=new Map;if("series"===meta.type){null===(_e=null===(_d=null==data?void 0:data.meta)||void 0===_d?void 0:_d.videos)||void 0===_e||_e.map(video=>{var _a,_b,_c,_d,_e,_f,_g,_h;(null==video?void 0:video.season)<=0||(season.has(null==video?void 0:video.season)||season.set(null==video?void 0:video.season,[]),season.get(null==video?void 0:video.season).push({title:"Episode "+(null==video?void 0:video.episode),type:"series",link:JSON.stringify({title:null===(_a=null==data?void 0:data.meta)||void 0===_a?void 0:_a.name,imdbId:null===(_b=null==data?void 0:data.meta)||void 0===_b?void 0:_b.imdb_id,season:null===(_c=null==video?void 0:video.id)||void 0===_c?void 0:_c.split(":")[1],episode:null===(_d=null==video?void 0:video.id)||void 0===_d?void 0:_d.split(":")[2],type:null===(_e=null==data?void 0:data.meta)||void 0===_e?void 0:_e.type,tmdbId:(null===(_g=null===(_f=null==data?void 0:data.meta)||void 0===_f?void 0:_f.moviedb_id)||void 0===_g?void 0:_g.toString())||"",year:null===(_h=null==data?void 0:data.meta)||void 0===_h?void 0:_h.year})}))});const keys=Array.from(season.keys());keys.sort(),keys.map(key=>{directLinks=season.get(key),links.push({title:`Season ${key}`,directLinks:directLinks})})}else links.push({title:null===(_f=null==data?void 0:data.meta)||void 0===_f?void 0:_f.name,directLinks:[{title:"Movie",type:"movie",link:JSON.stringify({title:null===(_g=null==data?void 0:data.meta)||void 0===_g?void 0:_g.name,imdbId:null===(_h=null==data?void 0:data.meta)||void 0===_h?void 0:_h.imdb_id,season:"",episode:"",type:null===(_j=null==data?void 0:data.meta)||void 0===_j?void 0:_j.type,tmdbId:(null===(_l=null===(_k=null==data?void 0:data.meta)||void 0===_k?void 0:_k.moviedb_id)||void 0===_l?void 0:_l.toString())||"",year:null===(_m=null==data?void 0:data.meta)||void 0===_m?void 0:_m.year})}]});return Object.assign(Object.assign({},meta),{linkList:links})}catch(err){return{title:"",synopsis:"",image:"",imdbId:"",type:"movie",linkList:[]}}})};exports.getMeta=getMeta;
|
"use strict";var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){var value;result.done?resolve(result.value):(value=result.value,value instanceof P?value:new P(function(resolve){resolve(value)})).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getMeta=void 0;const getMeta=function(_a){return __awaiter(this,arguments,void 0,function*({link:link,providerContext:providerContext}){var _b,_c,_d,_e,_f,_g,_h,_j,_k,_l,_m,_o,_p,_q;const axios=providerContext.axios;try{const data=(yield axios.get(link)).data,meta={title:(null===(_b=null==data?void 0:data.meta)||void 0===_b?void 0:_b.name)||"",synopsis:(null===(_c=null==data?void 0:data.meta)||void 0===_c?void 0:_c.description)||"",image:(null===(_d=null==data?void 0:data.meta)||void 0===_d?void 0:_d.background)||"",imdbId:(null===(_e=null==data?void 0:data.meta)||void 0===_e?void 0:_e.imdb_id)||"",type:(null===(_f=null==data?void 0:data.meta)||void 0===_f?void 0:_f.type)||"movie"},links=[];let directLinks=[],season=new Map;if("series"===meta.type){null===(_h=null===(_g=null==data?void 0:data.meta)||void 0===_g?void 0:_g.videos)||void 0===_h||_h.map(video=>{var _a,_b,_c,_d,_e,_f,_g,_h;(null==video?void 0:video.season)<=0||(season.has(null==video?void 0:video.season)||season.set(null==video?void 0:video.season,[]),season.get(null==video?void 0:video.season).push({title:"Episode "+(null==video?void 0:video.episode),type:"series",link:JSON.stringify({title:null===(_a=null==data?void 0:data.meta)||void 0===_a?void 0:_a.name,imdbId:null===(_b=null==data?void 0:data.meta)||void 0===_b?void 0:_b.imdb_id,season:null===(_c=null==video?void 0:video.id)||void 0===_c?void 0:_c.split(":")[1],episode:null===(_d=null==video?void 0:video.id)||void 0===_d?void 0:_d.split(":")[2],type:null===(_e=null==data?void 0:data.meta)||void 0===_e?void 0:_e.type,tmdbId:(null===(_g=null===(_f=null==data?void 0:data.meta)||void 0===_f?void 0:_f.moviedb_id)||void 0===_g?void 0:_g.toString())||"",year:null===(_h=null==data?void 0:data.meta)||void 0===_h?void 0:_h.year})}))});const keys=Array.from(season.keys());keys.sort(),keys.map(key=>{directLinks=season.get(key),links.push({title:`Season ${key}`,directLinks:directLinks})})}else links.push({title:null===(_j=null==data?void 0:data.meta)||void 0===_j?void 0:_j.name,directLinks:[{title:"Movie",type:"movie",link:JSON.stringify({title:null===(_k=null==data?void 0:data.meta)||void 0===_k?void 0:_k.name,imdbId:null===(_l=null==data?void 0:data.meta)||void 0===_l?void 0:_l.imdb_id,season:"",episode:"",type:null===(_m=null==data?void 0:data.meta)||void 0===_m?void 0:_m.type,tmdbId:(null===(_p=null===(_o=null==data?void 0:data.meta)||void 0===_o?void 0:_o.moviedb_id)||void 0===_p?void 0:_p.toString())||"",year:null===(_q=null==data?void 0:data.meta)||void 0===_q?void 0:_q.year})}]});return Object.assign(Object.assign({},meta),{linkList:links})}catch(err){return{title:"",synopsis:"",image:"",imdbId:"",type:"movie",linkList:[]}}})};exports.getMeta=getMeta;
|
||||||
2
dist/autoEmbed/stream.js
vendored
2
dist/autoEmbed/stream.js
vendored
File diff suppressed because one or more lines are too long
@@ -13,9 +13,9 @@ export const getMeta = async function ({
|
|||||||
const res = await axios.get(link);
|
const res = await axios.get(link);
|
||||||
const data = res.data;
|
const data = res.data;
|
||||||
const meta = {
|
const meta = {
|
||||||
title: "",
|
title: data?.meta?.name || "",
|
||||||
synopsis: "",
|
synopsis: data?.meta?.description || "",
|
||||||
image: "",
|
image: data?.meta?.background || "",
|
||||||
imdbId: data?.meta?.imdb_id || "",
|
imdbId: data?.meta?.imdb_id || "",
|
||||||
type: data?.meta?.type || "movie",
|
type: data?.meta?.type || "movie",
|
||||||
};
|
};
|
||||||
@@ -53,7 +53,6 @@ export const getMeta = async function ({
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log("all meta Mv🔥🔥", meta);
|
|
||||||
links.push({
|
links.push({
|
||||||
title: data?.meta?.name as string,
|
title: data?.meta?.name as string,
|
||||||
directLinks: [
|
directLinks: [
|
||||||
|
|||||||
@@ -11,12 +11,25 @@ export const getStream = async ({
|
|||||||
}): Promise<Stream[]> => {
|
}): Promise<Stream[]> => {
|
||||||
try {
|
try {
|
||||||
const streams: Stream[] = [];
|
const streams: Stream[] = [];
|
||||||
const { imdbId, season, episode, title, tmdbId, year } = JSON.parse(id);
|
const payload = (() => {
|
||||||
|
try {
|
||||||
|
return JSON.parse(id);
|
||||||
|
} catch {
|
||||||
|
return { tmdbId: id };
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
const tmdbId: string | number =
|
||||||
|
payload.tmdbId ?? payload.id ?? payload.tmdId ?? "";
|
||||||
|
const season: string = payload.season ?? "";
|
||||||
|
const episode: string = payload.episode ?? "";
|
||||||
|
const effectiveType: string = payload.type ?? type ?? "movie";
|
||||||
|
|
||||||
await getRiveStream(
|
await getRiveStream(
|
||||||
tmdbId,
|
String(tmdbId),
|
||||||
episode,
|
episode,
|
||||||
season,
|
season,
|
||||||
type,
|
effectiveType,
|
||||||
streams,
|
streams,
|
||||||
providerContext
|
providerContext
|
||||||
);
|
);
|
||||||
@@ -35,31 +48,25 @@ export async function getRiveStream(
|
|||||||
Streams: Stream[],
|
Streams: Stream[],
|
||||||
providerContext: ProviderContext
|
providerContext: ProviderContext
|
||||||
) {
|
) {
|
||||||
const secret = generateSecretKey(Number(tmdId));
|
if (!tmdId || tmdId === "undefined") {
|
||||||
|
console.warn("autoEmbed/rive: missing tmdbId in link payload");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const secret = generateSecretKey(tmdId);
|
||||||
const servers = [
|
const servers = [
|
||||||
"flowcast",
|
"flowcast",
|
||||||
"shadow",
|
"primevids",
|
||||||
|
"humpy",
|
||||||
|
"loki",
|
||||||
"asiacloud",
|
"asiacloud",
|
||||||
|
"shadow",
|
||||||
"hindicast",
|
"hindicast",
|
||||||
"anime",
|
|
||||||
"animez",
|
"animez",
|
||||||
"guard",
|
"aqua",
|
||||||
"curve",
|
"voyager",
|
||||||
"hq",
|
"yggdrasil",
|
||||||
"ninja",
|
|
||||||
"alpha",
|
|
||||||
"kaze",
|
|
||||||
"zenesis",
|
|
||||||
"genesis",
|
|
||||||
"zenith",
|
|
||||||
"ghost",
|
|
||||||
"halo",
|
|
||||||
"kinoecho",
|
|
||||||
"ee3",
|
|
||||||
"volt",
|
|
||||||
"putafilme",
|
"putafilme",
|
||||||
"ophim",
|
"ophim",
|
||||||
"kage",
|
|
||||||
];
|
];
|
||||||
const baseUrl = await providerContext.getBaseUrl("rive");
|
const baseUrl = await providerContext.getBaseUrl("rive");
|
||||||
const cors = process.env.CORS_PRXY ? process.env.CORS_PRXY + "?url=" : "";
|
const cors = process.env.CORS_PRXY ? process.env.CORS_PRXY + "?url=" : "";
|
||||||
@@ -109,142 +116,177 @@ export async function getRiveStream(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateSecretKey(id: number | string) {
|
function generateSecretKey(id: number | string) {
|
||||||
// Array of secret key fragments - updated array from the new implementation
|
// Array of secret key fragments from the provided implementation
|
||||||
const c = [
|
const c = [
|
||||||
"Yhv40uKAZa",
|
"oYRu3JJ5g1C",
|
||||||
"nn8YU4yBA",
|
"TRlWJIJXT",
|
||||||
"uNeH",
|
"RuoyGA0udvsFVXr",
|
||||||
"ehK",
|
"Y4s2LNM4y",
|
||||||
"jT0",
|
"wHzuSgl0fD",
|
||||||
"n5G",
|
"MGLTaSGs",
|
||||||
"99R",
|
"rr0rSBIYfwutV7E",
|
||||||
"MvB1M",
|
"ABJXC9c",
|
||||||
"DQtPCh",
|
"W2BuY0yDB9CcK",
|
||||||
"GBRjk4k4I",
|
"3yvZP1OJuTM",
|
||||||
"CzIOoa95UT",
|
"YDoqbu6zdN0zT",
|
||||||
"BLE8s",
|
"rnNQ2a5OBaMu",
|
||||||
"GDZlc7",
|
"eSKa1Uy",
|
||||||
"Fz45T",
|
"QsIV8J472Xa",
|
||||||
"JW6lWn",
|
"cPfTgu27",
|
||||||
"DE3g4uw0i",
|
"j4mzadQCou9",
|
||||||
"18KxmYizv",
|
"qHLZbLrZQfB",
|
||||||
"8ji",
|
"8U9YP6hrTz4cJNQ",
|
||||||
"JUDdNMnZ",
|
"xbAbu4pzFEXz",
|
||||||
"oGpBippPgm",
|
"dhuA9zvdw",
|
||||||
"7De8Pg",
|
"k3A1JGmb",
|
||||||
"Zv6",
|
"eVC3z4COdUNvvzA",
|
||||||
"VHT9TVN",
|
"dwMmuXnrb",
|
||||||
"bYH6m",
|
"AqpWzY9I1ZmGPR",
|
||||||
"aK1",
|
"VGXWUm0JTetmXs",
|
||||||
"WcWH6jU",
|
"gD4sH3CISTanpTs",
|
||||||
"Q47YEMi4k",
|
"d6w8dntV",
|
||||||
"vRD3A",
|
"iL6dvSNqEab4kd",
|
||||||
"CGOsfJO",
|
"mIB8NFtmPjnX1kM",
|
||||||
"BLn8",
|
"F4PXdP0Hx3",
|
||||||
"RgK0drv7l",
|
"5Fijua4Z7C",
|
||||||
"oPTfGCn3a",
|
"wPGnHJrkYa1Tu4P",
|
||||||
"MkpMDkttW9",
|
"pjrfBfTf",
|
||||||
"VNI1fPM",
|
"vswQDEbM0y64io",
|
||||||
"XNFi6",
|
"LAnpQuk6hR2bEWs",
|
||||||
"6cq",
|
"kX8orxNnkK",
|
||||||
"4LvTksXoEI",
|
"mRsZ5fjHbC8YuT",
|
||||||
"1rRa2KOZB0",
|
"JnBr1jr",
|
||||||
"zoOGRb8HT2",
|
"2twFGU5PgvDmKdP",
|
||||||
"mhcXDtvz",
|
"3wCg6zYtHFjy",
|
||||||
"NUmexFY2Ur",
|
"gaQSJhixHiy1pa8",
|
||||||
"6BIMdvSZ",
|
"pE2cXTP0GPX",
|
||||||
"Tr0zU2vjRd",
|
"xr0ONW3sOnCRdt",
|
||||||
"QPR",
|
"QZu43flHFsebX",
|
||||||
"fhOqJR",
|
"yrvtqRTOnHo",
|
||||||
"R9VnFY",
|
"kvXEs16lgj",
|
||||||
"xkZ99D6S",
|
"AGwT2zpQVHCMb09",
|
||||||
"umY7E",
|
"M4BxOh3z2JgC",
|
||||||
"5Ds8qyDq",
|
"5hbV7briYC7",
|
||||||
"Cc6jy09y3",
|
"YfHMsm0",
|
||||||
"yvU3iR",
|
"jC9PAPfz34Vgc",
|
||||||
"Bg07zY",
|
"ExoJ1tgEXpK",
|
||||||
"GccECglg",
|
"eD8WPA4Lmsyf4W",
|
||||||
"VYd",
|
"h7WSlhT7iNOj",
|
||||||
"6vOiXqz",
|
"RRP61kk",
|
||||||
"7xX",
|
"QtY0f1aN",
|
||||||
"UdRrbEzF",
|
"TlatGjcOQjup",
|
||||||
"fE6wc",
|
"MfpeEGbjouYSOa",
|
||||||
"BUd25Rb",
|
"Zz0Qh8B0pwUkdRT",
|
||||||
"lxq5Zum89o",
|
"Y4SkLSQNU",
|
||||||
|
"hOk01KFeEVbNRZx",
|
||||||
|
"fyf4H8MXazm3oY",
|
||||||
|
"Z116B9F2p",
|
||||||
|
"GdxNJOnvdz",
|
||||||
|
"kqVNNHfP",
|
||||||
|
"IO3hhNu",
|
||||||
|
"qDdC9Lcllce",
|
||||||
|
"Et7lLOg",
|
||||||
|
"6ZlQrvfgZu",
|
||||||
|
"YXHLeZBF",
|
||||||
|
"NH6nAd7y",
|
||||||
|
"ARsut59gfK6j0v",
|
||||||
|
"jPE2KXiJjnSsjn",
|
||||||
|
"qYcG5HOJc3TtxM",
|
||||||
|
"C2w06YGj5C",
|
||||||
|
"kHx1pT7",
|
||||||
|
"2enXfHXw",
|
||||||
|
"koFHBiR054aizN",
|
||||||
|
"Uj53XTQ92Ntbq7K",
|
||||||
|
"QjC5euFYi2AuxWb",
|
||||||
|
"njLwvdMejA",
|
||||||
|
"NWMzrwTAVZEb",
|
||||||
|
"s4sVqC0AyTM5h",
|
||||||
|
"pu01jeZ6AoH",
|
||||||
|
"SgiOfwx9qkR",
|
||||||
|
"grjsLtBNn9eTQg",
|
||||||
|
"XABTTaYgihZk2mq",
|
||||||
|
"2vlSCZQc3HT27F4",
|
||||||
|
"kQZ7VQfEL3TC7P",
|
||||||
|
"MEzqVne021W",
|
||||||
|
"BLYPZp2SIO",
|
||||||
|
"5zDMVoqw4nH",
|
||||||
|
"t14S9uLuGKX7Lb5",
|
||||||
|
"4McODHAYTyp",
|
||||||
|
"EAoxL5UKvMPqjH3",
|
||||||
|
"hJpAbqp",
|
||||||
|
"tcj63Wpz",
|
||||||
|
"hGqEu0LxKkMv46P",
|
||||||
|
"u2wNvb8ou19N3",
|
||||||
|
"wUKY6Opi1kH",
|
||||||
];
|
];
|
||||||
|
|
||||||
// Handle undefined input
|
|
||||||
if (id === undefined) {
|
if (id === undefined) {
|
||||||
return "rive";
|
return "rive";
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let fragment, insertPos;
|
let t: string, n: number;
|
||||||
// Convert input to string
|
const r = String(id);
|
||||||
const idStr = String(id);
|
|
||||||
|
if (isNaN(Number(id))) {
|
||||||
|
const sum = r.split("").reduce((e, ch) => e + ch.charCodeAt(0), 0);
|
||||||
|
t = c[sum % c.length] || btoa(r);
|
||||||
|
n = Math.floor((sum % r.length) / 2);
|
||||||
|
} else {
|
||||||
|
const num = Number(id);
|
||||||
|
t = c[num % c.length] || btoa(r);
|
||||||
|
n = Math.floor((num % r.length) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
const i = r.slice(0, n) + t + r.slice(n);
|
||||||
|
|
||||||
// Updated string hash function to match the new implementation
|
|
||||||
/* eslint-disable no-bitwise */
|
/* eslint-disable no-bitwise */
|
||||||
const generateStringHash = function (input: string) {
|
const innerHash = (e: string) => {
|
||||||
input = String(input);
|
e = String(e);
|
||||||
let hash = 0;
|
let t = 0 >>> 0;
|
||||||
for (let i = 0; i < input.length; i++) {
|
for (let n = 0; n < e.length; n++) {
|
||||||
const char = input.charCodeAt(i);
|
const r = e.charCodeAt(n);
|
||||||
hash =
|
const i =
|
||||||
((char + (hash << 6) + (hash << 16) - hash) ^ (char << i % 5)) >>> 0;
|
(((t = (r + (t << 6) + (t << 16) - t) >>> 0) << n % 5) |
|
||||||
|
(t >>> (32 - (n % 5)))) >>>
|
||||||
|
0;
|
||||||
|
t = (t ^ (i ^ (((r << n % 7) | (r >>> (8 - (n % 7)))) >>> 0))) >>> 0;
|
||||||
|
t = (t + ((t >>> 11) ^ (t << 3))) >>> 0;
|
||||||
}
|
}
|
||||||
hash ^= hash >>> 13;
|
t ^= t >>> 15;
|
||||||
hash = (1540483477 * hash) >>> 0;
|
t = ((t & 65535) * 49842 + ((((t >>> 16) * 49842) & 65535) << 16)) >>> 0;
|
||||||
return (hash ^= hash >>> 15).toString(16).padStart(8, "0");
|
t ^= t >>> 13;
|
||||||
|
t = ((t & 65535) * 40503 + ((((t >>> 16) * 40503) & 65535) << 16)) >>> 0;
|
||||||
|
t ^= t >>> 16;
|
||||||
|
return t.toString(16).padStart(8, "0");
|
||||||
};
|
};
|
||||||
|
|
||||||
// Updated MurmurHash-like function to match the new implementation
|
const outerHash = (e: string) => {
|
||||||
const applyMurmurHash = function (input: string) {
|
const t = String(e);
|
||||||
const str = String(input);
|
let n = (3735928559 ^ t.length) >>> 0;
|
||||||
let hash = 3735928559 ^ str.length;
|
for (let idx = 0; idx < t.length; idx++) {
|
||||||
for (let i = 0; i < str.length; i++) {
|
let r = t.charCodeAt(idx);
|
||||||
let char = str.charCodeAt(i);
|
r ^= ((131 * idx + 89) ^ (r << idx % 5)) & 255;
|
||||||
char ^= ((i + 31) * 131) & 255;
|
n = (((n << 7) | (n >>> 25)) >>> 0) ^ r;
|
||||||
hash =
|
const i = ((n & 65535) * 60205) >>> 0;
|
||||||
(668265261 *
|
const o = (((n >>> 16) * 60205) << 16) >>> 0;
|
||||||
(hash = (((hash << 7) | (hash >>> 25)) >>> 0) ^ char)) >>>
|
n = (i + o) >>> 0;
|
||||||
0;
|
n ^= n >>> 11;
|
||||||
}
|
}
|
||||||
hash ^= hash >>> 16;
|
n ^= n >>> 15;
|
||||||
hash = (2246822507 * hash) >>> 0;
|
n = (((n & 65535) * 49842 + (((n >>> 16) * 49842) << 16)) >>> 0) >>> 0;
|
||||||
hash ^= hash >>> 13;
|
n ^= n >>> 13;
|
||||||
hash = (3266489909 * hash) >>> 0;
|
n = (((n & 65535) * 40503 + (((n >>> 16) * 40503) << 16)) >>> 0) >>> 0;
|
||||||
return (hash ^= hash >>> 16).toString(16).padStart(8, "0");
|
n ^= n >>> 16;
|
||||||
|
n = (((n & 65535) * 10196 + (((n >>> 16) * 10196) << 16)) >>> 0) >>> 0;
|
||||||
|
n ^= n >>> 15;
|
||||||
|
return n.toString(16).padStart(8, "0");
|
||||||
};
|
};
|
||||||
/* eslint-enable no-bitwise */
|
/* eslint-enable no-bitwise */
|
||||||
|
|
||||||
// Generate the encoded hash using the new implementation
|
const o = outerHash(innerHash(i));
|
||||||
const encodedHash = btoa(applyMurmurHash(generateStringHash(idStr)));
|
return btoa(o);
|
||||||
|
} catch (e) {
|
||||||
// Different handling for non-numeric vs numeric inputs
|
|
||||||
if (isNaN(Number(id))) {
|
|
||||||
// For non-numeric inputs, sum the character codes
|
|
||||||
const charSum = idStr
|
|
||||||
.split("")
|
|
||||||
.reduce((sum, char) => sum + char.charCodeAt(0), 0);
|
|
||||||
// Select array element or fallback to base64 encoded input
|
|
||||||
fragment = c[charSum % c.length] || btoa(idStr);
|
|
||||||
// Calculate insertion position
|
|
||||||
insertPos = Math.floor((charSum % encodedHash.length) / 2);
|
|
||||||
} else {
|
|
||||||
// For numeric inputs, use the number directly
|
|
||||||
const numId = Number(id);
|
|
||||||
fragment = c[numId % c.length] || btoa(idStr);
|
|
||||||
// Calculate insertion position
|
|
||||||
insertPos = Math.floor((numId % encodedHash.length) / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct the final key by inserting the selected value into the base64 string
|
|
||||||
return (
|
|
||||||
encodedHash.slice(0, insertPos) + fragment + encodedHash.slice(insertPos)
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
// Return fallback value if any errors occur
|
|
||||||
return "topSecret";
|
return "topSecret";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user