forked from 1b-agent/opencadstudio-upstream
feat(plugins): redesign plugin manager
This commit is contained in:
1 parent
d80637cda7
commit
4e25e88c31
11 files changed
+741
-74
No files matched your search
@@ -148,6 +148,20 @@ pub fn fetch_releases(repo: &str) -> Result<Vec<Release>, String> {
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Fetch the repository README from its default branch as raw Markdown.
|
||||
pub fn fetch_readme(repo: &str) -> Result<String, String> {
|
||||
let url = format!("https://api.github.com/repos/{repo}/readme");
|
||||
agent()
|
||||
.get(&url)
|
||||
.header("User-Agent", UA)
|
||||
.header("Accept", "application/vnd.github.raw+json")
|
||||
.call()
|
||||
.map_err(|e| e.to_string())?
|
||||
.body_mut()
|
||||
.read_to_string()
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
fn download_string(url: &str) -> Result<String, String> {
|
||||
agent()
|
||||
.get(url)
|
||||
@@ -176,7 +190,7 @@ fn download_bytes(url: &str) -> Result<Vec<u8>, String> {
|
||||
/// Download and install a release's package into the plugins folder. Verifies
|
||||
/// the API version from the package's `plugin.toml` first. Returns the plugin
|
||||
/// id on success.
|
||||
pub fn install(release: &Release) -> Result<String, String> {
|
||||
pub fn install(release: &Release, repository: &str) -> Result<String, String> {
|
||||
let lib = release.lib_asset().ok_or("no library for this platform")?;
|
||||
let toml = release.toml_asset().ok_or("release has no plugin.toml")?;
|
||||
|
||||
@@ -199,6 +213,8 @@ pub fn install(release: &Release) -> Result<String, String> {
|
||||
let bytes = download_bytes(&lib.url)?;
|
||||
replace_library(&dir, &lib.name, external_lib_ext(), &bytes)?;
|
||||
std::fs::write(dir.join("plugin.toml"), toml_text).map_err(|e| e.to_string())?;
|
||||
std::fs::write(dir.join(".source_repo"), format!("{repository}\n"))
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(manifest.id)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user