mirror of
https://github.com/hexastack/hexabot
synced 2025-04-27 01:39:59 +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 UiChatWidget from "hexabot-chat-widget/src/UiChatWidget";
|
||||
import {
|
||||
extractSettingValues,
|
||||
generateUUIDFromString,
|
||||
generateHashFromString,
|
||||
getSettingValues,
|
||||
} from "hexabot-chat-widget/src/utils/text";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
@ -33,7 +33,7 @@ export const ChatWidget = () => {
|
||||
const [key, setKey] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
const settingValues = extractSettingValues(settings, [
|
||||
const settingValues = getSettingValues(settings, [
|
||||
{
|
||||
group: "console_channel",
|
||||
label: "allowed_domains",
|
||||
@ -46,7 +46,7 @@ export const ChatWidget = () => {
|
||||
},
|
||||
]);
|
||||
|
||||
setKey(generateUUIDFromString(settingValues.join()));
|
||||
generateHashFromString(settingValues.join()).then((key) => setKey(key));
|
||||
}, [settings]);
|
||||
|
||||
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).
|
||||
*/
|
||||
|
||||
import { createHash } from "node:crypto";
|
||||
|
||||
import { ChannelSettings } from "../providers/SettingsProvider";
|
||||
|
||||
export const truncate = (s: string, length = 100) => {
|
||||
@ -26,10 +24,15 @@ export const processContent = (s: string) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
export const generateUUIDFromString = (str: string) => {
|
||||
const hash = createHash("sha256").update(str).digest("hex");
|
||||
export const generateHashFromString = async (str: string) => {
|
||||
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";
|
||||
@ -45,15 +48,10 @@ type TCriterion = {
|
||||
selectedField: keyof TSetting;
|
||||
};
|
||||
|
||||
export const extractSettingValue = (
|
||||
settings: TSettings,
|
||||
criterion: TCriterion,
|
||||
) =>
|
||||
export const getSettingValue = (settings: TSettings, criterion: TCriterion) =>
|
||||
settings?.[criterion.group]?.find(
|
||||
(setting) => setting.label === criterion.label,
|
||||
)?.[criterion?.selectedField];
|
||||
|
||||
export const extractSettingValues = (
|
||||
settings: TSettings,
|
||||
criteria: TCriterion[],
|
||||
) => criteria.map((criterion) => extractSettingValue(settings, criterion));
|
||||
export const getSettingValues = (settings: TSettings, criteria: TCriterion[]) =>
|
||||
criteria.map((criterion) => getSettingValue(settings, criterion));
|
||||
|
Loading…
Reference in New Issue
Block a user