improve: base64 tool
This commit is contained in:
parent
ff0d05542d
commit
24f23b3573
@ -19,6 +19,8 @@ export default function Base64() {
|
|||||||
const [info, setInfo] = useState("");
|
const [info, setInfo] = useState("");
|
||||||
const [type, setType] = useState("");
|
const [type, setType] = useState("");
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
setType("");
|
||||||
|
setInfo("");
|
||||||
setHex(false);
|
setHex(false);
|
||||||
if (mode == "Encode") {
|
if (mode == "Encode") {
|
||||||
setMessageResult(utoa(message));
|
setMessageResult(utoa(message));
|
||||||
@ -29,14 +31,18 @@ export default function Base64() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
setMessageResult(normalizeHex(base64ToHex(message)));
|
setMessageResult(normalizeHex(base64ToHex(message)));
|
||||||
setHex(true);
|
setHex(true);
|
||||||
|
setType("info");
|
||||||
|
setInfo("Showing HEX result.");
|
||||||
}
|
}
|
||||||
} else if (message.trim() !== "") {
|
} else if (message.trim() !== "") {
|
||||||
setMessageResult("Invalid Base64");
|
setMessageResult("");
|
||||||
|
setType("warning");
|
||||||
|
setInfo("Invalid Base64.");
|
||||||
} else {
|
} else {
|
||||||
setMessageResult("");
|
setMessageResult("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}, [mode, message]);
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-3xl font-semibold">{t("base64.title")}</h1>
|
<h1 className="text-3xl font-semibold">{t("base64.title")}</h1>
|
||||||
@ -68,10 +74,9 @@ export default function Base64() {
|
|||||||
isHex ? "font-mono" : ""
|
isHex ? "font-mono" : ""
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{messageResult.length > 0 ? messageResult : "Waiting for input..."}
|
{messageResult}
|
||||||
</div>
|
</div>
|
||||||
<Notice type={type} info={info} class="mt-4" />
|
<Notice type={type} info={info} class="mt-4" />
|
||||||
<Notice type="info" info="HI." class="mt-4" />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ export default function () {
|
|||||||
{s.prompt && <span className="text-zinc-700 dark:text-zinc-400">{s.prompt}</span>}
|
{s.prompt && <span className="text-zinc-700 dark:text-zinc-400">{s.prompt}</span>}
|
||||||
<p>{s.suggestion}</p>
|
<p>{s.suggestion}</p>
|
||||||
{devMode && (
|
{devMode && (
|
||||||
<span className="absolute text-zinc-700 dark:text-zinc-400 text-sm leading-10 h-10 right-2">
|
<span className="bottom-0 absolute text-zinc-700 dark:text-zinc-400 text-sm leading-10 h-10 right-2">
|
||||||
{s.relevance}
|
{s.relevance}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
@ -2,17 +2,16 @@ export default function (props: { children: React.ReactNode; selected: boolean }
|
|||||||
if (props.selected) {
|
if (props.selected) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`w-full h-auto leading-6 break-all py-[0.6rem] bg-zinc-300 dark:bg-zinc-700
|
className={`block w-full h-auto leading-6 break-all py-[0.6rem] bg-zinc-300 dark:bg-zinc-700
|
||||||
px-5 z-10 cursor-pointer duration-100`}
|
px-5 z-10 cursor-pointer duration-100`}
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`w-full h-auto leading-6 break-all py-[0.6rem] bg-zinc-100 hover:bg-zinc-300
|
className={`block w-full h-auto leading-6 break-all py-[0.6rem] bg-zinc-100 hover:bg-zinc-300
|
||||||
dark:bg-zinc-800 hover:dark:bg-zinc-700 px-5 z-10 cursor-pointer duration-100`}
|
dark:bg-zinc-800 hover:dark:bg-zinc-700 px-5 z-10 cursor-pointer duration-100`}
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
|
@ -23,10 +23,10 @@ export default function Notice(props: { type: string; info: string; class?: stri
|
|||||||
<div
|
<div
|
||||||
className={`relative ${props.class} ${
|
className={`relative ${props.class} ${
|
||||||
typeToColor[props.type]
|
typeToColor[props.type]
|
||||||
} rounded-md w-full min-h-9 h-fit empty:px-0 px-4 mx-1 z-20 cursor-pointer duration-100`}
|
} rounded-md w-full min-h-12 h-fit empty:px-0 px-4 z-20 cursor-pointer duration-100 `}
|
||||||
>
|
>
|
||||||
<Icon className="text-2xl mt-3" icon={typeToIcon[props.type]} />
|
<Icon className="text-2xl mt-3" icon={typeToIcon[props.type]} />
|
||||||
<span className="">{props.info}</span>
|
<span className="absolute text-base mt-3 ml-1">{props.info}</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import slotExtract from "../nlp/extract";
|
import slotExtract from "../nlp/extract";
|
||||||
import removeStopwords from "../nlp/stopwords";
|
import removeStopwords from "../nlp/stopwords";
|
||||||
import { NLPResult } from "./NLPResult";
|
import { NLPResult } from "./NLPResult";
|
||||||
import {Kbd} from "@nextui-org/react";
|
import { Kbd } from "@nextui-org/react";
|
||||||
|
|
||||||
interface KeywordsDict {
|
interface KeywordsDict {
|
||||||
[key: string]: number;
|
[key: string]: number;
|
||||||
@ -45,25 +45,21 @@ export function base64NLP(str: string) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let processedQuery = str;
|
let processedQuery = str;
|
||||||
if (result.intention==="base64.encode"){
|
if (result.intention === "base64.encode") {
|
||||||
const blacklist = Object.keys(keywords).concat(Object.keys(intentions)).concat([
|
const blacklist = Object.keys(keywords).concat(Object.keys(intentions)).concat(["convert", "turn"]);
|
||||||
"convert", "turn"
|
processedQuery = slotExtract(str, blacklist);
|
||||||
]);
|
} else if (result.intention === "base64.decode") {
|
||||||
processedQuery = slotExtract(str,blacklist);
|
|
||||||
} else if (result.intention==="base64.decode") {
|
|
||||||
processedQuery = removeStopwords(str, Object.keys(keywords).concat(Object.keys(intentions))).trim();
|
processedQuery = removeStopwords(str, Object.keys(keywords).concat(Object.keys(intentions))).trim();
|
||||||
}
|
}
|
||||||
if (result.intention === "base64.decode"){
|
if (result.intention === "base64.decode") {
|
||||||
if (validBase64(processedQuery)) {
|
if (validBase64(processedQuery)) {
|
||||||
result.confidence = 1;
|
result.confidence = 1;
|
||||||
} else {
|
} else {
|
||||||
result.confidence = 0;
|
result.confidence = 0;
|
||||||
}
|
}
|
||||||
}
|
} else if (validBase64(processedQuery) && result.intention !== "base64.encode") {
|
||||||
else if (validBase64(processedQuery) && result.intention !== "base64.encode") {
|
|
||||||
console.log("!!");
|
|
||||||
result.intention = "base64.decode";
|
result.intention = "base64.decode";
|
||||||
result.confidence += Math.max(1 / Math.log2(1 / processedQuery.length) + 1, 0);
|
result.confidence += Math.max(1 / Math.log2(1 / processedQuery.length) + 1, 0);
|
||||||
result.probability += Math.max(1 / Math.log2(1 / processedQuery.length) + 1, 0);
|
result.probability += Math.max(1 / Math.log2(1 / processedQuery.length) + 1, 0);
|
||||||
@ -72,12 +68,19 @@ export function base64NLP(str: string) {
|
|||||||
switch (result.intention) {
|
switch (result.intention) {
|
||||||
case "base64.encode":
|
case "base64.encode":
|
||||||
result.suggestion = btoa(processedQuery);
|
result.suggestion = btoa(processedQuery);
|
||||||
result.prompt = <span>Base64 Encode (Hit <Kbd keys={["enter"]}></Kbd> to copy):</span>;
|
result.prompt = (
|
||||||
|
<span>
|
||||||
|
Base64 Encode (Hit <Kbd keys={["enter"]}></Kbd> to copy):
|
||||||
|
</span>
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "base64.decode":
|
case "base64.decode":
|
||||||
if (result.confidence > 0.1)
|
if (result.confidence > 0.1) result.suggestion = atob(processedQuery);
|
||||||
result.suggestion = atob(processedQuery);
|
result.prompt = (
|
||||||
result.prompt = <span>Base64 Decode (Hit <Kbd keys={["enter"]}></Kbd> to copy):</span>;
|
<span>
|
||||||
|
Base64 Decode (Hit <Kbd keys={["enter"]}></Kbd> to copy):
|
||||||
|
</span>
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user