refactor:Improve Document Preview page
This commit is contained in:
parent
48047cf288
commit
2fa5384e96
3 changed files with 1060 additions and 11 deletions
1035
presentation-export/index.cjs
Normal file
1035
presentation-export/index.cjs
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState, useRef, useMemo } from "react";
|
||||
import { Fragment, useEffect, useState, useRef, useMemo } from "react";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { OverlayLoader } from "@/components/ui/overlay-loader";
|
||||
import { PresentationGenerationApi } from "../../services/api/presentation-generation";
|
||||
|
|
@ -23,7 +23,6 @@ import { useRouter, usePathname } from "next/navigation";
|
|||
import { RootState } from "@/store/store";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { toast } from "sonner";
|
||||
import MarkdownRenderer from "./MarkdownRenderer";
|
||||
import { getIconFromFile } from "../../utils/others";
|
||||
import { ChevronRight, PanelRightOpen, X } from "lucide-react";
|
||||
import ToolTip from "@/components/ToolTip";
|
||||
|
|
@ -202,6 +201,23 @@ const DocumentsPreviewPage: React.FC = () => {
|
|||
|
||||
if (!isDocument) return null;
|
||||
|
||||
const renderParsedContent = (content: string) => {
|
||||
const normalizedContent = content.replace(/\r\n/g, "\n");
|
||||
return normalizedContent.split("\n\n").map((paragraph, paragraphIndex) => {
|
||||
const lines = paragraph.split("\n");
|
||||
return (
|
||||
<p key={paragraphIndex} className="mb-4">
|
||||
{lines.map((line, lineIndex) => (
|
||||
<Fragment key={`${paragraphIndex}-${lineIndex}`}>
|
||||
{line}
|
||||
{lineIndex < lines.length - 1 && <br />}
|
||||
</Fragment>
|
||||
))}
|
||||
</p>
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="h-full mr-4">
|
||||
<div className="overflow-y-auto custom_scrollbar h-full">
|
||||
|
|
@ -210,9 +226,7 @@ const DocumentsPreviewPage: React.FC = () => {
|
|||
{downloadingDocuments.includes(selectedDocument) ? (
|
||||
<Skeleton className="w-full h-full" />
|
||||
) : (
|
||||
<MarkdownRenderer
|
||||
content={textContents[selectedDocument] || ""}
|
||||
/>
|
||||
<div>{renderParsedContent(textContents[selectedDocument] || "")}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ export const getIconFromFile = (file: string): string => {
|
|||
} else if (file_ext == "docx") {
|
||||
return "/report.png";
|
||||
} else if (file_ext == "pptx") {
|
||||
return "/ppt.svg";
|
||||
return "/pptx.svg";
|
||||
}
|
||||
return "/report.png";
|
||||
};
|
||||
|
|
@ -63,10 +63,10 @@ export function sanitizeFilename(input: string | null | undefined, replacement =
|
|||
let sanitized = (input ?? '').toString();
|
||||
// Remove any null bytes first
|
||||
sanitized = sanitized.replace(/\0/g, '');
|
||||
|
||||
|
||||
// Remove or replace path traversal sequences
|
||||
sanitized = sanitized.replace(/\.\./g, replacement);
|
||||
|
||||
|
||||
// Regular filename sanitization (but preserve forward slashes for paths)
|
||||
const illegalRe = /[\?<>\\:\*\|"]/g; // Removed / from illegal characters
|
||||
const controlRe = /[\x00-\x1f\x80-\x9f]/g;
|
||||
|
|
@ -85,10 +85,10 @@ export function sanitizeFilename(input: string | null | undefined, replacement =
|
|||
.replace(reservedRe, replacement)
|
||||
.replace(windowsReservedRe, replacement)
|
||||
.replace(windowsTrailingRe, replacement);
|
||||
|
||||
|
||||
// Remove any remaining path traversal attempts in individual segments
|
||||
cleanSegment = cleanSegment.replace(/\.\./g, replacement);
|
||||
|
||||
|
||||
return cleanSegment;
|
||||
});
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ export function sanitizeFilename(input: string | null | undefined, replacement =
|
|||
|
||||
// Remove any remaining path traversal attempts after other replacements
|
||||
sanitized = sanitized.replace(/\.\./g, replacement);
|
||||
|
||||
|
||||
// Normalize multiple consecutive slashes to single slash
|
||||
sanitized = sanitized.replace(/\/+/g, '/');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue