Update preview formats and handling

This commit is contained in:
mbaharip
2024-04-07 12:02:49 +07:00
parent 715de6b70d
commit efccdc9ba0
4 changed files with 16 additions and 7 deletions
+8
View File
@@ -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}
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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?)");
}
}}
/>
+6 -5
View File
@@ -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"];
}