-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a2b7b1
commit 91a6b3f
Showing
10 changed files
with
188 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Center, Loader, Stack } from "@mantine/core"; | ||
|
||
const CenterLoader = () => { | ||
return ( | ||
<Center style={{ height: "70vh" }}> | ||
<Stack align="center" spacing={10}> | ||
<Loader /> | ||
</Stack> | ||
</Center> | ||
); | ||
}; | ||
|
||
export default CenterLoader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { Center, Stack, Text, Title } from "@mantine/core"; | ||
import { GetServerSidePropsContext } from "next"; | ||
import { useState } from "react"; | ||
|
||
export function getServerSideProps(context: GetServerSidePropsContext) { | ||
const { shareId, fileId } = context.params!; | ||
|
||
const mimeType = context.query.type as string; | ||
|
||
return { | ||
props: { shareId, fileId, mimeType }, | ||
}; | ||
} | ||
|
||
const UnSupportedFile = () => { | ||
return ( | ||
<Center style={{ height: "70vh" }}> | ||
<Stack align="center" spacing={10}> | ||
<Title order={3}>Preview not supported</Title> | ||
<Text> | ||
A preview for thise file type is unsupported. Please download the file | ||
to view it. | ||
</Text> | ||
</Stack> | ||
</Center> | ||
); | ||
}; | ||
|
||
const FilePreview = ({ | ||
shareId, | ||
fileId, | ||
mimeType, | ||
}: { | ||
shareId: string; | ||
fileId: string; | ||
mimeType: string; | ||
}) => { | ||
const [isNotSupported, setIsNotSupported] = useState(false); | ||
|
||
if (isNotSupported) return <UnSupportedFile />; | ||
|
||
if (mimeType == "application/pdf") { | ||
window.location.href = `/api/shares/${shareId}/files/${fileId}?download=false`; | ||
return null; | ||
} else if (mimeType.startsWith("video/")) { | ||
return ( | ||
<video | ||
width="100%" | ||
controls | ||
onError={() => { | ||
setIsNotSupported(true); | ||
}} | ||
> | ||
<source src={`/api/shares/${shareId}/files/${fileId}?download=false`} /> | ||
</video> | ||
); | ||
} else if (mimeType.startsWith("image/")) { | ||
return ( | ||
// eslint-disable-next-line @next/next/no-img-element | ||
<img | ||
onError={() => { | ||
setIsNotSupported(true); | ||
}} | ||
src={`/api/shares/${shareId}/files/${fileId}?download=false`} | ||
alt={`${fileId}_preview`} | ||
width="100%" | ||
/> | ||
); | ||
} else if (mimeType.startsWith("audio/")) { | ||
return ( | ||
<Center style={{ height: "70vh" }}> | ||
<Stack align="center" spacing={10} style={{ width: "100%" }}> | ||
<audio | ||
controls | ||
style={{ width: "100%" }} | ||
onError={() => { | ||
setIsNotSupported(true); | ||
}} | ||
> | ||
<source | ||
src={`/api/shares/${shareId}/files/${fileId}?download=false`} | ||
/> | ||
</audio> | ||
</Stack> | ||
</Center> | ||
); | ||
} else { | ||
return <UnSupportedFile />; | ||
} | ||
}; | ||
|
||
export default FilePreview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
export type FileUpload = File & { uploadingProgress: number }; | ||
|
||
export type FileUploadResponse = { id: string; name: string }; | ||
|
||
export type FileMetaData = { | ||
id: string; | ||
name: string; | ||
size: string; | ||
}; |