mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: update hash function
This commit is contained in:
parent
2b52e90dd6
commit
9580b4fe6c
@ -9,8 +9,8 @@
|
|||||||
import { Avatar, Box } from "@mui/material";
|
import { Avatar, Box } from "@mui/material";
|
||||||
import UiChatWidget from "hexabot-chat-widget/src/UiChatWidget";
|
import UiChatWidget from "hexabot-chat-widget/src/UiChatWidget";
|
||||||
import {
|
import {
|
||||||
extractSettingValues,
|
generateHashFromString,
|
||||||
generateUUIDFromString,
|
getSettingValues,
|
||||||
} from "hexabot-chat-widget/src/utils/text";
|
} from "hexabot-chat-widget/src/utils/text";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@ -33,7 +33,7 @@ export const ChatWidget = () => {
|
|||||||
const [key, setKey] = useState("");
|
const [key, setKey] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const settingValues = extractSettingValues(settings, [
|
const settingValues = getSettingValues(settings, [
|
||||||
{
|
{
|
||||||
group: "console_channel",
|
group: "console_channel",
|
||||||
label: "allowed_domains",
|
label: "allowed_domains",
|
||||||
@ -46,7 +46,7 @@ export const ChatWidget = () => {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
setKey(generateUUIDFromString(settingValues.join()));
|
generateHashFromString(settingValues.join()).then((key) => setKey(key));
|
||||||
}, [settings]);
|
}, [settings]);
|
||||||
|
|
||||||
return isAuthenticated ? (
|
return isAuthenticated ? (
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createHash } from "node:crypto";
|
|
||||||
|
|
||||||
import { ChannelSettings } from "../providers/SettingsProvider";
|
import { ChannelSettings } from "../providers/SettingsProvider";
|
||||||
|
|
||||||
export const truncate = (s: string, length = 100) => {
|
export const truncate = (s: string, length = 100) => {
|
||||||
@ -26,10 +24,15 @@ export const processContent = (s: string) => {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generateUUIDFromString = (str: string) => {
|
export const generateHashFromString = async (str: string) => {
|
||||||
const hash = createHash("sha256").update(str).digest("hex");
|
const msgBuffer = new TextEncoder().encode(str);
|
||||||
|
const hashBuffer = await crypto.subtle.digest("SHA-256", msgBuffer);
|
||||||
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||||
|
const hashHex = hashArray
|
||||||
|
.map((b) => b.toString(16).padStart(2, "0"))
|
||||||
|
.join("");
|
||||||
|
|
||||||
return hash.replace(/(.{8})(.{4})(.{4})(.{4})(.+)/, "$1-$2-$3-$4-$5");
|
return hashHex;
|
||||||
};
|
};
|
||||||
|
|
||||||
type TChannel = "console_channel";
|
type TChannel = "console_channel";
|
||||||
@ -45,15 +48,10 @@ type TCriterion = {
|
|||||||
selectedField: keyof TSetting;
|
selectedField: keyof TSetting;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const extractSettingValue = (
|
export const getSettingValue = (settings: TSettings, criterion: TCriterion) =>
|
||||||
settings: TSettings,
|
|
||||||
criterion: TCriterion,
|
|
||||||
) =>
|
|
||||||
settings?.[criterion.group]?.find(
|
settings?.[criterion.group]?.find(
|
||||||
(setting) => setting.label === criterion.label,
|
(setting) => setting.label === criterion.label,
|
||||||
)?.[criterion?.selectedField];
|
)?.[criterion?.selectedField];
|
||||||
|
|
||||||
export const extractSettingValues = (
|
export const getSettingValues = (settings: TSettings, criteria: TCriterion[]) =>
|
||||||
settings: TSettings,
|
criteria.map((criterion) => getSettingValue(settings, criterion));
|
||||||
criteria: TCriterion[],
|
|
||||||
) => criteria.map((criterion) => extractSettingValue(settings, criterion));
|
|
||||||
|
Loading…
Reference in New Issue
Block a user