mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 22:29:38 +00:00
Restructure
This commit is contained in:
20
src-electron/ipc/browse/AlbumArtHandler.ipc.ts
Normal file
20
src-electron/ipc/browse/AlbumArtHandler.ipc.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { AlbumArtResult } from '../../shared/interfaces/songDetails.interface'
|
||||
import { IPCInvokeHandler } from '../../shared/IPCHandler'
|
||||
import { serverURL } from '../../shared/Paths'
|
||||
|
||||
/**
|
||||
* Handles the 'album-art' event.
|
||||
*/
|
||||
class AlbumArtHandler implements IPCInvokeHandler<'album-art'> {
|
||||
event = 'album-art' as const
|
||||
|
||||
/**
|
||||
* @returns an `AlbumArtResult` object containing the album art for the song with `songID`.
|
||||
*/
|
||||
async handler(songID: number): Promise<AlbumArtResult> {
|
||||
const response = await fetch(`https://${serverURL}/api/data/album-art/${songID}`)
|
||||
return await response.json()
|
||||
}
|
||||
}
|
||||
|
||||
export const albumArtHandler = new AlbumArtHandler()
|
||||
20
src-electron/ipc/browse/BatchSongDetailsHandler.ipc.ts
Normal file
20
src-electron/ipc/browse/BatchSongDetailsHandler.ipc.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { VersionResult } from '../../shared/interfaces/songDetails.interface'
|
||||
import { IPCInvokeHandler } from '../../shared/IPCHandler'
|
||||
import { serverURL } from '../../shared/Paths'
|
||||
|
||||
/**
|
||||
* Handles the 'batch-song-details' event.
|
||||
*/
|
||||
class BatchSongDetailsHandler implements IPCInvokeHandler<'batch-song-details'> {
|
||||
event = 'batch-song-details' as const
|
||||
|
||||
/**
|
||||
* @returns an array of all the chart versions with a songID found in `songIDs`.
|
||||
*/
|
||||
async handler(songIDs: number[]): Promise<VersionResult[]> {
|
||||
const response = await fetch(`https://${serverURL}/api/data/song-versions/${songIDs.join(',')}`)
|
||||
return await response.json()
|
||||
}
|
||||
}
|
||||
|
||||
export const batchSongDetailsHandler = new BatchSongDetailsHandler()
|
||||
28
src-electron/ipc/browse/SearchHandler.ipc.ts
Normal file
28
src-electron/ipc/browse/SearchHandler.ipc.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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()
|
||||
20
src-electron/ipc/browse/SongDetailsHandler.ipc.ts
Normal file
20
src-electron/ipc/browse/SongDetailsHandler.ipc.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { VersionResult } from '../../shared/interfaces/songDetails.interface'
|
||||
import { IPCInvokeHandler } from '../../shared/IPCHandler'
|
||||
import { serverURL } from '../../shared/Paths'
|
||||
|
||||
/**
|
||||
* Handles the 'song-details' event.
|
||||
*/
|
||||
class SongDetailsHandler implements IPCInvokeHandler<'song-details'> {
|
||||
event = 'song-details' as const
|
||||
|
||||
/**
|
||||
* @returns the chart versions with `songID`.
|
||||
*/
|
||||
async handler(songID: number): Promise<VersionResult[]> {
|
||||
const response = await fetch(`https://${serverURL}/api/data/song-versions/${songID}`)
|
||||
return await response.json()
|
||||
}
|
||||
}
|
||||
|
||||
export const songDetailsHandler = new SongDetailsHandler()
|
||||
Reference in New Issue
Block a user