🐞 fix: Length is undefined when changing route

This commit is contained in:
mbaharip
2023-09-11 05:50:16 +07:00
parent 668f52939a
commit bdf1d02af1
2 changed files with 5 additions and 11 deletions
-6
View File
@@ -1,6 +0,0 @@
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
export function middleware(request: NextRequest) {
return NextResponse.next();
}
+5 -5
View File
@@ -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 (
<LoaderLayout
seo={{
title: props.mappedEncryptedPath[props.mappedEncryptedPath.length - 1].name,
title: props.mappedEncryptedPath[(props.mappedEncryptedPath.length ?? 1) - 1].name,
}}
>
{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}
/>
) : (
<ExplorerLayout
@@ -165,7 +165,7 @@ export default function FilePathPage(props: FilePathPageProps) {
readmeFile={readmeFile}
isProtected={false}
isFileProtected={isFileProtected}
encryptedId={props.mappedEncryptedPath[props.mappedEncryptedPath.length - 1].id}
encryptedId={props.mappedEncryptedPath[(props.mappedEncryptedPath.length ?? 1) - 1].id}
/>
)}
</>