1
1
import { withPageAuthRequired } from "@auth0/nextjs-auth0/dist/frontend" ;
2
- import { Container } from "@mui/material" ;
2
+ import type { Theme } from "@mui/material" ;
3
+ import { Container , useMediaQuery } from "@mui/material" ;
3
4
import type { GetServerSideProps } from "next" ;
4
5
import NextError from "next/error" ;
5
6
import { useRouter } from "next/router" ;
6
7
7
8
import { PlaintextViewer } from "../../components/PlaintextViewer" ;
8
9
import { API_ROUTES } from "../../constants/routes" ;
9
10
import { createErrorProps } from "../../utils/api/serverSidePropsError" ;
11
+ import { pathFromQuery } from "../../utils/paths" ;
10
12
import type { NotSuccessful , Successful } from "../../utils/plaintextViewerSSR" ;
11
13
import { plaintextViewerSSR } from "../../utils/plaintextViewerSSR" ;
12
14
@@ -19,13 +21,11 @@ export const getServerSideProps: GetServerSideProps<FileProps> = async ({ req, r
19
21
let { path } = query ;
20
22
const { file, project } = query ;
21
23
22
- if ( typeof path !== "string" || typeof file !== "string" || typeof project !== "string" ) {
23
- return createErrorProps ( res , 500 , "File or path are not valid" ) ;
24
+ if ( path === undefined || typeof file !== "string" || typeof project !== "string" ) {
25
+ return createErrorProps ( res , 500 , "File, path or project are not valid" ) ;
24
26
}
25
27
26
- if ( path === "" ) {
27
- path = "/" ;
28
- }
28
+ path = pathFromQuery ( path ) ;
29
29
30
30
let compressed = false ;
31
31
if ( file . endsWith ( ".gz" ) || file . endsWith ( ".gzip" ) ) {
@@ -38,6 +38,8 @@ export const getServerSideProps: GetServerSideProps<FileProps> = async ({ req, r
38
38
} ;
39
39
40
40
export const File = ( props : FileProps ) => {
41
+ const biggerThanSm = useMediaQuery < Theme > ( ( theme ) => theme . breakpoints . up ( "sm" ) ) ;
42
+
41
43
const { query } = useRouter ( ) ;
42
44
43
45
const { file, project, path } = query ;
@@ -51,7 +53,7 @@ export const File = (props: FileProps) => {
51
53
52
54
if ( isSuccessful ( props ) ) {
53
55
return (
54
- < Container maxWidth = "xl" >
56
+ < Container disableGutters = { ! biggerThanSm } maxWidth = "xl" >
55
57
< PlaintextViewer { ...props } compressed = { compressed } title = { title } />
56
58
</ Container >
57
59
) ;
0 commit comments