From 4919f028c884a041da7ff098abb02389b4eac598 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Tue, 18 Apr 2023 03:02:17 +0800 Subject: ✨add envshare docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/unseal/page.tsx | 159 ---------------------------------------------------- 1 file changed, 159 deletions(-) delete mode 100644 app/unseal/page.tsx (limited to 'app/unseal') diff --git a/app/unseal/page.tsx b/app/unseal/page.tsx deleted file mode 100644 index 0b63e6b..0000000 --- a/app/unseal/page.tsx +++ /dev/null @@ -1,159 +0,0 @@ -"use client"; -import React, { Fragment, useState, useEffect } from "react"; -import { ClipboardDocumentCheckIcon, ClipboardDocumentIcon, Cog6ToothIcon } from "@heroicons/react/24/outline"; - -import { Title } from "@components/title"; - -import { decodeCompositeKey } from "pkg/encoding"; -import { decrypt } from "pkg/encryption"; -import Link from "next/link"; -import { ErrorMessage } from "@components/error"; - -export default function Unseal() { - const [compositeKey, setCompositeKey] = useState(""); - useEffect(() => { - if (typeof window !== "undefined") { - setCompositeKey(window.location.hash.replace(/^#/, "")); - } - }, []); - - const [text, setText] = useState(null); - const [loading, setLoading] = useState(false); - const [remainingReads, setRemainingReads] = useState(null); - const [error, setError] = useState(null); - const [copied, setCopied] = useState(false); - - const onSubmit = async () => { - try { - setError(null); - setText(null); - setLoading(true); - - if (!compositeKey) { - throw new Error("No id provided"); - } - - const { id, encryptionKey, version } = decodeCompositeKey(compositeKey); - const res = await fetch(`/api/v1/load?id=${id}`); - if (!res.ok) { - throw new Error(await res.text()); - } - const json = (await res.json()) as { - iv: string; - encrypted: string; - remainingReads: number | null; - }; - setRemainingReads(json.remainingReads); - - const decrypted = await decrypt(json.encrypted, encryptionKey, json.iv, version); - - setText(decrypted); - } catch (e) { - console.error(e); - setError((e as Error).message); - } finally { - setLoading(false); - } - }; - - return ( -
- {error ? : null} - {text ? ( -
- {remainingReads !== null ? ( -
- {remainingReads > 0 ? ( -

- This document can be read {remainingReads} more times. -

- ) : ( -

- This was the last time this document could be read. It was deleted from storage. -

- )} -
- ) : null} -
-            
- -
-
-                  {text}
-                
-
-
-
- -
- - Share another - - -
-
- ) : ( -
{ - e.preventDefault(); - onSubmit(); - }} - > - Decrypt a document - -
- - setCompositeKey(e.target.value)} - /> -
- - -
- )} -
- ); -} -- cgit v1.2.3-70-g09d2