Skip to content

Commit

Permalink
Merge pull request #1829 from ubports/download_rename
Browse files Browse the repository at this point in the history
Download rename
  • Loading branch information
NeoTheThird authored Mar 7, 2021
2 parents a9a4fa7 + ea39581 commit 311e7da
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/core/helpers/asarLibs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const packageInfo = require("../../../package.json");
*/
function asarLibPathHack(lib) {
return packageInfo.package
? path.join(__dirname, "../../../app.asar.unpacked/node_modules/", lib)
? path.join(__dirname, "../../../../app.asar.unpacked/node_modules/", lib)
: lib;
}

Expand Down
10 changes: 8 additions & 2 deletions src/core/plugins/core/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class CorePlugin extends Plugin {
this.cachePath,
this.props.config.codename,
group,
path.basename(file.url)
file.name || path.basename(file.url)
)
})),
(progress, speed) => {
Expand All @@ -130,8 +130,9 @@ class CorePlugin extends Plugin {
this.event.emit("user:write:under", "Downloading");
},
(current, total) => {
if (current > 1)
if (current > 0)
this.log.info(`Downloaded file ${current} of ${total}`);
else this.log.info(`Downloading ${total} files`);
this.event.emit(
"user:write:status",
`${current} of ${total} files downloaded and verified`,
Expand Down Expand Up @@ -208,6 +209,11 @@ class CorePlugin extends Plugin {
);
}

/**
* core:manual_download action
* @param {Object} param0 {group, file}
* @returns {Promise}
*/
action__manual_download({ group, file }) {
return Promise.resolve()
.then(() => {
Expand Down
44 changes: 36 additions & 8 deletions src/core/plugins/core/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,46 @@ describe("core plugin", () => {

describe("action__download()", () => {
it("should download", () =>
core.action__download({
group: "fimrware",
files: [
{ url: "a/c", checksum: { sum: "b", algorithm: "sha256" } },
{ url: "a/b", checksum: { sum: "a", algorithm: "sha256" } }
]
})); // TODO add assertions for event messages
core
.action__download({
group: "firmware",
files: [
{ url: "a/c", checksum: { sum: "b", algorithm: "sha256" } },
{ url: "a/b" },
{ url: "a/c", name: "d" }
]
})
.then(r => {
expect(r).toEqual(undefined);
expect(download).toHaveBeenCalledTimes(1);
expect(download).toHaveBeenCalledWith(
[
{
checksum: { algorithm: "sha256", sum: "b" },
path: expect.stringMatching(/a.yggdrasil.firmware.c/),
url: "a/c"
},
{
path: expect.stringMatching(/a.yggdrasil.firmware.b/),
url: "a/b"
},
{
name: "d",
path: expect.stringMatching(/a.yggdrasil.firmware.d/),
url: "a/c"
}
],
expect.any(Function),
expect.any(Function),
expect.any(Function)
);
expect(mainEvent.emit).toHaveBeenCalledTimes(20);
}));
it("should show network error", done => {
download.mockRejectedValueOnce("download error");
core
.action__download({
group: "fimrware",
group: "firmware",
files: [
{ url: "a/c", checksum: { sum: "b", algorithm: "sha256" } },
{ url: "a/b", checksum: { sum: "a", algorithm: "sha256" } }
Expand Down

0 comments on commit 311e7da

Please sign in to comment.