* feat(auth): add OAuth2 login with GitHub and Google * chore(translations): add files for Japanese * fix(auth): fix link function for GitHub * feat(oauth): basic oidc implementation * feat(oauth): oauth guard * fix: disable image optimizations for logo to prevent caching issues with custom logos * fix: memory leak while downloading large files * chore(translations): update translations via Crowdin (#278) * New translations en-us.ts (Japanese) * New translations en-us.ts (Japanese) * New translations en-us.ts (Japanese) * release: 0.18.2 * doc(translations): Add Japanese README (#279) * Added Japanese README. * Added JAPANESE README link to README.md. * Updated Japanese README. * Updated Environment Variable Table. * updated zh-cn README. * feat(oauth): unlink account * refactor(oauth): make providers extensible * fix(oauth): fix discoveryUri error when toggle google-enabled * feat(oauth): add microsoft and discord as oauth provider * docs(oauth): update README.md * docs(oauth): update oauth2-guide.md * set password to null for new oauth users * New translations en-us.ts (Japanese) (#281) * chore(translations): add Polish files * fix(oauth): fix random username and password * feat(oauth): add totp * fix(oauth): fix totp throttle * fix(oauth): fix qrcode and remove comment * feat(oauth): add error page * fix(oauth): i18n of error page * feat(auth): add OAuth2 login * fix(auth): fix link function for GitHub * feat(oauth): basic oidc implementation * feat(oauth): oauth guard * feat(oauth): unlink account * refactor(oauth): make providers extensible * fix(oauth): fix discoveryUri error when toggle google-enabled * feat(oauth): add microsoft and discord as oauth provider * docs(oauth): update README.md * docs(oauth): update oauth2-guide.md * set password to null for new oauth users * fix(oauth): fix random username and password * feat(oauth): add totp * fix(oauth): fix totp throttle * fix(oauth): fix qrcode and remove comment * feat(oauth): add error page * fix(oauth): i18n of error page * refactor: return null instead of `false` in `getIdOfCurrentUser` functiom * feat: show original oauth error if available * refactor: run formatter * refactor(oauth): error message i18n * refactor(oauth): make OAuth token available someone may use it (to revoke token or get other info etc.) also improved the i18n message * chore(oauth): remove unused import * chore: add database migration * fix: missing python installation for nanoid --------- Co-authored-by: Elias Schneider <login@eliasschneider.com> Co-authored-by: ふうせん <10260662+fusengum@users.noreply.github.com>
107 lines
2.9 KiB
TypeScript
107 lines
2.9 KiB
TypeScript
import { Button, Center, createStyles, Group, Text } from "@mantine/core";
|
|
import { Dropzone as MantineDropzone } from "@mantine/dropzone";
|
|
import { ForwardedRef, useRef } from "react";
|
|
import { TbCloudUpload, TbUpload } from "react-icons/tb";
|
|
import { FormattedMessage } from "react-intl";
|
|
import useTranslate from "../../hooks/useTranslate.hook";
|
|
import { FileUpload } from "../../types/File.type";
|
|
import { byteToHumanSizeString } from "../../utils/fileSize.util";
|
|
import toast from "../../utils/toast.util";
|
|
|
|
const useStyles = createStyles((theme) => ({
|
|
wrapper: {
|
|
position: "relative",
|
|
marginBottom: 30,
|
|
},
|
|
|
|
dropzone: {
|
|
borderWidth: 1,
|
|
paddingBottom: 50,
|
|
},
|
|
|
|
icon: {
|
|
color:
|
|
theme.colorScheme === "dark"
|
|
? theme.colors.dark[3]
|
|
: theme.colors.gray[4],
|
|
},
|
|
|
|
control: {
|
|
position: "absolute",
|
|
bottom: -20,
|
|
},
|
|
}));
|
|
|
|
const Dropzone = ({
|
|
isUploading,
|
|
maxShareSize,
|
|
showCreateUploadModalCallback,
|
|
}: {
|
|
isUploading: boolean;
|
|
maxShareSize: number;
|
|
showCreateUploadModalCallback: (files: FileUpload[]) => void;
|
|
}) => {
|
|
const t = useTranslate();
|
|
|
|
const { classes } = useStyles();
|
|
const openRef = useRef<() => void>();
|
|
return (
|
|
<div className={classes.wrapper}>
|
|
<MantineDropzone
|
|
onReject={(e) => {
|
|
toast.error(e[0].errors[0].message);
|
|
}}
|
|
disabled={isUploading}
|
|
openRef={openRef as ForwardedRef<() => void>}
|
|
onDrop={(files: FileUpload[]) => {
|
|
const fileSizeSum = files.reduce((n, { size }) => n + size, 0);
|
|
|
|
if (fileSizeSum > maxShareSize) {
|
|
toast.error(
|
|
t("upload.dropzone.notify.file-too-big", {
|
|
maxSize: byteToHumanSizeString(maxShareSize),
|
|
}),
|
|
);
|
|
} else {
|
|
files = files.map((newFile) => {
|
|
newFile.uploadingProgress = 0;
|
|
return newFile;
|
|
});
|
|
showCreateUploadModalCallback(files);
|
|
}
|
|
}}
|
|
className={classes.dropzone}
|
|
radius="md"
|
|
>
|
|
<div style={{ pointerEvents: "none" }}>
|
|
<Group position="center">
|
|
<TbCloudUpload size={50} />
|
|
</Group>
|
|
<Text align="center" weight={700} size="lg" mt="xl">
|
|
<FormattedMessage id="upload.dropzone.title" />
|
|
</Text>
|
|
<Text align="center" size="sm" mt="xs" color="dimmed">
|
|
<FormattedMessage
|
|
id="upload.dropzone.description"
|
|
values={{ maxSize: byteToHumanSizeString(maxShareSize) }}
|
|
/>
|
|
</Text>
|
|
</div>
|
|
</MantineDropzone>
|
|
<Center>
|
|
<Button
|
|
className={classes.control}
|
|
variant="light"
|
|
size="sm"
|
|
radius="xl"
|
|
disabled={isUploading}
|
|
onClick={() => openRef.current && openRef.current()}
|
|
>
|
|
{<TbUpload />}
|
|
</Button>
|
|
</Center>
|
|
</div>
|
|
);
|
|
};
|
|
export default Dropzone;
|