mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 22:29:38 +00:00
29 lines
793 B
TypeScript
29 lines
793 B
TypeScript
import { SongResult, SongSearch } from '../../shared/interfaces/search.interface'
|
|
import { IPCInvokeHandler } from '../../shared/IPCHandler'
|
|
import { serverURL } from '../../shared/Paths'
|
|
|
|
/**
|
|
* Handles the 'song-search' event.
|
|
*/
|
|
class SearchHandler implements IPCInvokeHandler<'song-search'> {
|
|
event = 'song-search' as const
|
|
|
|
/**
|
|
* @returns the top 50 songs that match `search`.
|
|
*/
|
|
async handler(search: SongSearch): Promise<SongResult[]> {
|
|
const response = await fetch(`https://${serverURL}/api/search`, {
|
|
method: 'POST',
|
|
headers: {
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(search),
|
|
})
|
|
|
|
return await response.json()
|
|
}
|
|
}
|
|
|
|
export const searchHandler = new SearchHandler()
|