mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 14:19:38 +00:00
Fixed eslint errors
This commit is contained in:
@@ -88,4 +88,5 @@ class SetSettingsHandler implements IPCEmitHandler<'set-settings'> {
|
||||
}
|
||||
|
||||
export const getSettingsHandler = new GetSettingsHandler()
|
||||
export const setSettingsHandler = new SetSettingsHandler()
|
||||
export const setSettingsHandler = new SetSettingsHandler()
|
||||
export function getSettings() { return getSettingsHandler.getSettings() }
|
||||
@@ -17,7 +17,7 @@ const mkdir = promisify(_mkdir)
|
||||
export class ChartDownload {
|
||||
|
||||
// This changes if the user needs to click 'retry' or 'continue'
|
||||
run: () => void | Promise<void> = this.beginDownload
|
||||
run: () => void | Promise<void> = this.beginDownload.bind(this)
|
||||
cancel: () => void
|
||||
|
||||
isArchive: boolean
|
||||
@@ -51,7 +51,7 @@ export class ChartDownload {
|
||||
this.header = ''
|
||||
this.description = 'Waiting for other downloads to finish...'
|
||||
this.type = 'good'
|
||||
this.cancel = () => { }
|
||||
this.cancel = () => { /* do nothing */ }
|
||||
emitIPCEvent('download-updated', this)
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ export class ChartDownload {
|
||||
try {
|
||||
chartPath = await this.createDownloadFolder()
|
||||
} catch (e) {
|
||||
this.run = this.beginDownload // Retry action
|
||||
this.run = this.beginDownload.bind(this) // Retry action
|
||||
this.error('Access Error', e.message)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { IPCEmitHandler } from '../../shared/IPCHandler'
|
||||
import { randomBytes as _randomBytes } from 'crypto'
|
||||
import { Download } from '../../shared/interfaces/download.interface'
|
||||
import { mkdir as _mkdir } from 'fs'
|
||||
import { ChartDownload } from './ChartDownload'
|
||||
|
||||
class DownloadHandler implements IPCEmitHandler<'download'> {
|
||||
@@ -11,7 +9,7 @@ class DownloadHandler implements IPCEmitHandler<'download'> {
|
||||
downloadQueue: ChartDownload[] = []
|
||||
isGoogleDownloading = false // This is a lock controlled by only one ChartDownload at a time
|
||||
|
||||
async handler(data: Download) {
|
||||
handler(data: Download) {
|
||||
if (data.action == 'add') {
|
||||
this.downloads[data.versionID] = new ChartDownload(data.versionID, data.data)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@ import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import * as needle from 'needle'
|
||||
// TODO: replace needle with got (for cancel() method) (if before-headers event is possible?)
|
||||
import { getSettingsHandler } from '../SettingsHandler.ipc'
|
||||
const getSettings = getSettingsHandler.getSettings
|
||||
import { getSettings } from '../SettingsHandler.ipc'
|
||||
|
||||
type EventCallback = {
|
||||
'request': () => void
|
||||
@@ -16,7 +15,7 @@ type EventCallback = {
|
||||
}
|
||||
type Callbacks = { [E in keyof EventCallback]: EventCallback[E] }
|
||||
|
||||
export type DownloadError = { header: string, body: string }
|
||||
export type DownloadError = { header: string; body: string }
|
||||
|
||||
/**
|
||||
* Downloads a file from `url` to `destinationFolder` and verifies that its hash matches `expectedHash`.
|
||||
@@ -36,7 +35,7 @@ export class FileDownloader {
|
||||
* @param expectedHash The hash header value that is expected for this file.
|
||||
*/
|
||||
constructor(private url: string, private destinationFolder: string, private expectedHash?: string) { }
|
||||
|
||||
|
||||
/**
|
||||
* Calls `callback` when `event` fires.
|
||||
*/
|
||||
@@ -53,7 +52,7 @@ export class FileDownloader {
|
||||
this.callbacks.error({ header: 'Library folder not specified', body: 'Please go to the settings to set your library folder.' }, () => this.beginDownload())
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
this.requestDownload()
|
||||
}
|
||||
|
||||
@@ -64,17 +63,17 @@ export class FileDownloader {
|
||||
private requestDownload(cookieHeader?: string) {
|
||||
if (this.wasCanceled) { return } // CANCEL POINT
|
||||
this.callbacks.request()
|
||||
let uuid = generateUUID()
|
||||
const uuid = generateUUID()
|
||||
const req = needle.get(this.url, {
|
||||
follow_max: 10,
|
||||
open_timeout: 5000,
|
||||
headers: Object.assign({
|
||||
'follow_max': 10,
|
||||
'open_timeout': 5000,
|
||||
'headers': Object.assign({
|
||||
'User-Agent': 'PostmanRuntime/7.22.0',
|
||||
'Referer': this.url,
|
||||
'Accept': '*/*',
|
||||
'Postman-Token': uuid
|
||||
},
|
||||
(cookieHeader ? { 'Cookie': cookieHeader } : undefined)
|
||||
(cookieHeader ? { 'Cookie': cookieHeader } : undefined)
|
||||
)
|
||||
})
|
||||
|
||||
@@ -99,7 +98,7 @@ export class FileDownloader {
|
||||
return
|
||||
}
|
||||
|
||||
let fileType = headers['content-type']
|
||||
const fileType = headers['content-type']
|
||||
if (fileType.startsWith('text/html')) {
|
||||
this.handleHTMLResponse(req, headers['set-cookie'])
|
||||
} else {
|
||||
@@ -183,7 +182,7 @@ export class FileDownloader {
|
||||
} else {
|
||||
// GDrive specific jazz
|
||||
const filenameRegex = /filename="(.*?)"/g
|
||||
let results = filenameRegex.exec(headers['content-disposition'])
|
||||
const results = filenameRegex.exec(headers['content-disposition'])
|
||||
if (results == null) {
|
||||
console.log(`Warning: couldn't find filename in content-disposition header: [${headers['content-disposition']}]`)
|
||||
return 'unknownFilename'
|
||||
|
||||
@@ -4,9 +4,8 @@ import { promisify } from 'util'
|
||||
import { join, extname } from 'path'
|
||||
import * as node7z from 'node-7z'
|
||||
import * as zipBin from '7zip-bin'
|
||||
import { getSettingsHandler } from '../SettingsHandler.ipc'
|
||||
import { getSettings } from '../SettingsHandler.ipc'
|
||||
import { extractRar } from './RarExtractor'
|
||||
const getSettings = getSettingsHandler.getSettings
|
||||
|
||||
const readdir = promisify(fs.readdir)
|
||||
const unlink = promisify(fs.unlink)
|
||||
@@ -21,7 +20,7 @@ type EventCallback = {
|
||||
'extractProgress': (percent: number, fileCount: number) => void
|
||||
'transfer': (filepath: string) => void
|
||||
'complete': (filepath: string) => void
|
||||
'error': (error: DownloadError, retry: () => void) => void
|
||||
'error': (error: DownloadError, retry: () => void | Promise<void>) => void
|
||||
}
|
||||
type Callbacks = { [E in keyof EventCallback]: EventCallback[E] }
|
||||
|
||||
@@ -68,11 +67,9 @@ export class FileExtractor {
|
||||
await extractRar(source, this.sourceFolder)
|
||||
} catch (err) {
|
||||
this.callbacks.error({
|
||||
header: 'Extract Failed.',
|
||||
body: `Unable to extract [${filename}]: ${err}`
|
||||
},
|
||||
() => this.extract(filename, extname(filename) == '.rar')
|
||||
)
|
||||
header: 'Extract Failed.',
|
||||
body: `Unable to extract [${filename}]: ${err}`
|
||||
}, () => this.extract(filename, extname(filename) == '.rar'))
|
||||
return
|
||||
}
|
||||
this.transfer(source)
|
||||
@@ -82,7 +79,7 @@ export class FileExtractor {
|
||||
// Use node-7z to extract the archive
|
||||
const stream = node7z.extractFull(source, this.sourceFolder, { $progress: true, $bin: zipBin.path7za })
|
||||
|
||||
stream.on('progress', (progress: { percent: number, fileCount: number }) => {
|
||||
stream.on('progress', (progress: { percent: number; fileCount: number }) => {
|
||||
this.callbacks.extractProgress(progress.percent, progress.fileCount)
|
||||
})
|
||||
|
||||
@@ -107,9 +104,10 @@ export class FileExtractor {
|
||||
*/
|
||||
private async transfer(archiveFilepath?: string) {
|
||||
// TODO: this fails if the extracted chart has nested folders
|
||||
// TODO: skip over "__MACOSX" folder
|
||||
if (this.wasCanceled) { return } // CANCEL POINT
|
||||
try {
|
||||
|
||||
|
||||
// Create destiniation folder if it doesn't exist
|
||||
const destinationFolder = join(this.libraryFolder, this.destinationFolderName)
|
||||
this.callbacks.transfer(destinationFolder)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { getSettingsHandler } from '../SettingsHandler.ipc'
|
||||
const getSettings = getSettingsHandler.getSettings
|
||||
import { getSettings } from '../SettingsHandler.ipc'
|
||||
|
||||
class GoogleTimer {
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ function createBridgeWindow() {
|
||||
defaultHeight: 800,
|
||||
path: dataPath
|
||||
})
|
||||
|
||||
|
||||
// Create the browser window
|
||||
mainWindow = createBrowserWindow(windowState)
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint @typescript-eslint/no-explicit-any: 0 */ // Using any is required because that type is required in catch statements
|
||||
import { red } from 'cli-color'
|
||||
import { getRelativeFilepath } from './ElectronUtilFunctions'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user