mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-02-19 01:55:48 -05:00
refactor: convert config variables to upper case
This commit is contained in:
parent
d4a0f1a4f1
commit
0499548dd3
20 changed files with 54 additions and 51 deletions
|
@ -3,7 +3,7 @@ import * as crypto from "crypto";
|
|||
|
||||
const configVariables = [
|
||||
{
|
||||
key: "setupFinished",
|
||||
key: "SETUP_FINISHED",
|
||||
description: "Whether the setup has been finished",
|
||||
type: "boolean",
|
||||
value: "false",
|
||||
|
@ -11,49 +11,49 @@ const configVariables = [
|
|||
locked: true,
|
||||
},
|
||||
{
|
||||
key: "appUrl",
|
||||
key: "APP_URL",
|
||||
description: "On which URL Pingvin Share is available",
|
||||
type: "string",
|
||||
value: "http://localhost:3000",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "showHomePage",
|
||||
key: "SHOW_HOME_PAGE",
|
||||
description: "Whether to show the home page",
|
||||
type: "boolean",
|
||||
value: "true",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "allowRegistration",
|
||||
key: "ALLOW_REGISTRATION",
|
||||
description: "Whether registration is allowed",
|
||||
type: "boolean",
|
||||
value: "true",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "allowUnauthenticatedShares",
|
||||
key: "ALLOW_UNAUTHENTICATED_SHARES",
|
||||
description: "Whether unauthorized users can create shares",
|
||||
type: "boolean",
|
||||
value: "false",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "maxFileSize",
|
||||
key: "MAX_FILE_SIZE",
|
||||
description: "Maximum file size in bytes",
|
||||
type: "number",
|
||||
value: "1000000000",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "jwtSecret",
|
||||
key: "JWT_SECRET",
|
||||
description: "Long random string used to sign JWT tokens",
|
||||
type: "string",
|
||||
value: crypto.randomBytes(256).toString("base64"),
|
||||
locked: true,
|
||||
},
|
||||
{
|
||||
key: "emailRecipientsEnabled",
|
||||
key: "ENABLE_EMAIL_RECIPIENTS",
|
||||
description:
|
||||
"Whether to send emails to recipients. Only set this to true if you entered the host, port, email and password of your SMTP server.",
|
||||
type: "boolean",
|
||||
|
@ -61,25 +61,25 @@ const configVariables = [
|
|||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "smtpHost",
|
||||
key: "SMTP_HOST",
|
||||
description: "Host of the SMTP server",
|
||||
type: "string",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
key: "smtpPort",
|
||||
key: "SMTP_PORT",
|
||||
description: "Port of the SMTP server",
|
||||
type: "number",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
key: "smtpEmail",
|
||||
key: "SMTP_EMAIL",
|
||||
description: "Email address of the SMTP server",
|
||||
type: "string",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
key: "smtpPassword",
|
||||
key: "SMTP_PASSWORD",
|
||||
description: "Password of the SMTP server",
|
||||
type: "string",
|
||||
value: "",
|
||||
|
|
|
@ -26,13 +26,13 @@ import { UserModule } from "./user/user.module";
|
|||
MulterModule.registerAsync({
|
||||
useFactory: (config: ConfigService) => ({
|
||||
fileFilter: (req: Request, file, cb) => {
|
||||
const maxFileSize = config.get("maxFileSize");
|
||||
const MAX_FILE_SIZE = config.get("MAX_FILE_SIZE");
|
||||
const requestFileSize = parseInt(req.headers["content-length"]);
|
||||
const isValidFileSize = requestFileSize <= maxFileSize;
|
||||
const isValidFileSize = requestFileSize <= MAX_FILE_SIZE;
|
||||
cb(
|
||||
!isValidFileSize &&
|
||||
new HttpException(
|
||||
`File must be smaller than ${maxFileSize} bytes`,
|
||||
`File must be smaller than ${MAX_FILE_SIZE} bytes`,
|
||||
HttpStatus.PAYLOAD_TOO_LARGE
|
||||
),
|
||||
isValidFileSize
|
||||
|
|
|
@ -28,7 +28,7 @@ export class AuthController {
|
|||
@Throttle(10, 5 * 60)
|
||||
@Post("signUp")
|
||||
async signUp(@Body() dto: AuthRegisterDTO) {
|
||||
if (!this.config.get("allowRegistration"))
|
||||
if (!this.config.get("ALLOW_REGISTRATION"))
|
||||
throw new ForbiddenException("Registration is not allowed");
|
||||
return this.authService.signUp(dto);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ export class AuthService {
|
|||
email: dto.email,
|
||||
username: dto.username,
|
||||
password: hash,
|
||||
isAdmin: !this.config.get("setupFinished"),
|
||||
isAdmin: !this.config.get("SETUP_FINISHED"),
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -74,7 +74,7 @@ export class AuthService {
|
|||
throw new ForbiddenException("Invalid password");
|
||||
|
||||
const hash = await argon.hash(newPassword);
|
||||
|
||||
|
||||
this.prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: { password: hash },
|
||||
|
@ -89,7 +89,7 @@ export class AuthService {
|
|||
},
|
||||
{
|
||||
expiresIn: "15min",
|
||||
secret: this.config.get("jwtSecret"),
|
||||
secret: this.config.get("JWT_SECRET"),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ export class JwtGuard extends AuthGuard("jwt") {
|
|||
try {
|
||||
return (await super.canActivate(context)) as boolean;
|
||||
} catch {
|
||||
return this.config.get("allowUnauthenticatedShares");
|
||||
return this.config.get("ALLOW_UNAUTHENTICATED_SHARES");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ import { PrismaService } from "src/prisma/prisma.service";
|
|||
@Injectable()
|
||||
export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(config: ConfigService, private prisma: PrismaService) {
|
||||
config.get("jwtSecret");
|
||||
config.get("JWT_SECRET");
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
secretOrKey: config.get("jwtSecret"),
|
||||
secretOrKey: config.get("JWT_SECRET"),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ export class ConfigService {
|
|||
|
||||
async finishSetup() {
|
||||
return await this.prisma.config.update({
|
||||
where: { key: "setupFinished" },
|
||||
where: { key: "SETUP_FINISHED" },
|
||||
data: { value: "true" },
|
||||
});
|
||||
}
|
||||
|
|
|
@ -22,8 +22,7 @@ export class EmailService {
|
|||
if (!this.config.get("emailRecepientsEnabled"))
|
||||
throw new InternalServerErrorException("Email service disabled");
|
||||
|
||||
const shareUrl = `${this.config.get("appUrl")}/share/${shareId}`;
|
||||
|
||||
const shareUrl = `${this.config.get("APP_URL")}/share/${shareId}`;
|
||||
|
||||
await transporter.sendMail({
|
||||
from: `"Pingvin Share" <${this.config.get("SMTP_EMAIL")}>`,
|
||||
|
|
|
@ -82,7 +82,7 @@ export class FileService {
|
|||
const downloadToken = this.generateFileDownloadToken(shareId, fileId);
|
||||
|
||||
return `${this.config.get(
|
||||
"appUrl"
|
||||
"APP_URL"
|
||||
)}/api/shares/${shareId}/files/${fileId}?token=${downloadToken}`;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ export class FileService {
|
|||
},
|
||||
{
|
||||
expiresIn: "10min",
|
||||
secret: this.config.get("jwtSecret"),
|
||||
secret: this.config.get("JWT_SECRET"),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ export class FileService {
|
|||
verifyFileDownloadToken(shareId: string, token: string) {
|
||||
try {
|
||||
const claims = this.jwtService.verify(token, {
|
||||
secret: this.config.get("jwtSecret"),
|
||||
secret: this.config.get("JWT_SECRET"),
|
||||
});
|
||||
return claims.shareId == shareId;
|
||||
} catch {
|
||||
|
|
|
@ -10,7 +10,7 @@ import { ConfigService } from "src/config/config.service";
|
|||
export class FileValidationPipe implements PipeTransform {
|
||||
constructor(private config: ConfigService) {}
|
||||
async transform(value: any, metadata: ArgumentMetadata) {
|
||||
if (value.size > this.config.get("maxFileSize"))
|
||||
if (value.size > this.config.get("MAX_FILE_SIZE"))
|
||||
throw new BadRequestException("File is ");
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ export class ShareService {
|
|||
},
|
||||
{
|
||||
expiresIn: moment(expiration).diff(new Date(), "seconds") + "s",
|
||||
secret: this.config.get("jwtSecret"),
|
||||
secret: this.config.get("JWT_SECRET"),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ export class ShareService {
|
|||
|
||||
try {
|
||||
const claims = this.jwtService.verify(token, {
|
||||
secret: this.config.get("jwtSecret"),
|
||||
secret: this.config.get("JWT_SECRET"),
|
||||
// Ignore expiration if expiration is 0
|
||||
ignoreExpiration: moment(expiration).isSame(0),
|
||||
});
|
||||
|
|
|
@ -49,7 +49,7 @@ const SignInForm = () => {
|
|||
>
|
||||
Welcome back
|
||||
</Title>
|
||||
{config.get("allowRegistration") && (
|
||||
{config.get("ALLOW_REGISTRATION") && (
|
||||
<Text color="dimmed" size="sm" align="center" mt={5}>
|
||||
You don't have an account yet?{" "}
|
||||
<Anchor component={Link} href={"signUp"} size="sm">
|
||||
|
@ -65,6 +65,7 @@ const SignInForm = () => {
|
|||
>
|
||||
<TextInput
|
||||
label="Email or username"
|
||||
type="email"
|
||||
placeholder="you@email.com"
|
||||
{...form.getInputProps("emailOrUsername")}
|
||||
/>
|
||||
|
|
|
@ -57,7 +57,7 @@ const SignUpForm = () => {
|
|||
>
|
||||
Sign up
|
||||
</Title>
|
||||
{config.get("allowRegistration") && (
|
||||
{config.get("ALLOW_REGISTRATION") && (
|
||||
<Text color="dimmed" size="sm" align="center" mt={5}>
|
||||
You have an account already?{" "}
|
||||
<Anchor component={Link} href={"signIn"} size="sm">
|
||||
|
@ -78,6 +78,7 @@ const SignUpForm = () => {
|
|||
/>
|
||||
<TextInput
|
||||
label="Email"
|
||||
type="email"
|
||||
placeholder="you@email.com"
|
||||
mt="md"
|
||||
{...form.getInputProps("email")}
|
||||
|
|
|
@ -130,7 +130,7 @@ const NavBar = () => {
|
|||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (config.get("showHomePage"))
|
||||
if (config.get("SHOW_HOME_PAGE"))
|
||||
setUnauthenticatedLinks((array) => [
|
||||
{
|
||||
link: "/",
|
||||
|
@ -139,7 +139,7 @@ const NavBar = () => {
|
|||
...array,
|
||||
]);
|
||||
|
||||
if (config.get("allowRegistration"))
|
||||
if (config.get("ALLOW_REGISTRATION"))
|
||||
setUnauthenticatedLinks((array) => [
|
||||
...array,
|
||||
{
|
||||
|
|
|
@ -45,7 +45,7 @@ const Dropzone = ({
|
|||
return (
|
||||
<div className={classes.wrapper}>
|
||||
<MantineDropzone
|
||||
maxSize={parseInt(config.get("maxFileSize"))}
|
||||
maxSize={parseInt(config.get("MAX_FILE_SIZE"))}
|
||||
onReject={(e) => {
|
||||
toast.error(e[0].errors[0].message);
|
||||
}}
|
||||
|
@ -75,7 +75,7 @@ const Dropzone = ({
|
|||
<Text align="center" size="sm" mt="xs" color="dimmed">
|
||||
Drag'n'drop files here to start your share. We can accept
|
||||
only files that are less than{" "}
|
||||
{byteStringToHumanSizeString(config.get("maxFileSize"))} in size.
|
||||
{byteStringToHumanSizeString(config.get("MAX_FILE_SIZE"))} in size.
|
||||
</Text>
|
||||
</div>
|
||||
</MantineDropzone>
|
||||
|
|
|
@ -29,8 +29,8 @@ const showCreateUploadModal = (
|
|||
modals: ModalsContextProps,
|
||||
options: {
|
||||
isUserSignedIn: boolean;
|
||||
allowUnauthenticatedShares: boolean;
|
||||
emailRecipientsEnabled: boolean;
|
||||
ALLOW_UNAUTHENTICATED_SHARES: boolean;
|
||||
ENABLE_EMAIL_RECIPIENTS: boolean;
|
||||
},
|
||||
uploadCallback: (
|
||||
id: string,
|
||||
|
@ -62,14 +62,14 @@ const CreateUploadModalBody = ({
|
|||
) => void;
|
||||
options: {
|
||||
isUserSignedIn: boolean;
|
||||
allowUnauthenticatedShares: boolean;
|
||||
emailRecipientsEnabled: boolean;
|
||||
ALLOW_UNAUTHENTICATED_SHARES: boolean;
|
||||
ENABLE_EMAIL_RECIPIENTS: boolean;
|
||||
};
|
||||
}) => {
|
||||
const modals = useModals();
|
||||
|
||||
const [showNotSignedInAlert, setShowNotSignedInAlert] = useState(
|
||||
options.emailRecipientsEnabled
|
||||
options.ENABLE_EMAIL_RECIPIENTS
|
||||
);
|
||||
|
||||
const validationSchema = yup.object().shape({
|
||||
|
@ -230,7 +230,7 @@ const CreateUploadModalBody = ({
|
|||
{ExpirationPreview({ form })}
|
||||
</Text>
|
||||
<Accordion>
|
||||
{options.emailRecipientsEnabled && (
|
||||
{options.ENABLE_EMAIL_RECIPIENTS && (
|
||||
<Accordion.Item value="recipients" sx={{ borderBottom: "none" }}>
|
||||
<Accordion.Control>Email recipients</Accordion.Control>
|
||||
<Accordion.Panel>
|
||||
|
|
|
@ -17,7 +17,7 @@ const Setup = () => {
|
|||
if (!user) {
|
||||
router.push("/auth/signUp");
|
||||
return;
|
||||
} else if (config.get("setupFinished")) {
|
||||
} else if (config.get("SETUP_FINISHED")) {
|
||||
router.push("/");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ const SignUp = () => {
|
|||
const router = useRouter();
|
||||
if (user) {
|
||||
router.replace("/");
|
||||
} else if (config.get("allowRegistration") == "false") {
|
||||
} else if (config.get("ALLOW_REGISTRATION") == "false") {
|
||||
router.replace("/auth/signIn");
|
||||
} else {
|
||||
return (
|
||||
|
|
|
@ -74,9 +74,9 @@ export default function Home() {
|
|||
|
||||
const { classes } = useStyles();
|
||||
const router = useRouter();
|
||||
if (user || config.get("allowUnauthenticatedShares")) {
|
||||
if (user || config.get("ALLOW_UNAUTHENTICATED_SHARES")) {
|
||||
router.replace("/upload");
|
||||
} else if (!config.get("showHomePage")) {
|
||||
} else if (!config.get("SHOW_HOME_PAGE")) {
|
||||
router.replace("/auth/signIn");
|
||||
} else {
|
||||
return (
|
||||
|
|
|
@ -95,7 +95,7 @@ const Upload = () => {
|
|||
}
|
||||
}
|
||||
}, [files]);
|
||||
if (!user && !config.get("allowUnauthenticatedShares")) {
|
||||
if (!user && !config.get("ALLOW_UNAUTHENTICATED_SHARES")) {
|
||||
router.replace("/");
|
||||
} else {
|
||||
return (
|
||||
|
@ -110,10 +110,12 @@ const Upload = () => {
|
|||
modals,
|
||||
{
|
||||
isUserSignedIn: user ? true : false,
|
||||
allowUnauthenticatedShares: config.get(
|
||||
"allowUnauthenticatedShares"
|
||||
ALLOW_UNAUTHENTICATED_SHARES: config.get(
|
||||
"ALLOW_UNAUTHENTICATED_SHARES"
|
||||
),
|
||||
ENABLE_EMAIL_RECIPIENTS: config.get(
|
||||
"ENABLE_EMAIL_RECIPIENTS"
|
||||
),
|
||||
emailRecipientsEnabled: config.get("emailRecipientsEnabled"),
|
||||
},
|
||||
uploadFiles
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue