From 050614a342924d45544a61db05ba66626dc66f64 Mon Sep 17 00:00:00 2001 From: Aswanth Vc Date: Fri, 21 Jun 2024 22:18:49 +0530 Subject: [PATCH 1/8] fix : Updated file upload limit (50 -> 30MB) --- app/main.tsx | 4 ++-- app/page.tsx | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/main.tsx b/app/main.tsx index bbdcc06..456b68c 100644 --- a/app/main.tsx +++ b/app/main.tsx @@ -104,11 +104,11 @@ export default function MainContainer({ setLoader!({ text: "Loading...", visible: true }); mainDragEnd(); if (event.dataTransfer.files && event.dataTransfer.files.length > 0) { - if (event.dataTransfer.files[0].size > (50 * 1024 * 1024)) { + if (event.dataTransfer.files[0].size > (30 * 1024 * 1024)) { setLoader!({ text: "", visible: false }); showPopup( setPopup!, - "File size is too large (Maximum 50 MB)", + "File size is too large (Maximum 30 MB)", "bi bi-x-circle", 2000 ); diff --git a/app/page.tsx b/app/page.tsx index ae9b133..ae9ece0 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -5,6 +5,7 @@ import MainContainer from "./main"; import { FileContext } from "@/context/FileContext"; import { useRouter } from "next/navigation"; import { LoaderContext } from "@/context/LoaderContext"; +import { PopupContext, showPopup } from "@/context/PopupContext"; export default function Home() { useEffect(() => { @@ -12,6 +13,7 @@ export default function Home() { }, []); const router = useRouter(); const { setLoader } = useContext(LoaderContext); + const { setPopup } = useContext(PopupContext); const fileContext = useContext(FileContext); const filePicRef = useRef(null); return ( @@ -53,6 +55,16 @@ export default function Home() { onChange={(e) => { const file = e.target.files?.[0]; if (file) { + if (file.size > 30 * 1024 * 1024) { + setLoader!({ text: "", visible: false }); + showPopup( + setPopup!, + "File size is too large (Maximum 30 MB)", + "bi bi-x-circle", + 2000 + ); + return; + } setLoader!({ text: "", visible: true }); fileContext.setFile!(file); router.push("/share"); From 01f59acd59ab1a0eb67a8d1a15118cd9b84f1961 Mon Sep 17 00:00:00 2001 From: Aswanth Vc Date: Fri, 21 Jun 2024 22:23:02 +0530 Subject: [PATCH 2/8] fix : Updated download progress bar buffering. --- app/receive/page.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/receive/page.tsx b/app/receive/page.tsx index f6d0dc9..b192bd4 100644 --- a/app/receive/page.tsx +++ b/app/receive/page.tsx @@ -184,7 +184,6 @@ export default function Share() { } const total = parseInt(contentLength, 10); let loaded = 0; - setProgress({ buffering: false, percent: 0, total, loaded }); showPopup(setPopup!, "Downloading ...", "bi bi-download", 1000); const reader = response.body!.getReader(); const stream = new ReadableStream({ @@ -192,6 +191,12 @@ export default function Share() { function push() { reader.read().then(({ done, value }) => { if (done) { + setProgress({ + buffering: true, + percent: 100, + total, + loaded, + }); controller.close(); return; } @@ -214,7 +219,6 @@ export default function Share() { }) .then((response) => response.blob()) .then((blob) => { - setProgress({ ...progress, buffering: true }); const url = window.URL.createObjectURL(blob); const a = document.createElement("a"); a.style.display = "none"; From 797582e655c47291a9ef7d89991adea3e0ec309c Mon Sep 17 00:00:00 2001 From: Aswanth Vc Date: Sat, 22 Jun 2024 00:47:18 +0530 Subject: [PATCH 3/8] fix : Upload file withour content type --- app/share/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/share/page.tsx b/app/share/page.tsx index cb5e384..d4f4b23 100644 --- a/app/share/page.tsx +++ b/app/share/page.tsx @@ -58,7 +58,7 @@ export default function Share() { file_name: file.name, file_size: fileSize.toString(), uploaded_by: name, - content_type: file.type, + content_type: file.type == null || file.type.length <= 1 ? 'application/octet-stream' : file.type, usage_limit: usageCount.toString(), }), }); From 06546f6f40ada464012776f20c31db2ff568e762 Mon Sep 17 00:00:00 2001 From: Aswanth Vc Date: Sat, 22 Jun 2024 01:23:16 +0530 Subject: [PATCH 4/8] feat (main) : Now paste code work in all pages --- app/main.tsx | 17 +++++++++++++++-- app/receive/page.tsx | 21 +++++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/app/main.tsx b/app/main.tsx index 456b68c..4818c61 100644 --- a/app/main.tsx +++ b/app/main.tsx @@ -29,9 +29,22 @@ export default function MainContainer({ icon: "bi bi-info", }); const [statusLoaded, setStatusLoaded] = useState(false); - + useEffect(() => { console.log("Page loaded (MAIN)", process.env.NODE_ENV); + const handlePaste = (event: React.ClipboardEvent) => { + if (window.location.pathname.includes("receive")) return; + event.clipboardData?.items[0].getAsString((text) => { + navigator.clipboard.readText().then((text) => { + console.log(text); + if (text[1] == "-") + text = text[0]+text.slice(2); + if (text.length > 8 || !/^[A-Z]\d{0,6}$/.test(text)) return; + router.push(`/receive/?code=${text}`); + }); + }); + }; + window.addEventListener("paste", handlePaste as any); document.body.style.setProperty("--x", "0px"); document.body.style.setProperty("--y", "0px"); document.body.style.setProperty( @@ -104,7 +117,7 @@ export default function MainContainer({ setLoader!({ text: "Loading...", visible: true }); mainDragEnd(); if (event.dataTransfer.files && event.dataTransfer.files.length > 0) { - if (event.dataTransfer.files[0].size > (30 * 1024 * 1024)) { + if (event.dataTransfer.files[0].size > 30 * 1024 * 1024) { setLoader!({ text: "", visible: false }); showPopup( setPopup!, diff --git a/app/receive/page.tsx b/app/receive/page.tsx index b192bd4..7996065 100644 --- a/app/receive/page.tsx +++ b/app/receive/page.tsx @@ -4,6 +4,7 @@ import styles from "./page.module.css"; import { LoaderContext } from "@/context/LoaderContext"; import Link from "next/link"; import { PopupContext, showPopup } from "@/context/PopupContext"; +import { useSearchParams, useRouter } from "next/navigation"; type ProgressType = { buffering: boolean; @@ -29,7 +30,7 @@ const progressBytes = (progress: ProgressType) => { }`; }; -export default function Share() { +export default function Receive() { const { setPopup } = useContext(PopupContext); const [fileIcon, setFileIcon] = useState("bi bi-filetype-"); const [fileSize, setFileSize] = useState("0MB"); @@ -38,6 +39,8 @@ export default function Share() { const { setLoader } = useContext(LoaderContext); const [fileInfo, setFileInfo] = useState(null); const [downloading, setDownloading] = useState(false); + const searchParams = useSearchParams(); + const router = useRouter(); const [progress, setProgress] = useState({ buffering: false, percent: 0, @@ -54,7 +57,20 @@ export default function Share() { useEffect(() => { console.log("Page loaded (RECEIVE)"); inputRef.current?.focus(); - setCode(""); + if (searchParams.has("code")) { + if (searchParams.get("code")!.length != 7 || !/^[A-Z]\d{0,6}$/.test(searchParams.get("code")!)) { + showPopup(setPopup!, "Invalid Code", "bi bi-exclamation-triangle"); + router.push("/"); + return; + } + setCode(searchParams.get("code")!); + for (var i = 0; i < 7; i++) { + document + .getElementsByClassName(styles.codeChar) + [i != 0 ? i + 1 : i].classList.remove(styles.inactive); + } + viewFileInfo(); + } setLoader!({ text: "", visible: false }); }, [setLoader]); @@ -219,6 +235,7 @@ export default function Share() { }) .then((response) => response.blob()) .then((blob) => { + setProgress({ ...progress, buffering: true }); const url = window.URL.createObjectURL(blob); const a = document.createElement("a"); a.style.display = "none"; From 5073191c90e0ca4ed2b311d7a351cae7e2f74c0d Mon Sep 17 00:00:00 2001 From: Aswanth Vc Date: Sat, 22 Jun 2024 01:33:23 +0530 Subject: [PATCH 5/8] fix: Check if clipboard permission is given --- app/share/page.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/share/page.tsx b/app/share/page.tsx index d4f4b23..ef21d5f 100644 --- a/app/share/page.tsx +++ b/app/share/page.tsx @@ -176,6 +176,10 @@ export default function Share() {

Your Code

{ + if(!navigator.clipboard) { + showPopup(setPopup!, "Failed to copy code", "bi bi-x-circle", 2000); + return; + } navigator.clipboard.writeText(code); setCopied(true); showPopup(setPopup!, "Copied", "bi bi-check-circle", 2000); From f728f812e56365bc009253fac8efeaa613d3743c Mon Sep 17 00:00:00 2001 From: Aswanth Vc Date: Sat, 22 Jun 2024 01:40:56 +0530 Subject: [PATCH 6/8] fix : Minor responsive issue fix --- app/main.module.css | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/main.module.css b/app/main.module.css index 9403894..1eac4e4 100644 --- a/app/main.module.css +++ b/app/main.module.css @@ -8,6 +8,7 @@ align-items: center; justify-content: start; max-width: 70%; + width: fit-content; height: auto; padding: 1rem; bottom: 0; @@ -43,6 +44,7 @@ font-weight: 600; color: #222; background: transparent; + word-break: break-all; } } .loader { @@ -224,7 +226,8 @@ @media only screen and (max-width: 728px) { .main { .popup { - max-width: calc(100% - 3rem); + max-width: calc(100% - 1rem); + width: calc(100% - 3rem); } .bg { background-size: 190%; From d264550f2365314006c138f113b98d1ee3f714d5 Mon Sep 17 00:00:00 2001 From: Aswanth Vc Date: Sat, 22 Jun 2024 01:59:32 +0530 Subject: [PATCH 7/8] feat : Press 'r' to go to receive, esc to home --- app/main.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/main.tsx b/app/main.tsx index 4818c61..135cbdb 100644 --- a/app/main.tsx +++ b/app/main.tsx @@ -30,6 +30,18 @@ export default function MainContainer({ }); const [statusLoaded, setStatusLoaded] = useState(false); + useEffect(() => { + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key == "Escape") { + router.push("/"); + } else if (!window.location.pathname.includes("receive") && !window.location.pathname.includes("share")) { + if (event.key == "r") + router.push("/receive"); + } + } + window.addEventListener("keydown", handleKeyDown); +}, []); + useEffect(() => { console.log("Page loaded (MAIN)", process.env.NODE_ENV); const handlePaste = (event: React.ClipboardEvent) => { @@ -37,8 +49,7 @@ export default function MainContainer({ event.clipboardData?.items[0].getAsString((text) => { navigator.clipboard.readText().then((text) => { console.log(text); - if (text[1] == "-") - text = text[0]+text.slice(2); + if (text[1] == "-") text = text[0] + text.slice(2); if (text.length > 8 || !/^[A-Z]\d{0,6}$/.test(text)) return; router.push(`/receive/?code=${text}`); }); From 1482777ca76fc1fb634a5f57fdb5644355587099 Mon Sep 17 00:00:00 2001 From: Aswanth Vc Date: Sat, 22 Jun 2024 03:44:56 +0530 Subject: [PATCH 8/8] fix(receive) : Disable download button if already downloading --- app/receive/page.module.css | 5 +++++ app/receive/page.tsx | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/receive/page.module.css b/app/receive/page.module.css index d8aee56..23526e0 100644 --- a/app/receive/page.module.css +++ b/app/receive/page.module.css @@ -258,6 +258,11 @@ &:hover { background: #66a63f; } + + &.inactive { + background: #636363; + cursor: not-allowed; + } } } } diff --git a/app/receive/page.tsx b/app/receive/page.tsx index 7996065..0bfc679 100644 --- a/app/receive/page.tsx +++ b/app/receive/page.tsx @@ -58,7 +58,10 @@ export default function Receive() { console.log("Page loaded (RECEIVE)"); inputRef.current?.focus(); if (searchParams.has("code")) { - if (searchParams.get("code")!.length != 7 || !/^[A-Z]\d{0,6}$/.test(searchParams.get("code")!)) { + if ( + searchParams.get("code")!.length != 7 || + !/^[A-Z]\d{0,6}$/.test(searchParams.get("code")!) + ) { showPopup(setPopup!, "Invalid Code", "bi bi-exclamation-triangle"); router.push("/"); return; @@ -182,6 +185,9 @@ export default function Receive() { }; const downloadFile = () => { + if (downloading) { + return; + } if (fileInfo == null) { return; } @@ -352,7 +358,7 @@ export default function Receive() { )}
-