From 737a9c3d2dcf51895464a7c2b451dbc0fb7048a9 Mon Sep 17 00:00:00 2001 From: srijna Date: Wed, 25 Feb 2026 15:57:26 +0530 Subject: [PATCH 1/3] refactor(custom-sounds): remove any usage and enforce strict typing in AddCustomSound and EditSound --- .../client/views/admin/customSounds/AddCustomSound.tsx | 8 +++++--- apps/meteor/client/views/admin/customSounds/EditSound.tsx | 8 ++++---- apps/meteor/client/views/admin/customSounds/lib.ts | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/meteor/client/views/admin/customSounds/AddCustomSound.tsx b/apps/meteor/client/views/admin/customSounds/AddCustomSound.tsx index 3bc46c8742f1d..f2320cd08d7bb 100644 --- a/apps/meteor/client/views/admin/customSounds/AddCustomSound.tsx +++ b/apps/meteor/client/views/admin/customSounds/AddCustomSound.tsx @@ -19,7 +19,7 @@ const AddCustomSound = ({ goToNew, close, onChange, ...props }: AddCustomSoundPr const dispatchToastMessage = useToastMessageDispatch(); const [name, setName] = useState(''); - const [sound, setSound] = useState<{ name: string }>(); + const [sound, setSound] = useState(); const uploadCustomSound = useMethod('uploadCustomSound'); const insertOrUpdateSound = useMethod('insertOrUpdateSound'); @@ -31,8 +31,7 @@ const AddCustomSound = ({ goToNew, close, onChange, ...props }: AddCustomSoundPr const [clickUpload] = useSingleFileInput(handleChangeFile, 'audio/mp3'); const saveAction = useCallback( - // FIXME - async (name: string, soundFile: any) => { + async (name: string, soundFile: File) => { const soundData = createSoundData(soundFile, name); const validation = validate(soundData, soundFile) as Array[0]>; @@ -73,6 +72,9 @@ const AddCustomSound = ({ goToNew, close, onChange, ...props }: AddCustomSoundPr const handleSave = useCallback(async () => { try { + if (!sound) { + return; + } const result = await saveAction(name, sound); if (result) { dispatchToastMessage({ type: 'success', message: t('Custom_Sound_Saved_Successfully') }); diff --git a/apps/meteor/client/views/admin/customSounds/EditSound.tsx b/apps/meteor/client/views/admin/customSounds/EditSound.tsx index 9f72df02ca7bd..9ddeea40d846c 100644 --- a/apps/meteor/client/views/admin/customSounds/EditSound.tsx +++ b/apps/meteor/client/views/admin/customSounds/EditSound.tsx @@ -52,9 +52,9 @@ function EditSound({ close, onChange, data, ...props }: EditSoundProps): ReactEl const hasUnsavedChanges = useMemo(() => previousName !== name || previousSound !== sound, [name, previousName, previousSound, sound]); const saveAction = useCallback( - // FIXME - async (sound: any) => { - const soundData = createSoundData(sound, name, { previousName, previousSound, _id, extension: sound.extension }); + async (sound: { _id: string; name: string; extension?: string } | File) => { + const extension = 'extension' in sound ? sound.extension ?? '' : ''; + const soundData = createSoundData(sound, name, { previousName, previousSound, _id, extension }); const validation = validate(soundData, sound); if (validation.length === 0) { let soundId: string; @@ -68,7 +68,7 @@ function EditSound({ close, onChange, data, ...props }: EditSoundProps): ReactEl soundData._id = soundId; soundData.random = Math.round(Math.random() * 1000); - if (sound && sound !== previousSound) { + if (sound instanceof File) { dispatchToastMessage({ type: 'success', message: t('Uploading_file') }); const reader = new FileReader(); diff --git a/apps/meteor/client/views/admin/customSounds/lib.ts b/apps/meteor/client/views/admin/customSounds/lib.ts index c447bad77bdeb..2e3e577203e31 100644 --- a/apps/meteor/client/views/admin/customSounds/lib.ts +++ b/apps/meteor/client/views/admin/customSounds/lib.ts @@ -2,7 +2,7 @@ import type { ICustomSoundData } from '../../../../app/custom-sounds/server/meth type ICustomSoundFile = { name: string; - type: string; + type?: string; extension?: string; }; @@ -20,7 +20,7 @@ export function validate(soundData: ICustomSoundData, soundFile?: ICustomSoundFi if (soundFile) { if (!soundData.previousSound || soundData.previousSound !== soundFile) { - if (!/audio\/mp3/.test(soundFile.type) && !/audio\/mpeg/.test(soundFile.type) && !/audio\/x-mpeg/.test(soundFile.type)) { + if (soundFile.type && !/audio\/mp3/.test(soundFile.type) && !/audio\/mpeg/.test(soundFile.type) && !/audio\/x-mpeg/.test(soundFile.type)) { errors.push('FileType'); } } From a472d6ff67ba6bddf784878545eb47c750b7dde6 Mon Sep 17 00:00:00 2001 From: srijna Date: Wed, 25 Feb 2026 16:37:22 +0530 Subject: [PATCH 2/3] fix(custom-sounds): validate empty MIME type values in sound file checks --- apps/meteor/client/views/admin/customSounds/lib.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/meteor/client/views/admin/customSounds/lib.ts b/apps/meteor/client/views/admin/customSounds/lib.ts index 2e3e577203e31..9de09dcd23c19 100644 --- a/apps/meteor/client/views/admin/customSounds/lib.ts +++ b/apps/meteor/client/views/admin/customSounds/lib.ts @@ -20,7 +20,7 @@ export function validate(soundData: ICustomSoundData, soundFile?: ICustomSoundFi if (soundFile) { if (!soundData.previousSound || soundData.previousSound !== soundFile) { - if (soundFile.type && !/audio\/mp3/.test(soundFile.type) && !/audio\/mpeg/.test(soundFile.type) && !/audio\/x-mpeg/.test(soundFile.type)) { + if ('type' in soundFile && !/audio\/mp3/.test(soundFile.type ?? '') && !/audio\/mpeg/.test(soundFile.type ?? '') && !/audio\/x-mpeg/.test(soundFile.type ?? '')) { errors.push('FileType'); } } From 114a5fe58be20e9525b0273a469fa0bde5dc1deb Mon Sep 17 00:00:00 2001 From: srijna Date: Fri, 27 Feb 2026 16:28:15 +0530 Subject: [PATCH 3/3] fix: resolve prettier formatting errors in lib.ts and EditSound.tsx --- apps/meteor/client/views/admin/customSounds/EditSound.tsx | 2 +- apps/meteor/client/views/admin/customSounds/lib.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/meteor/client/views/admin/customSounds/EditSound.tsx b/apps/meteor/client/views/admin/customSounds/EditSound.tsx index 9ddeea40d846c..3f85f33803c93 100644 --- a/apps/meteor/client/views/admin/customSounds/EditSound.tsx +++ b/apps/meteor/client/views/admin/customSounds/EditSound.tsx @@ -53,7 +53,7 @@ function EditSound({ close, onChange, data, ...props }: EditSoundProps): ReactEl const saveAction = useCallback( async (sound: { _id: string; name: string; extension?: string } | File) => { - const extension = 'extension' in sound ? sound.extension ?? '' : ''; + const extension = 'extension' in sound ? (sound.extension ?? '') : ''; const soundData = createSoundData(sound, name, { previousName, previousSound, _id, extension }); const validation = validate(soundData, sound); if (validation.length === 0) { diff --git a/apps/meteor/client/views/admin/customSounds/lib.ts b/apps/meteor/client/views/admin/customSounds/lib.ts index 9de09dcd23c19..b79decf837e58 100644 --- a/apps/meteor/client/views/admin/customSounds/lib.ts +++ b/apps/meteor/client/views/admin/customSounds/lib.ts @@ -20,7 +20,12 @@ export function validate(soundData: ICustomSoundData, soundFile?: ICustomSoundFi if (soundFile) { if (!soundData.previousSound || soundData.previousSound !== soundFile) { - if ('type' in soundFile && !/audio\/mp3/.test(soundFile.type ?? '') && !/audio\/mpeg/.test(soundFile.type ?? '') && !/audio\/x-mpeg/.test(soundFile.type ?? '')) { + if ( + 'type' in soundFile && + !/audio\/mp3/.test(soundFile.type ?? '') && + !/audio\/mpeg/.test(soundFile.type ?? '') && + !/audio\/x-mpeg/.test(soundFile.type ?? '') + ) { errors.push('FileType'); } }