From 7cd826b05280d97111bcdbb66bf807e6929bfa6d Mon Sep 17 00:00:00 2001 From: typist <1003659191@qq.com> Date: Tue, 28 Oct 2025 04:39:39 +0800 Subject: [PATCH] feat: add-tool `base64` (#7) Co-authored-by: typist Reviewed-on: https://gitea.typist.cc/typist/litek/pulls/7 --- src/components/tool/base64.tsx | 70 ++++++++++++++++++++++++++++++++++ src/components/tool/index.tsx | 10 ++++- src/layout.tsx | 4 +- 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 src/components/tool/base64.tsx diff --git a/src/components/tool/base64.tsx b/src/components/tool/base64.tsx new file mode 100644 index 0000000..f47b957 --- /dev/null +++ b/src/components/tool/base64.tsx @@ -0,0 +1,70 @@ +import { useState, type FC } from "react"; +import { Textarea } from "@/components/ui/textarea"; +import { Button } from "@/components/ui/button"; +import { toast } from "sonner"; +import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react"; + +const Tool: FC = () => { + const [decoded, setDecoded] = useState(""); + const [encoded, setEncoded] = useState(""); + + const encode = () => { + try { + const encoded64 = btoa(decoded); + setEncoded(encoded64); + setDecoded(""); + toast.success("encoded successfully"); + } catch (error: unknown) { + if (error instanceof Error) { + toast.error(error.message); + } else { + toast.error("encoding failed"); + } + } + }; + + const decode = () => { + try { + const decoded64 = atob(encoded); + setDecoded(decoded64); + setEncoded(""); + toast.success("decoded successfully"); + } catch (error: unknown) { + if (error instanceof Error) { + toast.error(error.message); + } else { + toast.error("decoding failed"); + } + } + }; + + return ( +
+