mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-02-05 01:38:56 -05:00
Add disable home page option
This commit is contained in:
parent
2cdd802422
commit
c02e9c4efb
10 changed files with 46 additions and 43 deletions
|
@ -2,3 +2,4 @@ APPWRITE_FUNCTION_API_KEY=""
|
||||||
PUBLIC_APPWRITE_HOST="http://localhost/v1"
|
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_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"
|
|
@ -10,3 +10,4 @@ services:
|
||||||
- PUBLIC_APPWRITE_HOST=${PUBLIC_APPWRITE_HOST}
|
- PUBLIC_APPWRITE_HOST=${PUBLIC_APPWRITE_HOST}
|
||||||
- PUBLIC_MAX_FILE_SIZE=${PUBLIC_MAX_FILE_SIZE}
|
- 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}
|
|
@ -5,7 +5,8 @@ const withPWA = require("next-pwa");
|
||||||
const nextConfig = withPWA({
|
const nextConfig = withPWA({
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
pwa: {
|
pwa: {
|
||||||
dest: "public"
|
dest: "public",
|
||||||
|
disable: process.env.NODE_ENV == "development"
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint",
|
"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 ."
|
"deploy": "docker buildx build -t stonith404/pingvin-share --platform linux/amd64,linux/arm64 --push ."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -67,11 +67,11 @@ const Header = () => {
|
||||||
const items = links.map((link) => {
|
const items = links.map((link) => {
|
||||||
if (link) {
|
if (link) {
|
||||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
if (window.location.pathname == link.link) {
|
// if (window.location.pathname == link.link) {
|
||||||
setActive(link.link);
|
// setActive(link.link);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
return (
|
return (
|
||||||
<NextLink
|
<NextLink
|
||||||
key={link.label}
|
key={link.label}
|
||||||
|
|
|
@ -19,28 +19,31 @@ import authUtil, { IsSignedInContext } from "../utils/auth.util";
|
||||||
import configUtil, { ConfigContext } from "../utils/config.util";
|
import configUtil, { ConfigContext } from "../utils/config.util";
|
||||||
import { GlobalLoadingContext } from "../utils/loading.util";
|
import { GlobalLoadingContext } from "../utils/loading.util";
|
||||||
|
|
||||||
function App(props: AppProps & { colorScheme: ColorScheme }) {
|
let environmentVariables: any = {};
|
||||||
const { Component, pageProps } = props;
|
|
||||||
|
|
||||||
|
function App(
|
||||||
|
props: AppProps & { colorScheme: ColorScheme; environmentVariables: any }
|
||||||
|
) {
|
||||||
|
const { Component, pageProps } = props;
|
||||||
const [colorScheme, setColorScheme] = useState<ColorScheme>(
|
const [colorScheme, setColorScheme] = useState<ColorScheme>(
|
||||||
props.colorScheme
|
props.colorScheme
|
||||||
);
|
);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [isSignedIn, setIsSignedIn] = useState(false);
|
const [isSignedIn, setIsSignedIn] = useState(false);
|
||||||
const [environmentVariables, setEnvironmentVariables] = useState<any>({});
|
|
||||||
|
if (Object.keys(props.environmentVariables).length != 0) {
|
||||||
|
environmentVariables = props.environmentVariables;
|
||||||
|
}
|
||||||
|
|
||||||
const getInitalData = async () => {
|
const getInitalData = async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const environmentVariables = await configUtil.getGonfig();
|
|
||||||
aw.setEndpoint(environmentVariables.APPWRITE_HOST);
|
aw.setEndpoint(environmentVariables.APPWRITE_HOST);
|
||||||
setEnvironmentVariables(environmentVariables);
|
|
||||||
setIsSignedIn(await authUtil.isSignedIn());
|
setIsSignedIn(await authUtil.isSignedIn());
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getInitalData();
|
getInitalData();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MantineProvider withGlobalStyles withNormalizeCSS theme={globalStyle}>
|
<MantineProvider withGlobalStyles withNormalizeCSS theme={globalStyle}>
|
||||||
<ThemeProvider colorScheme={colorScheme} setColorScheme={setColorScheme}>
|
<ThemeProvider colorScheme={colorScheme} setColorScheme={setColorScheme}>
|
||||||
|
@ -70,6 +73,9 @@ function App(props: AppProps & { colorScheme: ColorScheme }) {
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|
||||||
App.getInitialProps = ({ ctx }: { ctx: GetServerSidePropsContext }) => ({
|
App.getInitialProps = ({ ctx }: { ctx: GetServerSidePropsContext }) => {
|
||||||
colorScheme: getCookie("mantine-color-scheme", ctx) || "light",
|
return {
|
||||||
});
|
environmentVariables: configUtil.getGonfig(),
|
||||||
|
colorScheme: getCookie("mantine-color-scheme", ctx) || "light",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -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;
|
|
|
@ -15,6 +15,7 @@ import { Check } from "tabler-icons-react";
|
||||||
import { IsSignedInContext } from "../utils/auth.util";
|
import { IsSignedInContext } from "../utils/auth.util";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Meta from "../components/Meta";
|
import Meta from "../components/Meta";
|
||||||
|
import { useConfig } from "../utils/config.util";
|
||||||
const useStyles = createStyles((theme) => ({
|
const useStyles = createStyles((theme) => ({
|
||||||
inner: {
|
inner: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
|
@ -69,10 +70,13 @@ const useStyles = createStyles((theme) => ({
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const isSignedIn = useContext(IsSignedInContext);
|
const isSignedIn = useContext(IsSignedInContext);
|
||||||
|
const config = useConfig();
|
||||||
const { classes } = useStyles();
|
const { classes } = useStyles();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
if (isSignedIn) {
|
if (isSignedIn) {
|
||||||
router.replace("/upload");
|
router.replace("/upload");
|
||||||
|
} else if (config.PUBLIC_DISABLE_HOME_PAGE) {
|
||||||
|
router.replace("/auth/signIn");
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -10,7 +10,7 @@ const isSignedIn = async () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const IsSignedInContext = createContext(false);
|
export const IsSignedInContext = createContext(true);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
isSignedIn,
|
isSignedIn,
|
||||||
|
|
|
@ -1,12 +1,24 @@
|
||||||
import axios from "axios";
|
|
||||||
import { createContext, useContext } from "react";
|
import { createContext, useContext } from "react";
|
||||||
|
|
||||||
export const ConfigContext = createContext<any>({});
|
export const ConfigContext = createContext<any>({});
|
||||||
|
|
||||||
export const useConfig = () => useContext(ConfigContext);
|
export const useConfig = () => useContext(ConfigContext);
|
||||||
|
|
||||||
const getGonfig = async() => {
|
const getGonfig = () => {
|
||||||
return (await axios.get("/api/config")).data;
|
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 };
|
export default { getGonfig };
|
||||||
|
|
Loading…
Add table
Reference in a new issue