From bdf1d02af197b38de637b3d82b7b088fd957598d Mon Sep 17 00:00:00 2001 From: mbaharip <62494292+mbahArip@users.noreply.github.com> Date: Mon, 11 Sep 2023 05:50:16 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20Length=20is=20undefined?= =?UTF-8?q?=20when=20changing=20route?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/middleware.ts | 6 ------ src/pages/[...path]/index.tsx | 10 +++++----- 2 files changed, 5 insertions(+), 11 deletions(-) delete mode 100644 src/middleware.ts diff --git a/src/middleware.ts b/src/middleware.ts deleted file mode 100644 index ba55683..0000000 --- a/src/middleware.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { NextRequest } from "next/server"; -import { NextResponse } from "next/server"; - -export function middleware(request: NextRequest) { - return NextResponse.next(); -} diff --git a/src/pages/[...path]/index.tsx b/src/pages/[...path]/index.tsx index 12c293d..fc48c60 100644 --- a/src/pages/[...path]/index.tsx +++ b/src/pages/[...path]/index.tsx @@ -43,7 +43,7 @@ export default function FilePathPage(props: FilePathPageProps) { useEffect(() => { setIsLoadingData(true); - const lastPathMimeType = props.mappedEncryptedPath[props.mappedEncryptedPath.length - 1].mimeType; + const lastPathMimeType = props.mappedEncryptedPath[(props.mappedEncryptedPath.length ?? 1) - 1].mimeType; let isLastPathFile = false; if (lastPathMimeType === "application/vnd.google-apps.folder") { isLastPathFile = false; @@ -73,7 +73,7 @@ export default function FilePathPage(props: FilePathPageProps) { Promise.all([_getPassword, _getData, _getReadme]) .then(async ([passwordData, fileData, readmeData]) => { // Check password - if (passwordData.data.data.length) { + if (passwordData.data.data && passwordData.data.data.length) { let isPathProtected = true; const savedPasswordCookie = document.cookie.split(";").find((cookie) => cookie.startsWith(`${Constant.cookies_SitePassword}=`)) ?? @@ -118,7 +118,7 @@ export default function FilePathPage(props: FilePathPageProps) { return ( {isLoadingData ? ( @@ -156,7 +156,7 @@ export default function FilePathPage(props: FilePathPageProps) { data={data} isProtected={false} isFileProtected={isFileProtected} - encryptedId={props.mappedEncryptedPath[props.mappedEncryptedPath.length - 1].id} + encryptedId={props.mappedEncryptedPath[(props.mappedEncryptedPath.length ?? 1) - 1].id} /> ) : ( )}