1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-11-13 03:00:12 +01:00

use environment instead

This commit is contained in:
gluzzati 2024-03-22 00:35:55 +00:00
parent bff8c77164
commit 19cd21f50f
13 changed files with 44 additions and 27 deletions

View File

@ -20,11 +20,6 @@ const configVariables: ConfigVariables = {
defaultValue: "http://localhost:3000",
secret: false,
},
webroot: {
type: "string",
defaultValue: "",
secret: false,
},
showHomePage: {
type: "boolean",
defaultValue: "true",

View File

@ -13,6 +13,8 @@ import { FormattedMessage } from "react-intl";
import useConfig from "../../../hooks/config.hook";
import Logo from "../../Logo";
const webroot = process.env.WEBROOT || "";
const ConfigurationHeader = ({
isMobileNavBarOpened,
setIsMobileNavBarOpened,
@ -42,7 +44,7 @@ const ConfigurationHeader = ({
</Group>
</Link>
<MediaQuery smallerThan="sm" styles={{ display: "none" }}>
<Button variant="light" component={Link} href={config.get("general.webroot") + "/admin"}>
<Button variant="light" component={Link} href={webroot + "/admin"}>
<FormattedMessage id="common.button.go-back" />
</Button>
</MediaQuery>

View File

@ -15,6 +15,8 @@ import { TbAt, TbMail, TbShare, TbSocial, TbSquare } from "react-icons/tb";
import { FormattedMessage } from "react-intl";
import useConfig from "../../../hooks/config.hook";
const webroot = process.env.WEBROOT || "";
const categories = [
{ name: "General", icon: <TbSquare /> },
{ name: "Email", icon: <TbMail /> },
@ -71,7 +73,7 @@ const ConfigurationNavBar = ({
: undefined
}
key={category.name}
href={`${config.get("general.webroot")}/admin/config/${category.name.toLowerCase()}`}
href={`${webroot}/admin/config/${category.name.toLowerCase()}`}
>
<Group>
<ThemeIcon
@ -94,7 +96,7 @@ const ConfigurationNavBar = ({
</Stack>
</Navbar.Section>
<MediaQuery largerThan="sm" styles={{ display: "none" }}>
<Button mt="xl" variant="light" component={Link} href={config.get("general.webroot") + "/admin"}>
<Button mt="xl" variant="light" component={Link} href={webroot + "/admin"}>
<FormattedMessage id="common.button.go-back" />
</Button>
</MediaQuery>

View File

@ -26,6 +26,8 @@ import authService from "../../services/auth.service";
import { getOAuthIcon, getOAuthUrl } from "../../utils/oauth.util";
import toast from "../../utils/toast.util";
const webroot = process.env.WEBROOT || "";
const useStyles = createStyles((theme) => ({
or: {
"&:before": {
@ -145,7 +147,7 @@ const SignInForm = ({ redirectPath }: { redirectPath: string }) => {
/>
{config.get("smtp.enabled") && (
<Group position="right" mt="xs">
<Anchor component={Link} href={config.get("general.webroot") + "/auth/resetPassword"} size="xs">
<Anchor component={Link} href={webroot + "/auth/resetPassword"} size="xs">
<FormattedMessage id="resetPassword.title" />
</Anchor>
</Group>

View File

@ -6,6 +6,8 @@ import authService from "../../services/auth.service";
import { FormattedMessage, useIntl } from "react-intl";
import useConfig from "../../hooks/config.hook";
const webroot = process.env.WEBROOT || "";
const ActionAvatar = () => {
const { user } = useUser();
const config = useConfig();
@ -18,13 +20,13 @@ const ActionAvatar = () => {
</ActionIcon>
</Menu.Target>
<Menu.Dropdown>
<Menu.Item component={Link} href={config.get("general.webroot") + "/account"} icon={<TbUser size={14} />}>
<Menu.Item component={Link} href={webroot + "/account"} icon={<TbUser size={14} />}>
<FormattedMessage id="navbar.avatar.account" />
</Menu.Item>
{user!.isAdmin && (
<Menu.Item
component={Link}
href={config.get("general.webroot") + "/admin"}
href={webroot + "/admin"}
icon={<TbSettings size={14} />}
>
<FormattedMessage id="navbar.avatar.admin" />

View File

@ -22,6 +22,7 @@ import ActionAvatar from "./ActionAvatar";
import NavbarShareMenu from "./NavbarShareMenu";
const HEADER_HEIGHT = 60;
const webroot = process.env.WEBROOT || "";
type NavLink = {
link?: string;
@ -125,7 +126,7 @@ const Header = () => {
const authenticatedLinks: NavLink[] = [
{
link: config.get("general.webroot") + "/upload",
link: webroot + "/upload",
label: t("navbar.upload"),
},
{
@ -138,27 +139,27 @@ const Header = () => {
let unauthenticatedLinks: NavLink[] = [
{
link: config.get("general.webroot") + "/auth/signIn",
link: webroot + "/auth/signIn",
label: t("navbar.signin"),
},
];
if (config.get("share.allowUnauthenticatedShares")) {
unauthenticatedLinks.unshift({
link: config.get("general.webroot") + "/upload",
link: webroot + "/upload",
label: t("navbar.upload"),
});
}
if (config.get("general.showHomePage"))
unauthenticatedLinks.unshift({
link: config.get("general.webroot") + "/",
link: webroot + "/",
label: t("navbar.home"),
});
if (config.get("share.allowRegistration"))
unauthenticatedLinks.push({
link: config.get("general.webroot") + "/auth/signUp",
link: webroot + "/auth/signUp",
label: t("navbar.signup"),
});
@ -191,7 +192,7 @@ const Header = () => {
return (
<MantineHeader height={HEADER_HEIGHT} mb={40} className={classes.root}>
<Container className={classes.header}>
<Link href={config.get("general.webroot")+"/"} passHref>
<Link href={webroot + "/"} passHref>
<Group>
<Logo height={35} width={35} />
<Text weight={600}>{config.get("general.appName")}</Text>

View File

@ -4,6 +4,8 @@ import { TbArrowLoopLeft, TbLink } from "react-icons/tb";
import { FormattedMessage } from "react-intl";
import useConfig from "../../hooks/config.hook";
const webroot = process.env.WEBROOT || "";
const NavbarShareMneu = () => {
const config = useConfig();
return (
@ -14,12 +16,12 @@ const NavbarShareMneu = () => {
</ActionIcon>
</Menu.Target>
<Menu.Dropdown>
<Menu.Item component={Link} href={config.get("general.webroot") + "/account/shares"} icon={<TbLink />}>
<Menu.Item component={Link} href={webroot + "/account/shares"} icon={<TbLink />}>
<FormattedMessage id="navbar.links.shares" />
</Menu.Item>
<Menu.Item
component={Link}
href={config.get("general.webroot") + "/account/reverseShares"}
href={webroot + "/account/reverseShares"}
icon={<TbArrowLoopLeft />}
>
<FormattedMessage id="navbar.links.reverse" />

View File

@ -14,6 +14,7 @@ import api from "../../services/api.service";
import Markdown from "markdown-to-jsx";
import useConfig from "../../hooks/config.hook";
const webroot = process.env.WEBROOT || "";
const FilePreviewContext = React.createContext<{
shareId: string;
@ -51,7 +52,7 @@ const FilePreview = ({
component={Link}
onClick={() => modals.closeAll()}
target="_blank"
href={`${config.get("general.webroot")}/api/shares/${shareId}/files/${fileId}?download=false`}
href={`${webroot}/api/shares/${shareId}/files/${fileId}?download=false`}
>
View original file
{/* Add translation? */}

View File

@ -11,6 +11,8 @@ import Meta from "../components/Meta";
import { FormattedMessage } from "react-intl";
import useConfig from "../hooks/config.hook";
const webroot = process.env.WEBROOT || "";
const useStyles = createStyles((theme) => ({
root: {
paddingTop: 80,
@ -54,7 +56,7 @@ const ErrorNotFound = () => {
className={classes.description}
></Text>
<Group position="center">
<Button component={Link} href={config.get("general.webroot") + "/"} variant="light">
<Button component={Link} href={webroot + "/"} variant="light">
<FormattedMessage id="404.button.home" />
</Button>
</Group>

View File

@ -28,6 +28,8 @@ import shareService from "../../services/share.service";
import { MyShare } from "../../types/share.type";
import toast from "../../utils/toast.util";
const webroot = process.env.WEBROOT || "";
const MyShares = () => {
const modals = useModals();
const clipboard = useClipboard();
@ -58,7 +60,7 @@ const MyShares = () => {
<FormattedMessage id="account.shares.description.empty" />
</Text>
<Space h={5} />
<Button component={Link} href={config.get("general.webroot") + "/upload"} variant="light">
<Button component={Link} href={webroot + "/upload"} variant="light">
<FormattedMessage id="account.shares.button.create" />
</Button>
</Stack>

View File

@ -12,6 +12,8 @@ import Logo from "../../components/Logo";
import Meta from "../../components/Meta";
import useConfig from "../../hooks/config.hook";
const webroot = process.env.WEBROOT || "";
const Intro = () => {
const config = useConfig();
return (
@ -45,10 +47,10 @@ const Intro = () => {
<Text>Enough talked, have fun with Pingvin Share!</Text>
<Text mt="lg">How to you want to continue?</Text>
<Stack>
<Button href={config.get("general.webroot") + "/admin/config/general"} component={Link}>
<Button href={webroot + "/admin/config/general"} component={Link}>
Customize configuration
</Button>
<Button href={config.get("general.webroot") + "/"} component={Link} variant="light">
<Button href={webroot + "/"} component={Link} variant="light">
Explore Pingvin Share
</Button>
</Stack>

View File

@ -22,6 +22,8 @@ import authService from "../../../services/auth.service";
import toast from "../../../utils/toast.util";
import useConfig from "../../../hooks/config.hook";
const webroot = process.env.WEBROOT || "";
const useStyles = createStyles((theme) => ({
title: {
fontSize: 26,
@ -95,7 +97,7 @@ const ResetPassword = () => {
color="dimmed"
size="sm"
className={classes.control}
href={config.get("general.webroot") + "/auth/signIn"}
href={webroot + "/auth/signIn"}
>
<Center inline>
<TbArrowLeft size={12} />

View File

@ -18,6 +18,8 @@ import Meta from "../components/Meta";
import useUser from "../hooks/user.hook";
import useConfig from "../hooks/config.hook";
const webroot = process.env.WEBROOT || "";
const useStyles = createStyles((theme) => ({
inner: {
display: "flex",
@ -80,7 +82,7 @@ export default function Home() {
useEffect(() => {
refreshUser().then((user) => {
if (user) {
router.replace(config.get("general.webroot") + "/upload");
router.replace(webroot + "/upload");
}
});
}, []);
@ -144,7 +146,7 @@ export default function Home() {
<Group mt={30}>
<Button
component={Link}
href={config.get("general.webroot") + "/auth/signUp"}
href={webroot + "/auth/signUp"}
radius="xl"
size="md"
className={classes.control}