Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<File>();

const uploadCustomSound = useMethod('uploadCustomSound');
const insertOrUpdateSound = useMethod('insertOrUpdateSound');
Expand All @@ -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<Parameters<typeof t>[0]>;

Expand Down Expand Up @@ -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') });
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/client/views/admin/customSounds/EditSound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
9 changes: 7 additions & 2 deletions apps/meteor/client/views/admin/customSounds/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ICustomSoundData } from '../../../../app/custom-sounds/server/meth

type ICustomSoundFile = {
name: string;
type: string;
type?: string;
extension?: string;
};

Expand All @@ -20,7 +20,12 @@ 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 (
'type' in soundFile &&
!/audio\/mp3/.test(soundFile.type ?? '') &&
!/audio\/mpeg/.test(soundFile.type ?? '') &&
!/audio\/x-mpeg/.test(soundFile.type ?? '')
) {
errors.push('FileType');
}
}
Expand Down