-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partially implemented downloadPackage as part of CliProviderImpl
- Loading branch information
Showing
4 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { CliProgressCallback, CliProvider, CliStateCallback } from 'src/cli/CliProvider'; | ||
import VersionNumber from 'src/model/VersionNumber'; | ||
import { EventManager } from 'src/cli/EventManager'; | ||
import Profile from 'src/model/Profile'; | ||
|
||
export default class CliProviderImpl implements CliProvider { | ||
|
||
downloadPackage(packageName: string, version: VersionNumber, downloadEventManager: EventManager<CliProgressCallback>, writeToDiskEventManager: EventManager<CliProgressCallback>, successStateManager: EventManager<CliStateCallback>): Promise<void> { | ||
return Promise.reject("Not yet implemented"); | ||
} | ||
|
||
getRequiredPackageUpdates(profile: Profile): Promise<string[]> { | ||
return Promise.reject("Not yet implemented"); | ||
} | ||
|
||
hasPackageExtractedSuccessfully(packageName: string, version: VersionNumber): Promise<boolean> { | ||
return Promise.reject("Not yet implemented"); | ||
} | ||
|
||
installPackage( | ||
packageName: string, | ||
version: VersionNumber, | ||
writeToDiskEventManager: () => EventManager<CliProgressCallback>, | ||
successStateManager: () => EventManager<CliStateCallback>) | ||
: Promise<void> | ||
{ | ||
return Promise.reject("Not yet implemented"); | ||
} | ||
|
||
isPackageInCache(packageName: string, version: VersionNumber): Promise<boolean> { | ||
return Promise.reject("Not yet implemented"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import VersionNumber from 'src/model/VersionNumber'; | ||
import { EventManager } from 'src/cli/EventManager'; | ||
import { CliProgressCallback, CliStateCallback } from 'src/cli/CliProvider'; | ||
import ThunderstorePackages from 'src/r2mm/data/ThunderstorePackages'; | ||
import R2Error from 'src/model/errors/R2Error'; | ||
import axios from 'axios'; | ||
|
||
export default class PackageDownloader { | ||
|
||
public downloadPackage( | ||
packageName: string, | ||
version: VersionNumber, | ||
downloadEventManager: EventManager<CliProgressCallback>, | ||
writeToDiskEventManager: EventManager<CliProgressCallback>, | ||
successStateManager: EventManager<CliStateCallback>) | ||
: void { | ||
|
||
const packageMap = ThunderstorePackages.PACKAGES_MAP; | ||
if (!packageMap.has(packageName)) { | ||
successStateManager.publish({ | ||
finished: false, | ||
error: new R2Error(`${packageName} not found`, `Unable to find package ${packageName}`, 'Refresh the mod list via the settings screen or try again later') | ||
} as CliStateCallback); | ||
return; | ||
} | ||
|
||
const pkg = packageMap.get(packageName)!; | ||
const pkgVersion = pkg.getVersions() | ||
.find(pv => pv.getVersionNumber().isEqualTo(version)); | ||
|
||
if (pkgVersion === undefined) { | ||
successStateManager.publish({ | ||
finished: false, | ||
error: new R2Error(`${packageName}-${version.toString()} not found`, `No version of ${packageName} matching ${version.toString()} was found`, 'Refresh the mod list via the settings screen or try again later') | ||
} as CliStateCallback); | ||
return; | ||
} | ||
|
||
axios.get(pkgVersion.getDownloadUrl(), { | ||
onDownloadProgress: progress => { | ||
downloadEventManager.publish({ | ||
currentBytes: progress.loaded, | ||
totalBytes: progress.total | ||
} as CliProgressCallback); | ||
}, | ||
responseType: 'arraybuffer', | ||
headers: { | ||
'Content-Type': 'application/zip', | ||
'Access-Control-Allow-Origin': '*' | ||
} | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters