mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-07-09 03:25:09 +00:00
Replace Database connection with web server API
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
import { Connection, createConnection } from 'mysql'
|
||||
import { failQuery } from './ErrorMessages'
|
||||
|
||||
export default class Database {
|
||||
|
||||
// Singleton
|
||||
private static database: Database
|
||||
private constructor() { }
|
||||
static async getInstance() {
|
||||
if (this.database == undefined) {
|
||||
this.database = new Database()
|
||||
await this.database.initDatabaseConnection()
|
||||
}
|
||||
return this.database
|
||||
}
|
||||
|
||||
private conn: Connection
|
||||
|
||||
/**
|
||||
* Constructs a database connection to the chartmanager database.
|
||||
*/
|
||||
private async initDatabaseConnection() {
|
||||
this.conn = createConnection({
|
||||
host: 'chartmanager.cdtrqnlcxz86.us-east-1.rds.amazonaws.com',
|
||||
port: 3306,
|
||||
user: 'standarduser',
|
||||
password: 'E4OZXWDPiX9exUpMhcQq', // Note: this login is read-only
|
||||
database: 'chartmanagerdatabase',
|
||||
multipleStatements: true,
|
||||
charset: 'utf8mb4',
|
||||
typeCast: (field, next) => { // Convert 1/0 to true/false
|
||||
if (field.type == 'TINY' && field.length == 1) {
|
||||
return (field.string() == '1') // 1 = true, 0 = false
|
||||
} else {
|
||||
return next()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// TODO: make this error message more user-friendly (retry option?)
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
this.conn.connect(err => {
|
||||
if (err) {
|
||||
reject(`Failed to connect to database: ${err}`)
|
||||
return
|
||||
} else {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the database connection.
|
||||
*/
|
||||
static closeConnection() {
|
||||
if (this.database != undefined) {
|
||||
this.database.conn.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends `query` to the database.
|
||||
* @param queryStatement The nth response statement to be returned. If undefined, the entire response is returned.
|
||||
* @returns the selected response statement, or an empty array if the query fails.
|
||||
*/
|
||||
async sendQuery<ResponseType>(query: string, queryStatement?: number) {
|
||||
return new Promise<ResponseType[] | ResponseType>(resolve => {
|
||||
this.conn.query(query, (err, results) => {
|
||||
if (err) {
|
||||
failQuery(query, err)
|
||||
resolve([])
|
||||
return
|
||||
}
|
||||
if (queryStatement !== undefined) {
|
||||
resolve(results[queryStatement - 1])
|
||||
} else {
|
||||
resolve(results)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,7 @@ export const dataPath = path.join(app.getPath('userData'), 'bridge_data')
|
||||
export const libraryPath = path.join(dataPath, 'library.db')
|
||||
export const settingsPath = path.join(dataPath, 'settings.json')
|
||||
export const tempPath = path.join(dataPath, 'temp')
|
||||
export const themesPath = path.join(dataPath, 'themes')
|
||||
export const themesPath = path.join(dataPath, 'themes')
|
||||
|
||||
// URL
|
||||
export const serverURL = '64.53.210.87'
|
||||
@@ -1,3 +1,5 @@
|
||||
import { DriveChart } from './songDetails.interface'
|
||||
|
||||
/**
|
||||
* Represents a user's request to interact with the download system.
|
||||
*/
|
||||
@@ -14,7 +16,7 @@ export interface NewDownload {
|
||||
avTagName: string
|
||||
artist: string
|
||||
charter: string
|
||||
links: { [type: string]: string }
|
||||
driveData: DriveChart
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* The image data for a song's album art.
|
||||
*/
|
||||
export interface AlbumArtResult {
|
||||
art: Buffer
|
||||
base64Art: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -15,13 +15,12 @@ export interface VersionResult {
|
||||
latestVersionID: number
|
||||
latestSetlistVersionID: number
|
||||
icon: string
|
||||
name: string
|
||||
driveData: DriveChart & { inChartPack: boolean }
|
||||
avTagName: string
|
||||
charters: string
|
||||
charterIDs: string
|
||||
tags: string | null
|
||||
downloadLink: string
|
||||
lastModified: number
|
||||
lastModified: string
|
||||
song_length: number
|
||||
diff_band: number
|
||||
diff_guitar: number
|
||||
@@ -32,5 +31,53 @@ export interface VersionResult {
|
||||
diff_guitarghl: number
|
||||
diff_bassghl: number
|
||||
songDataIncorrect: boolean
|
||||
isUnusualAvTagName: boolean
|
||||
year: string
|
||||
chartMetadata: ChartMetadata
|
||||
}
|
||||
|
||||
export interface DriveChart {
|
||||
source: DriveSource
|
||||
isArchive: boolean
|
||||
downloadPath: string
|
||||
filesHash: string
|
||||
files: DriveFile[]
|
||||
}
|
||||
|
||||
export interface DriveSource {
|
||||
isSetlistSource: boolean
|
||||
setlistIcon?: string
|
||||
sourceUserIDs: number[]
|
||||
sourceName: string
|
||||
sourceDriveID: string
|
||||
}
|
||||
|
||||
export interface DriveFile {
|
||||
id: string
|
||||
originalFilename: string
|
||||
mimeType: string
|
||||
webContentLink: string
|
||||
modifiedTime: string
|
||||
md5Checksum: string
|
||||
size: string
|
||||
}
|
||||
|
||||
export interface ChartMetadata {
|
||||
hasSections: boolean
|
||||
hasStarPower: boolean
|
||||
hasForced: boolean
|
||||
hasTap: boolean
|
||||
hasOpen: {
|
||||
[instrument: string]: boolean
|
||||
}
|
||||
hasSoloSections: boolean
|
||||
hasLyrics: boolean
|
||||
is120: boolean
|
||||
hasBrokenNotes: boolean
|
||||
noteCounts: {
|
||||
[instrument: string]: {
|
||||
[difficulty: string]: number
|
||||
}
|
||||
}
|
||||
length: number
|
||||
effectiveLength: number
|
||||
}
|
||||
Reference in New Issue
Block a user