re-order alot, move to bun redis, generalized
All checks were successful
Code quality checks / biome (push) Successful in 8s
All checks were successful
Code quality checks / biome (push) Successful in 8s
This commit is contained in:
parent
a646607597
commit
8a9499be85
51 changed files with 559 additions and 916 deletions
|
@ -1,4 +1,4 @@
|
|||
import { logger } from "@helpers/logger";
|
||||
import { logger } from "@creations.works/logger";
|
||||
import { type ReservedSQL, sql } from "bun";
|
||||
|
||||
export const order: number = 6;
|
||||
|
@ -32,13 +32,3 @@ export async function createTable(reservation?: ReservedSQL): Promise<void> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isValidTypeOrExtension(
|
||||
type: string,
|
||||
extension: string,
|
||||
): boolean {
|
||||
return (
|
||||
["image/jpeg", "image/png", "image/gif", "image/webp"].includes(type) &&
|
||||
["jpeg", "jpg", "png", "gif", "webp"].includes(extension)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { logger } from "@helpers/logger";
|
||||
import { logger } from "@creations.works/logger";
|
||||
import { type ReservedSQL, sql } from "bun";
|
||||
|
||||
export const order: number = 5;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { logger } from "@helpers/logger";
|
||||
import { logger } from "@creations.works/logger";
|
||||
import { type ReservedSQL, sql } from "bun";
|
||||
|
||||
export const order: number = 4;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { logger } from "@helpers/logger";
|
||||
import { logger } from "@creations.works/logger";
|
||||
import { type ReservedSQL, sql } from "bun";
|
||||
|
||||
export const order: number = 3;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { logger } from "@helpers/logger";
|
||||
import { logger } from "@creations.works/logger";
|
||||
import { type ReservedSQL, sql } from "bun";
|
||||
|
||||
export const order: number = 2;
|
||||
|
@ -93,8 +93,6 @@ export async function createTable(reservation?: ReservedSQL): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
// * Validation functions
|
||||
|
||||
export async function getSetting(
|
||||
key: string,
|
||||
reservation?: ReservedSQL,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { logger } from "@helpers/logger";
|
||||
import { logger } from "@creations.works/logger";
|
||||
import { type ReservedSQL, sql } from "bun";
|
||||
|
||||
export const order: number = 1;
|
||||
|
@ -36,135 +36,3 @@ export async function createTable(reservation?: ReservedSQL): Promise<void> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// * Validation functions
|
||||
|
||||
// ? should support non english characters but won't mess up the url
|
||||
export const userNameRestrictions: {
|
||||
length: { min: number; max: number };
|
||||
regex: RegExp;
|
||||
} = {
|
||||
length: { min: 3, max: 20 },
|
||||
regex: /^[\p{L}\p{N}._-]+$/u,
|
||||
};
|
||||
|
||||
export const passwordRestrictions: {
|
||||
length: { min: number; max: number };
|
||||
regex: RegExp;
|
||||
} = {
|
||||
length: { min: 12, max: 64 },
|
||||
regex: /^(?=.*\p{Ll})(?=.*\p{Lu})(?=.*\d)(?=.*[^\w\s]).{12,64}$/u,
|
||||
};
|
||||
|
||||
export const emailRestrictions: { regex: RegExp } = {
|
||||
regex: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
||||
};
|
||||
|
||||
export const inviteRestrictions: { min: number; max: number; regex: RegExp } = {
|
||||
min: 4,
|
||||
max: 15,
|
||||
regex: /^[a-zA-Z0-9]+$/,
|
||||
};
|
||||
|
||||
export function isValidUsername(username: string): {
|
||||
valid: boolean;
|
||||
error?: string;
|
||||
} {
|
||||
if (!username) {
|
||||
return { valid: false, error: "" };
|
||||
}
|
||||
|
||||
if (username.length < userNameRestrictions.length.min) {
|
||||
return { valid: false, error: "Username is too short" };
|
||||
}
|
||||
|
||||
if (username.length > userNameRestrictions.length.max) {
|
||||
return { valid: false, error: "Username is too long" };
|
||||
}
|
||||
|
||||
if (!userNameRestrictions.regex.test(username)) {
|
||||
return { valid: false, error: "Username contains invalid characters" };
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
export function isValidPassword(password: string): {
|
||||
valid: boolean;
|
||||
error?: string;
|
||||
} {
|
||||
if (!password) {
|
||||
return { valid: false, error: "" };
|
||||
}
|
||||
|
||||
if (password.length < passwordRestrictions.length.min) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Password must be at least ${passwordRestrictions.length.min} characters long`,
|
||||
};
|
||||
}
|
||||
|
||||
if (password.length > passwordRestrictions.length.max) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Password can't be longer than ${passwordRestrictions.length.max} characters`,
|
||||
};
|
||||
}
|
||||
|
||||
if (!passwordRestrictions.regex.test(password)) {
|
||||
return {
|
||||
valid: false,
|
||||
error:
|
||||
"Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character",
|
||||
};
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
export function isValidEmail(email: string): {
|
||||
valid: boolean;
|
||||
error?: string;
|
||||
} {
|
||||
if (!email) {
|
||||
return { valid: false, error: "" };
|
||||
}
|
||||
|
||||
if (!emailRestrictions.regex.test(email)) {
|
||||
return { valid: false, error: "Invalid email address" };
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
export function isValidInvite(invite: string): {
|
||||
valid: boolean;
|
||||
error?: string;
|
||||
} {
|
||||
if (!invite) {
|
||||
return { valid: false, error: "" };
|
||||
}
|
||||
|
||||
if (invite.length < inviteRestrictions.min) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Invite code must be at least ${inviteRestrictions.min} characters long`,
|
||||
};
|
||||
}
|
||||
|
||||
if (invite.length > inviteRestrictions.max) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Invite code can't be longer than ${inviteRestrictions.max} characters`,
|
||||
};
|
||||
}
|
||||
|
||||
if (!inviteRestrictions.regex.test(invite)) {
|
||||
return {
|
||||
valid: false,
|
||||
error: "Invite code contains invalid characters",
|
||||
};
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue