Skip to content

Commit

Permalink
tweak: small stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Mar 16, 2024
1 parent c20da1f commit d2ac5b9
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/extras/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlayerIdsObjectType } from "@shared/otherTypes";
import type { PlayerIdsObjectType } from "@shared/otherTypes";
import consts from "../../shared/consts";

/**
Expand Down
8 changes: 6 additions & 2 deletions core/webroutes/adminManager/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ async function handleAdd(ctx: AuthedCtx) {
//Validate Discord ID
let discordData: ProviderDataType | undefined;
if (discordID.length) {
if (!consts.regexValidDiscordId.test(discordID)) return ctx.send({type: 'danger', message: 'Invalid Discord ID'});
if (!consts.validIdentifierParts.discord.test(discordID)) {
return ctx.send({type: 'danger', message: 'Invalid Discord ID'});
}
discordData = {
id: discordID,
identifier: `discord:${discordID}`,
Expand Down Expand Up @@ -210,7 +212,9 @@ async function handleEdit(ctx: AuthedCtx) {
//Validate Discord ID
let discordData: ProviderDataType | undefined;
if (discordID.length) {
if (!consts.regexValidDiscordId.test(discordID)) return ctx.send({type: 'danger', message: 'Invalid Discord ID'});
if (!consts.validIdentifierParts.discord.test(discordID)) {
return ctx.send({type: 'danger', message: 'Invalid Discord ID'});
}
discordData = {
id: discordID,
identifier: `discord:${discordID}`,
Expand Down
2 changes: 1 addition & 1 deletion core/webroutes/authentication/addMasterSave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default async function AuthAddMasterSave(ctx: InitializedCtx) {
}

//Checking the discordId
if (typeof discordId === 'string' && !consts.regexValidDiscordId.test(discordId)) {
if (typeof discordId === 'string' && !consts.validIdentifierParts.discord.test(discordId)) {
return ctx.send<ApiAddMasterSaveResp>({
error: `Invalid Discord ID.`,
});
Expand Down
3 changes: 2 additions & 1 deletion core/webroutes/player/checkJoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const modulename = 'WebServer:PlayerCheckJoin';
import cleanPlayerName from '@shared/cleanPlayerName';
import { GenericApiErrorResp } from '@shared/genericApiTypes';
import { DatabaseActionType, DatabaseWhitelistApprovalsType } from '@core/components/PlayerDatabase/databaseTypes';
import { anyUndefined, filterPlayerHwids, now, parsePlayerIds, PlayerIdsObjectType } from '@core/extras/helpers';
import { anyUndefined, filterPlayerHwids, now, parsePlayerIds } from '@core/extras/helpers';
import type { PlayerIdsObjectType } from "@shared/otherTypes";
import xssInstancer from '@core/extras/xss';
import playerResolver from '@core/playerLogic/playerResolver';
import humanizeDuration, { Unit } from 'humanize-duration';
Expand Down
1 change: 1 addition & 0 deletions panel/src/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export function Header() {
<div className="flex flex-row items-center flex-grow gap-5 mr-5">
<div className="w-sidebar hidden xl:flex justify-center">
<NavLink href="/">
{/* <h2 className="text-4xl font-bold text-pink-500 saturate-150">Option B</h2> */}
<LogoFullSquareGreen className="h-9 hover:scale-105 hover:brightness-110" />
</NavLink>
</div>
Expand Down
11 changes: 6 additions & 5 deletions panel/src/pages/Players/PlayersSearchBox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { throttle } from "throttle-debounce";
import { useEffect, useRef, useState } from 'react';
import { Button } from '@/components/ui/button';
import { createRandomHslColor } from '@/lib/utils';
import { ChevronsUpDownIcon, FilterXIcon, XIcon, ChevronDownIcon } from 'lucide-react';
import { Input } from '@/components/ui/input';
import {
Expand Down Expand Up @@ -78,12 +77,13 @@ export function PlayerSearchBox({ doSearch, initialState }: PlayerSearchBoxProps
const [currSearchType, setCurrSearchType] = useState<string>(initialState.search?.type || 'playerName');
const [selectedFilters, setSelectedFilters] = useState<string[]>(initialState.filters);
const [hasSearchText, setHasSearchText] = useState(!!initialState.search?.value);
const [inputErrorMsg, setInputErrorMsg] = useState('');

const updateSearch = () => {
if (!inputRef.current) return;
const searchValue = inputRef.current.value.trim();
if(searchValue.length){
doSearch({value: searchValue, type: currSearchType}, selectedFilters);
if (searchValue.length) {
doSearch({ value: searchValue, type: currSearchType }, selectedFilters);
} else {
doSearch(null, selectedFilters);
}
Expand All @@ -95,7 +95,7 @@ export function PlayerSearchBox({ doSearch, initialState }: PlayerSearchBoxProps
}, [inputRef, currSearchType, selectedFilters]);

//Input handlers
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
const handleInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
throttleFunc.cancel({ upcomingOnly: true });
updateSearch();
Expand Down Expand Up @@ -124,6 +124,7 @@ export function PlayerSearchBox({ doSearch, initialState }: PlayerSearchBoxProps
}
}

//It's render time! 🎉
const selectedSearchType = availableSearchTypes.find((type) => type.value === currSearchType);
if (!selectedSearchType) throw new Error(`Invalid search type: ${currSearchType}`);
const filterBtnMessage = selectedFilters.length ? `${selectedFilters.length} Filters` : 'No filters';
Expand All @@ -138,7 +139,7 @@ export function PlayerSearchBox({ doSearch, initialState }: PlayerSearchBoxProps
autoCorrect='off'
ref={inputRef}
placeholder={selectedSearchType.placeholder}
onKeyDown={handleKeyDown}
onKeyDown={handleInputKeyDown}
/>
{hasSearchText ? (
<button
Expand Down
2 changes: 1 addition & 1 deletion panel/src/pages/auth/AddMasterCallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function RegisterForm({ fivemId, fivemName, profilePicture }: ApiAddMasterCallba
discordInput = discordInput.substring(8);
discordRef.current!.value = discordInput;
}
if (!consts.regexValidDiscordId.test(discordInput)) {
if (!consts.validIdentifierParts.discord.test(discordInput)) {
setErrorMessage('The Discord ID needs to be the numeric "User ID" instead of the username.\n You can also leave it blank.');
return;
}
Expand Down
10 changes: 9 additions & 1 deletion shared/consts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const noLookAlikesAlphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZ'; //i,o removed
export default {
//Identifier stuff
regexValidDiscordId: /^\d{17,20}$/,
regexValidHwidToken: /^[0-9A-Fa-f]{1,2}:[0-9A-Fa-f]{64}$/,
validIdentifiers: {
// https://github.com/discordjs/discord.js/pull/9144
Expand All @@ -14,6 +13,15 @@ export default {
steam: /^steam:1100001[0-9A-Fa-f]{8}$/,
xbl: /^xbl:\d{14,20}$/,
},
validIdentifierParts: {
discord: /^\d{17,20}$/,
fivem: /^\d{1,8}$/,
license: /^[0-9A-Fa-f]{40}$/,
license2: /^[0-9A-Fa-f]{40}$/,
live: /^\d{14,20}$/,
steam: /^1100001[0-9A-Fa-f]{8}$/,
xbl: /^\d{14,20}$/,
},

// Database stuff
adminPasswordMinLength: 6,
Expand Down

0 comments on commit d2ac5b9

Please sign in to comment.