mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 14:19:38 +00:00
Version dropdown and Album Art
This commit is contained in:
22
src/electron/ipc/AlbumArtHandler.ipc.ts
Normal file
22
src/electron/ipc/AlbumArtHandler.ipc.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { IPCHandler } from '../shared/IPCHandler'
|
||||
import Database from '../shared/Database'
|
||||
import { AlbumArtResult } from '../shared/interfaces/songDetails.interface'
|
||||
|
||||
export default class AlbumArtHandler implements IPCHandler<'album-art'> {
|
||||
event: 'album-art' = 'album-art'
|
||||
// TODO: add method documentation
|
||||
|
||||
async handler(songID: number) {
|
||||
const db = await Database.getInstance()
|
||||
|
||||
return db.sendQuery(this.getAlbumArtQuery(songID), 1) as Promise<AlbumArtResult>
|
||||
}
|
||||
|
||||
private getAlbumArtQuery(songID: number) {
|
||||
return `
|
||||
SELECT art
|
||||
FROM AlbumArt
|
||||
WHERE songID = ${songID};
|
||||
`
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@ export default class Database {
|
||||
static async getInstance() {
|
||||
if (this.database == undefined) {
|
||||
this.database = new Database()
|
||||
await this.database.initDatabaseConnection()
|
||||
}
|
||||
await this.database.initDatabaseConnection()
|
||||
return this.database
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ export default class Database {
|
||||
* @returns one of the responses as type <ResponseType[]>, or an empty array if the query fails.
|
||||
*/
|
||||
async sendQuery<ResponseType>(query: string, queryStatement?: number) {
|
||||
return new Promise<ResponseType[]>(resolve => {
|
||||
return new Promise<ResponseType[] | ResponseType>(resolve => {
|
||||
this.conn.query(query, (err, results) => {
|
||||
if (err) {
|
||||
failQuery(query, err)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import SearchHandler from '../ipc/SearchHandler.ipc'
|
||||
import { SongSearch, SongResult } from './interfaces/search.interface'
|
||||
import { VersionResult } from './interfaces/songDetails.interface'
|
||||
import { VersionResult, AlbumArtResult } from './interfaces/songDetails.interface'
|
||||
import SearchHandler from '../ipc/SearchHandler.ipc'
|
||||
import SongDetailsHandler from '../ipc/SongDetailsHandler.ipc'
|
||||
import AlbumArtHandler from '../ipc/AlbumArtHandler.ipc'
|
||||
|
||||
/**
|
||||
* To add a new IPC listener:
|
||||
@@ -14,7 +15,8 @@ import SongDetailsHandler from '../ipc/SongDetailsHandler.ipc'
|
||||
export function getIPCHandlers(): IPCHandler<keyof IPCEvents>[] {
|
||||
return [
|
||||
new SearchHandler(),
|
||||
new SongDetailsHandler()
|
||||
new SongDetailsHandler(),
|
||||
new AlbumArtHandler()
|
||||
]
|
||||
}
|
||||
|
||||
@@ -23,6 +25,10 @@ export type IPCEvents = {
|
||||
input: SongSearch
|
||||
output: SongResult[]
|
||||
}
|
||||
['album-art']: {
|
||||
input: SongResult['id']
|
||||
output: AlbumArtResult
|
||||
}
|
||||
['song-details']: {
|
||||
input: SongResult['id']
|
||||
output: VersionResult[]
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
export interface AlbumArtResult {
|
||||
art: Buffer
|
||||
}
|
||||
|
||||
export interface VersionResult {
|
||||
versionID: number
|
||||
chartID: number
|
||||
|
||||
Reference in New Issue
Block a user