@@ -5,17 +5,20 @@ import {
55 isCustomSoundsGetOneProps ,
66 isCustomSoundsListProps ,
77 isCustomSoundsCreateProps ,
8+ isCustomSoundsDeleteProps ,
89 isCustomSoundsUpdateProps ,
910 ajv ,
1011 validateBadRequestErrorResponse ,
1112 validateNotFoundErrorResponse ,
1213 validateForbiddenErrorResponse ,
1314 validateUnauthorizedErrorResponse ,
15+ validateInternalErrorResponse ,
1416} from '@rocket.chat/rest-typings' ;
1517import { escapeRegExp } from '@rocket.chat/string-helpers' ;
1618
1719import { MAX_CUSTOM_SOUND_SIZE_BYTES , CUSTOM_SOUND_ALLOWED_MIME_TYPES } from '../../../../lib/constants' ;
1820import { SystemLogger } from '../../../../server/lib/logger/system' ;
21+ import { deleteCustomSound } from '../../../custom-sounds/server/lib/deleteCustomSound' ;
1922import { insertOrUpdateSound } from '../../../custom-sounds/server/lib/insertOrUpdateSound' ;
2023import { uploadCustomSound } from '../../../custom-sounds/server/lib/uploadCustomSound' ;
2124import { getExtension , getMimeTypeFromFileName } from '../../../utils/lib/mimeTypes' ;
@@ -58,6 +61,18 @@ const updateCustomSoundsResponse = ajv.compile<{ success: boolean }>({
5861 required : [ 'success' ] ,
5962} ) ;
6063
64+ const deleteCustomSoundsResponse = ajv . compile < void > ( {
65+ additionalProperties : false ,
66+ type : 'object' ,
67+ properties : {
68+ success : {
69+ type : 'boolean' ,
70+ description : 'Indicates if the request was successful.' ,
71+ } ,
72+ } ,
73+ required : [ 'success' ] ,
74+ } ) ;
75+
6176const customSoundsEndpoints = API . v1
6277 . get (
6378 'custom-sounds.list' ,
@@ -280,6 +295,39 @@ const customSoundsEndpoints = API.v1
280295 return API . v1 . failure ( error instanceof Error ? error . message : 'Unknown error' ) ;
281296 }
282297 } ,
298+ )
299+ . post (
300+ 'custom-sounds.delete' ,
301+ {
302+ response : {
303+ 200 : deleteCustomSoundsResponse ,
304+ 400 : validateBadRequestErrorResponse ,
305+ 401 : validateUnauthorizedErrorResponse ,
306+ 403 : validateForbiddenErrorResponse ,
307+ 404 : validateNotFoundErrorResponse ,
308+ 500 : validateInternalErrorResponse ,
309+ } ,
310+ authRequired : true ,
311+ body : isCustomSoundsDeleteProps ,
312+ permissionsRequired : [ 'manage-sounds' ] ,
313+ } ,
314+ async function action ( ) {
315+ const { _id } = this . bodyParams ;
316+
317+ try {
318+ await deleteCustomSound ( _id ) ;
319+
320+ return API . v1 . success ( ) ;
321+ } catch ( error : unknown ) {
322+ this . logger . error ( { error } ) ;
323+
324+ if ( error instanceof Meteor . Error && error . error === 'Custom_Sound_Error_Invalid_Sound' ) {
325+ return API . v1 . failure ( error . error ) ;
326+ }
327+
328+ return API . v1 . internalError ( ) ;
329+ }
330+ } ,
283331 ) ;
284332
285333export type CustomSoundEndpoints = ExtractRoutesFromAPI < typeof customSoundsEndpoints > ;
0 commit comments