mirror of
https://github.com/Nezumi-2711/next-gdrive-index.git
synced 2026-09-22 20:01:36 +00:00
Update preview formats and handling
This commit is contained in:
@@ -16,6 +16,7 @@ type Props = {
|
||||
|
||||
export default function PreviewDoc({ file }: Props) {
|
||||
const [docSrc, setDocSrc] = useState<string>("");
|
||||
const [docBuffer, setDocBuffer] = useState<ArrayBuffer>();
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [error, setError] = useState<string>("");
|
||||
|
||||
@@ -27,6 +28,10 @@ export default function PreviewDoc({ file }: Props) {
|
||||
return;
|
||||
}
|
||||
const token = await CreateDownloadToken();
|
||||
const buffer = await fetch(
|
||||
`/api/download/${file.encryptedId}?token=${token}`,
|
||||
).then((res) => res.arrayBuffer());
|
||||
setDocBuffer(buffer);
|
||||
setDocSrc(`/api/download/${file.encryptedId}?token=${token}`);
|
||||
} catch (error) {
|
||||
const e = error as Error;
|
||||
@@ -69,6 +74,9 @@ export default function PreviewDoc({ file }: Props) {
|
||||
documents={[
|
||||
{
|
||||
uri: docSrc,
|
||||
fileData: docBuffer,
|
||||
fileName: file.name,
|
||||
fileType: file.mimeType,
|
||||
},
|
||||
]}
|
||||
pluginRenderers={DocViewerRenderers}
|
||||
|
||||
@@ -26,7 +26,7 @@ export default function PreviewUnknown() {
|
||||
size={32}
|
||||
className='animate-spin text-foreground'
|
||||
/>
|
||||
<p>Loading image...</p>
|
||||
<p>Loading content...</p>
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
|
||||
@@ -83,7 +83,7 @@ export default function PreviewVideo({ file }: Props) {
|
||||
if (error instanceof Error) {
|
||||
setError(error.message);
|
||||
} else {
|
||||
setError("An unknown error occurred");
|
||||
setError("Failed to load video. (Probably not supported?)");
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -17,10 +17,10 @@ const extensionsMap: Record<FileTypes, string[]> = {
|
||||
"mp4",
|
||||
"mkv",
|
||||
"webm",
|
||||
"avi",
|
||||
"mov",
|
||||
"flv",
|
||||
"wmv",
|
||||
// "avi",
|
||||
// "mov",
|
||||
// "flv",
|
||||
// "wmv",
|
||||
"mpg",
|
||||
"mpeg",
|
||||
"m4v",
|
||||
@@ -131,7 +131,8 @@ export function getFileType(
|
||||
export function getPreviewIcon(fileExtension: string, mimeType: string) {
|
||||
if (fileExtension === "ts") {
|
||||
if (mimeType.includes("video")) {
|
||||
return iconMap["video"];
|
||||
// .ts video are not supported
|
||||
return iconMap["unknown"];
|
||||
} else {
|
||||
return iconMap["code"];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user