-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
890cec8
commit 95745e5
Showing
7 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,74 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2020-2021 UBports Foundation <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
const axios = require("axios"); | ||
|
||
/** @module asteroid_os */ | ||
|
||
const baseURL = "https://release.asteroidos.org/"; | ||
|
||
const api = axios.create({ baseURL, timeout: 15000 }); | ||
|
||
/** | ||
* get images from api | ||
* @param {String} channel channel | ||
* @param {String} device device codename | ||
* @returns {Promise<Array<Object>>} images array | ||
* @throws {Error} message "no network" if request failed | ||
*/ | ||
const getImages = (channel, device) => | ||
api | ||
.get(`${channel}/${device}/MD5SUMS`) | ||
.then(({ data }) => | ||
data | ||
.trim() | ||
.split("\n") | ||
.map(line => ({ | ||
url: `${baseURL}${channel}/${device}/${line.split(/[ ,]+/)[1]}`, | ||
checksum: { | ||
sum: line.split(/[ ,]+/)[0], | ||
algorithm: "md5" | ||
} | ||
})) | ||
) | ||
.catch(error => { | ||
if (error.response.status === 404) throw new Error("404"); | ||
else if (error.response) throw new Error("no network"); | ||
else throw error; | ||
}); | ||
|
||
/** | ||
* get channels from api | ||
* @param {String} device device codename | ||
* @returns {Promise<Array<String>>} channels | ||
* @throws {Error} message "unsupported" if 404 not found | ||
*/ | ||
const getChannels = device => | ||
Promise.all( | ||
["1.0", "nightlies", "1.0-alpha"].map(channel => | ||
getImages(channel, device) | ||
.then(() => channel) | ||
.catch(error => { | ||
if (error.message === "404") return null; | ||
else throw error; | ||
}) | ||
) | ||
).then(channels => channels.filter(c => c)); | ||
|
||
module.exports = { getImages, getChannels }; |
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,7 @@ | ||
process.argv = [null, null, "-vv"]; | ||
const { ipcMain } = require("electron"); | ||
jest.mock("electron"); | ||
|
||
const api = require("./api.js"); | ||
|
||
it("should construct", () => expect(require("./api.js")).toBeDefined()); |
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,63 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2020-2021 UBports Foundation <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
const Plugin = require("../plugin.js"); | ||
const api = require("./api.js"); | ||
|
||
/** | ||
* Asteroid OS plugin | ||
* @extends Plugin | ||
*/ | ||
class AsteroidOsPlugin extends Plugin { | ||
/** | ||
* action download | ||
* @returns {Promise<Array<Object>>} | ||
*/ | ||
action__download() { | ||
return api | ||
.getImages(this.props.settings.channel, this.props.config.codename) | ||
.then(files => [ | ||
{ | ||
actions: [ | ||
{ | ||
"core:download": { | ||
group: "AsteroidOS", | ||
files | ||
} | ||
} | ||
] | ||
} | ||
]); | ||
} | ||
|
||
/** | ||
* channels remote_values | ||
* @returns {Promise<Array<Object>>} | ||
*/ | ||
remote_values__channels() { | ||
return api.getChannels(this.props.config.codename).then(channels => | ||
channels.map(channel => ({ | ||
value: channel, | ||
label: channel | ||
})) | ||
); | ||
} | ||
} | ||
|
||
module.exports = AsteroidOsPlugin; |
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,4 @@ | ||
const systemimage = require("./plugin.js"); | ||
|
||
it("should be a singleton", () => | ||
expect(systemimage).toEqual(require("./plugin.js"))); |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2020 UBports Foundation <[email protected]> | ||
* Copyright (C) 2020-2021 UBports Foundation <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -18,6 +18,7 @@ | |
*/ | ||
|
||
const AdbPlugin = require("./adb/plugin.js"); | ||
const AsteroidOsPlugin = require("./asteroid_os/plugin.js"); | ||
const CorePlugin = require("./core/plugin.js"); | ||
const FastbootPlugin = require("./fastboot/plugin.js"); | ||
const HeimdallPlugin = require("./heimdall/plugin.js"); | ||
|
@@ -28,6 +29,7 @@ const SystemimagePlugin = require("./systemimage/plugin.js"); | |
* @property {Props} props props reference | ||
* @property {Object} plugins plugins namespace | ||
* @property {AdbPlugin} plugins.adb adb plugin | ||
* @property {AsteroidOsPlugin} plugins.asteroid_os AteroidOS plugin | ||
* @property {CorePlugin} plugins.core core plugin | ||
* @property {FastbootPlugin} plugins.fastboot fastboot plugin | ||
* @property {HeimdallPlugin} plugins.heimdall heimdall plugin | ||
|
@@ -40,6 +42,7 @@ class PluginIndex { | |
const pluginArgs = [props, cachePath, mainEvent, log]; | ||
this.plugins = { | ||
adb: new AdbPlugin(...pluginArgs), | ||
asteroid_os: new AsteroidOsPlugin(...pluginArgs), | ||
core: new CorePlugin(...pluginArgs), | ||
fastboot: new FastbootPlugin(...pluginArgs), | ||
heimdall: new HeimdallPlugin(...pluginArgs), | ||
|