1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-06-30 14:40:10 +02:00

Add disable home page option

This commit is contained in:
Elias Schneider 2022-05-02 22:42:27 +02:00
parent 2cdd802422
commit c02e9c4efb
No known key found for this signature in database
GPG Key ID: D5EC1C72D93244FD
10 changed files with 46 additions and 43 deletions

View File

@ -1,4 +1,5 @@
APPWRITE_FUNCTION_API_KEY=""
PUBLIC_APPWRITE_HOST="http://localhost/v1"
PUBLIC_MAX_FILE_SIZE="300000000" # Note: Must be the same as in the _APP_STORAGE_LIMIT in the Appwrite env file
PUBLIC_DISABLE_REGISTRATION="true" # Note: In the Appwrite console you have to change your user limit to 0 if false and else to 1
PUBLIC_DISABLE_REGISTRATION="true" # Note: In the Appwrite console you have to change your user limit to 0 if false and else to 1
PUBLIC_DISABLE_HOME_PAGE="false"

View File

@ -9,4 +9,5 @@ services:
- APPWRITE_FUNCTION_API_KEY=${APPWRITE_FUNCTION_API_KEY}
- PUBLIC_APPWRITE_HOST=${PUBLIC_APPWRITE_HOST}
- PUBLIC_MAX_FILE_SIZE=${PUBLIC_MAX_FILE_SIZE}
- PUBLIC_DISABLE_REGISTRATION=${PUBLIC_DISABLE_REGISTRATION}
- PUBLIC_DISABLE_REGISTRATION=${PUBLIC_DISABLE_REGISTRATION}
- PUBLIC_DISABLE_HOME_PAGE=${PUBLIC_DISABLE_HOME_PAGE}

View File

@ -5,7 +5,8 @@ const withPWA = require("next-pwa");
const nextConfig = withPWA({
reactStrictMode: true,
pwa: {
dest: "public"
dest: "public",
disable: process.env.NODE_ENV == "development"
},
})

View File

@ -7,7 +7,6 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"init:appwrite": "cd .setup && npm install && npx ts-node index.ts",
"deploy": "docker buildx build -t stonith404/pingvin-share --platform linux/amd64,linux/arm64 --push ."
},
"dependencies": {

View File

@ -67,11 +67,11 @@ const Header = () => {
const items = links.map((link) => {
if (link) {
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
if (window.location.pathname == link.link) {
setActive(link.link);
}
});
// useEffect(() => {
// if (window.location.pathname == link.link) {
// setActive(link.link);
// }
// });
return (
<NextLink
key={link.label}

View File

@ -19,28 +19,31 @@ import authUtil, { IsSignedInContext } from "../utils/auth.util";
import configUtil, { ConfigContext } from "../utils/config.util";
import { GlobalLoadingContext } from "../utils/loading.util";
function App(props: AppProps & { colorScheme: ColorScheme }) {
const { Component, pageProps } = props;
let environmentVariables: any = {};
function App(
props: AppProps & { colorScheme: ColorScheme; environmentVariables: any }
) {
const { Component, pageProps } = props;
const [colorScheme, setColorScheme] = useState<ColorScheme>(
props.colorScheme
);
const [isLoading, setIsLoading] = useState(true);
const [isSignedIn, setIsSignedIn] = useState(false);
const [environmentVariables, setEnvironmentVariables] = useState<any>({});
if (Object.keys(props.environmentVariables).length != 0) {
environmentVariables = props.environmentVariables;
}
const getInitalData = async () => {
setIsLoading(true);
const environmentVariables = await configUtil.getGonfig();
aw.setEndpoint(environmentVariables.APPWRITE_HOST);
setEnvironmentVariables(environmentVariables);
setIsSignedIn(await authUtil.isSignedIn());
setIsLoading(false);
};
useEffect(() => {
getInitalData();
}, []);
return (
<MantineProvider withGlobalStyles withNormalizeCSS theme={globalStyle}>
<ThemeProvider colorScheme={colorScheme} setColorScheme={setColorScheme}>
@ -70,6 +73,9 @@ function App(props: AppProps & { colorScheme: ColorScheme }) {
export default App;
App.getInitialProps = ({ ctx }: { ctx: GetServerSidePropsContext }) => ({
colorScheme: getCookie("mantine-color-scheme", ctx) || "light",
});
App.getInitialProps = ({ ctx }: { ctx: GetServerSidePropsContext }) => {
return {
environmentVariables: configUtil.getGonfig(),
colorScheme: getCookie("mantine-color-scheme", ctx) || "light",
};
};

View File

@ -1,21 +0,0 @@
import type { NextApiRequest, NextApiResponse } from "next";
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
let publicEnvironmentVariables: any = {};
Object.entries(process.env).forEach(([key, value]: any) => {
value as string | number | boolean;
if (key.startsWith("PUBLIC") && value) {
key = key.replace("PUBLIC_", "");
if (value == "false" || value == "true") {
value = JSON.parse(value);
} else if (!isNaN(Number(value))) {
value = parseInt(value as string);
}
publicEnvironmentVariables[key] = value;
}
});
res.setHeader("cache-control", "max-age=100");
res.status(200).json(publicEnvironmentVariables);
};
export default handler;

View File

@ -15,6 +15,7 @@ import { Check } from "tabler-icons-react";
import { IsSignedInContext } from "../utils/auth.util";
import Image from "next/image";
import Meta from "../components/Meta";
import { useConfig } from "../utils/config.util";
const useStyles = createStyles((theme) => ({
inner: {
display: "flex",
@ -69,10 +70,13 @@ const useStyles = createStyles((theme) => ({
export default function Home() {
const isSignedIn = useContext(IsSignedInContext);
const config = useConfig();
const { classes } = useStyles();
const router = useRouter();
if (isSignedIn) {
router.replace("/upload");
} else if (config.PUBLIC_DISABLE_HOME_PAGE) {
router.replace("/auth/signIn");
} else {
return (
<>

View File

@ -10,7 +10,7 @@ const isSignedIn = async () => {
}
};
export const IsSignedInContext = createContext(false);
export const IsSignedInContext = createContext(true);
export default {
isSignedIn,

View File

@ -1,12 +1,24 @@
import axios from "axios";
import { createContext, useContext } from "react";
export const ConfigContext = createContext<any>({});
export const useConfig = () => useContext(ConfigContext);
const getGonfig = async() => {
return (await axios.get("/api/config")).data;
const getGonfig = () => {
let publicEnvironmentVariables: any = {};
Object.entries(process.env).forEach(([key, value]: any) => {
value as string | number | boolean;
if (key.startsWith("PUBLIC") && value) {
key = key.replace("PUBLIC_", "");
if (value == "false" || value == "true") {
value = JSON.parse(value);
} else if (!isNaN(Number(value))) {
value = parseInt(value as string);
}
publicEnvironmentVariables[key] = value;
}
});
return publicEnvironmentVariables;
};
export default { getGonfig };