fix(ext): mirror fallback for Release downloads and default ~/.marqdo/ext
Try proxy.cflmy.top when github.com fails; honor MARQDO_EXT_DOWNLOAD_BASE; resolve ext imports from the ext-add install root without exporting MARQDO_EXT. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3287799959
commit
6324036e41
4 files changed
+103
-22
No files matched your search
@@ -3,8 +3,10 @@
|
|||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
- `ext add` 下载:GitHub 失败后自动回退 `https://proxy.cflmy.top/github.com/…`;可用 `MARQDO_EXT_DOWNLOAD_BASE` 指定首选镜像;加长读写超时。
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
- `ext/` 导入默认搜索 `~/.marqdo/ext`(与 `marqdo ext add` 安装根一致),无需再手动 `export MARQDO_EXT`。
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -53,8 +53,11 @@ L1 sources:
|
|||||||
|----------|---------|
|
|----------|---------|
|
||||||
| `MARQDO_EXT_VERSION` | Override SemVer used for Release asset names (default: CLI `CARGO_PKG_VERSION`) |
|
| `MARQDO_EXT_VERSION` | Override SemVer used for Release asset names (default: CLI `CARGO_PKG_VERSION`) |
|
||||||
| `MARQDO_EXT_NO_DOWNLOAD=1` | Never hit the network (CI / air-gap); local/cargo only |
|
| `MARQDO_EXT_NO_DOWNLOAD=1` | Never hit the network (CI / air-gap); local/cargo only |
|
||||||
|
| `MARQDO_EXT_DOWNLOAD_BASE` | Optional mirror base tried **first** (e.g. `https://proxy.cflmy.top/github.com` or a flat asset dir) |
|
||||||
| `MARQDO_WEB_PLUGIN` / `MARQDO_AGENT_PLUGIN` / `MARQDO_QUANTUM_PLUGIN` | Explicit native path |
|
| `MARQDO_WEB_PLUGIN` / `MARQDO_AGENT_PLUGIN` / `MARQDO_QUANTUM_PLUGIN` | Explicit native path |
|
||||||
|
|
||||||
|
Download order for each Release asset: `MARQDO_EXT_DOWNLOAD_BASE` (if set) → `github.com` → **`https://proxy.cflmy.top/github.com/…`** fallback. Connect timeout 20s; read timeout 10min so large native zips can finish on slow links.
|
||||||
|
|
||||||
Windows Release **zip** also ships `ext/` + `ext/native/*.dll` next to `marqdo.exe` so a portable unzip works offline after one download.
|
Windows Release **zip** also ships `ext/` + `ext/native/*.dll` next to `marqdo.exe` so a portable unzip works offline after one download.
|
||||||
|
|
||||||
## Source for `add` (developers)
|
## Source for `add` (developers)
|
||||||
|
|||||||
+80
-17
@@ -2,15 +2,22 @@
|
|||||||
//!
|
//!
|
||||||
//! Enables `marqdo ext add web` without a local Rust toolchain or repo checkout.
|
//! Enables `marqdo ext add web` without a local Rust toolchain or repo checkout.
|
||||||
//! Disable with `MARQDO_EXT_NO_DOWNLOAD=1`. Override tag with `MARQDO_EXT_VERSION=0.3.4`.
|
//! Disable with `MARQDO_EXT_NO_DOWNLOAD=1`. Override tag with `MARQDO_EXT_VERSION=0.3.4`.
|
||||||
|
//!
|
||||||
|
//! When GitHub is unreachable, downloads automatically fall back to the project
|
||||||
|
//! reverse proxy (`https://proxy.cflmy.top/github.com/…`). Override the candidate
|
||||||
|
//! list with `MARQDO_EXT_DOWNLOAD_BASE` (tried first).
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
|
|
||||||
const REPO: &str = "cflmy/marqdo";
|
const REPO: &str = "cflmy/marqdo";
|
||||||
|
/// HTTPS reverse proxy used when github.com is slow or blocked (same as git origin).
|
||||||
|
const GITHUB_MIRROR_PREFIX: &str = "https://proxy.cflmy.top/github.com";
|
||||||
|
|
||||||
pub fn downloads_enabled() -> bool {
|
pub fn downloads_enabled() -> bool {
|
||||||
match env::var("MARQDO_EXT_NO_DOWNLOAD") {
|
match env::var("MARQDO_EXT_NO_DOWNLOAD") {
|
||||||
@@ -61,13 +68,46 @@ fn user_agent() -> String {
|
|||||||
format!("marqdo/{}", env!("CARGO_PKG_VERSION"))
|
format!("marqdo/{}", env!("CARGO_PKG_VERSION"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn http_agent() -> ureq::Agent {
|
||||||
|
ureq::AgentBuilder::new()
|
||||||
|
.timeout_connect(Duration::from_secs(20))
|
||||||
|
.timeout_read(Duration::from_secs(600))
|
||||||
|
.user_agent(&user_agent())
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Candidate download URLs: optional `MARQDO_EXT_DOWNLOAD_BASE`, GitHub, then proxy mirror.
|
||||||
|
pub fn release_asset_urls(ver: &str, filename: &str) -> Vec<String> {
|
||||||
|
let mut urls = Vec::new();
|
||||||
|
if let Ok(base) = env::var("MARQDO_EXT_DOWNLOAD_BASE") {
|
||||||
|
let base = base.trim().trim_end_matches('/');
|
||||||
|
if !base.is_empty() {
|
||||||
|
// Flexible bases: full github path prefix, repo root, or flat asset dir.
|
||||||
|
urls.push(format!(
|
||||||
|
"{base}/{REPO}/releases/download/v{ver}/{filename}"
|
||||||
|
));
|
||||||
|
urls.push(format!("{base}/releases/download/v{ver}/{filename}"));
|
||||||
|
urls.push(format!("{base}/v{ver}/{filename}"));
|
||||||
|
urls.push(format!("{base}/{filename}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
urls.push(format!(
|
||||||
|
"https://github.com/{REPO}/releases/download/v{ver}/{filename}"
|
||||||
|
));
|
||||||
|
urls.push(format!(
|
||||||
|
"{GITHUB_MIRROR_PREFIX}/{REPO}/releases/download/v{ver}/{filename}"
|
||||||
|
));
|
||||||
|
let mut seen = std::collections::HashSet::new();
|
||||||
|
urls.into_iter().filter(|u| seen.insert(u.clone())).collect()
|
||||||
|
}
|
||||||
|
|
||||||
fn download_to_file(url: &str, dest: &Path) -> Result<()> {
|
fn download_to_file(url: &str, dest: &Path) -> Result<()> {
|
||||||
if let Some(parent) = dest.parent() {
|
if let Some(parent) = dest.parent() {
|
||||||
fs::create_dir_all(parent)?;
|
fs::create_dir_all(parent)?;
|
||||||
}
|
}
|
||||||
let tmp = dest.with_extension("download-tmp");
|
let tmp = dest.with_extension("download-tmp");
|
||||||
let resp = ureq::get(url)
|
let resp = http_agent()
|
||||||
.set("User-Agent", &user_agent())
|
.get(url)
|
||||||
.set("Accept", "application/octet-stream")
|
.set("Accept", "application/octet-stream")
|
||||||
.call()
|
.call()
|
||||||
.with_context(|| format!("GET {url}"))?;
|
.with_context(|| format!("GET {url}"))?;
|
||||||
@@ -86,6 +126,30 @@ fn download_to_file(url: &str, dest: &Path) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn download_first_ok(urls: &[String], dest: &Path) -> Result<()> {
|
||||||
|
let mut errors: Vec<String> = Vec::new();
|
||||||
|
for (i, url) in urls.iter().enumerate() {
|
||||||
|
if i == 0 {
|
||||||
|
println!("downloading ({url})…");
|
||||||
|
} else {
|
||||||
|
println!("retry via mirror ({url})…");
|
||||||
|
}
|
||||||
|
match download_to_file(url, dest) {
|
||||||
|
Ok(()) => return Ok(()),
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("note: {e:#}");
|
||||||
|
errors.push(format!("{url} → {e:#}"));
|
||||||
|
let _ = fs::remove_file(dest.with_extension("download-tmp"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bail!(
|
||||||
|
"all download mirrors failed for {}:\n - {}",
|
||||||
|
dest.file_name().and_then(|s| s.to_str()).unwrap_or("asset"),
|
||||||
|
errors.join("\n - ")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn extract_zip(zip_path: &Path, dest_dir: &Path) -> Result<()> {
|
fn extract_zip(zip_path: &Path, dest_dir: &Path) -> Result<()> {
|
||||||
fs::create_dir_all(dest_dir)?;
|
fs::create_dir_all(dest_dir)?;
|
||||||
let file = File::open(zip_path).with_context(|| format!("open {}", zip_path.display()))?;
|
let file = File::open(zip_path).with_context(|| format!("open {}", zip_path.display()))?;
|
||||||
@@ -121,10 +185,6 @@ fn extract_zip(zip_path: &Path, dest_dir: &Path) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn release_asset_url(ver: &str, filename: &str) -> String {
|
|
||||||
format!("https://github.com/{REPO}/releases/download/v{ver}/{filename}")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ensure L1 `ext/` tree is available (repo checkout or downloaded Release zip).
|
/// Ensure L1 `ext/` tree is available (repo checkout or downloaded Release zip).
|
||||||
/// Returns a directory that contains `web/web.mq.md`, `ai/…`, etc.
|
/// Returns a directory that contains `web/web.mq.md`, `ai/…`, etc.
|
||||||
pub fn ensure_ext_source_tree() -> Result<PathBuf> {
|
pub fn ensure_ext_source_tree() -> Result<PathBuf> {
|
||||||
@@ -143,10 +203,9 @@ pub fn ensure_ext_source_tree() -> Result<PathBuf> {
|
|||||||
bail!("extension sources not found and downloads disabled (MARQDO_EXT_NO_DOWNLOAD)");
|
bail!("extension sources not found and downloads disabled (MARQDO_EXT_NO_DOWNLOAD)");
|
||||||
}
|
}
|
||||||
let zip_name = format!("marqdo-{ver}-ext.zip");
|
let zip_name = format!("marqdo-{ver}-ext.zip");
|
||||||
let url = release_asset_url(&ver, &zip_name);
|
let urls = release_asset_urls(&ver, &zip_name);
|
||||||
let zip_path = cache_root()?.join(&zip_name);
|
let zip_path = cache_root()?.join(&zip_name);
|
||||||
println!("downloading official ext sources ({url})…");
|
download_first_ok(&urls, &zip_path)?;
|
||||||
download_to_file(&url, &zip_path)?;
|
|
||||||
let stage = cache_root()?.join(format!("ext-src-v{ver}-extract"));
|
let stage = cache_root()?.join(format!("ext-src-v{ver}-extract"));
|
||||||
if stage.exists() {
|
if stage.exists() {
|
||||||
let _ = fs::remove_dir_all(&stage);
|
let _ = fs::remove_dir_all(&stage);
|
||||||
@@ -206,7 +265,7 @@ pub fn download_native_plugin(short: &str, lib_name: &str) -> Result<PathBuf> {
|
|||||||
};
|
};
|
||||||
let ver = release_version();
|
let ver = release_version();
|
||||||
let zip_name = format!("marqdo-{ver}-native-{triple}.zip");
|
let zip_name = format!("marqdo-{ver}-native-{triple}.zip");
|
||||||
let url = release_asset_url(&ver, &zip_name);
|
let urls = release_asset_urls(&ver, &zip_name);
|
||||||
let cache = cache_root()?.join(format!("native-v{ver}-{triple}"));
|
let cache = cache_root()?.join(format!("native-v{ver}-{triple}"));
|
||||||
let lib_in_cache = cache.join("native").join(lib_name);
|
let lib_in_cache = cache.join("native").join(lib_name);
|
||||||
if lib_in_cache.is_file() {
|
if lib_in_cache.is_file() {
|
||||||
@@ -218,11 +277,11 @@ pub fn download_native_plugin(short: &str, lib_name: &str) -> Result<PathBuf> {
|
|||||||
return Ok(flat);
|
return Ok(flat);
|
||||||
}
|
}
|
||||||
let zip_path = cache_root()?.join(&zip_name);
|
let zip_path = cache_root()?.join(&zip_name);
|
||||||
println!("downloading prebuilt native plugins ({url})…");
|
download_first_ok(&urls, &zip_path).with_context(|| {
|
||||||
download_to_file(&url, &zip_path).with_context(|| {
|
|
||||||
format!(
|
format!(
|
||||||
"failed to download prebuilt plugins for {triple}. \
|
"failed to download prebuilt plugins for {triple}. \
|
||||||
Build locally with `cargo build --release -p marqdo_plugin_{short}`, \
|
Set MARQDO_EXT_DOWNLOAD_BASE to a reachable mirror, build locally \
|
||||||
|
(`bash ./scripts/build-web-plugin.sh` for web), \
|
||||||
or check https://github.com/{REPO}/releases/tag/v{ver}"
|
or check https://github.com/{REPO}/releases/tag/v{ver}"
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
@@ -283,11 +342,15 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn asset_url_shape() {
|
fn asset_urls_include_github_and_mirror() {
|
||||||
let u = release_asset_url("0.3.4", "marqdo-0.3.4-ext.zip");
|
let u = release_asset_urls("1.0.2", "marqdo-1.0.2-ext.zip");
|
||||||
|
assert!(u.iter().any(|x| x.contains("github.com/cflmy/marqdo")));
|
||||||
|
assert!(u
|
||||||
|
.iter()
|
||||||
|
.any(|x| x.contains("proxy.cflmy.top/github.com/cflmy/marqdo")));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
u,
|
u[0],
|
||||||
"https://github.com/cflmy/marqdo/releases/download/v0.3.4/marqdo-0.3.4-ext.zip"
|
"https://github.com/cflmy/marqdo/releases/download/v1.0.2/marqdo-1.0.2-ext.zip"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-5
@@ -140,10 +140,18 @@ pub fn resolve_import(from_dir: &Path, rel: &str) -> Result<PathBuf> {
|
|||||||
"cannot resolve import `{rel}` from {}",
|
"cannot resolve import `{rel}` from {}",
|
||||||
from_dir.display()
|
from_dir.display()
|
||||||
);
|
);
|
||||||
if env::var_os("MARQDO_EXT").is_none() {
|
let user_ext = crate::ext_cli::default_user_ext_dir();
|
||||||
msg.push_str(
|
if env::var_os("MARQDO_EXT").is_none() && !user_ext.join("web").join("web.mq.md").is_file()
|
||||||
"\nhint: set MARQDO_EXT to the directory that contains web/ (or run `marqdo ext add web`)",
|
{
|
||||||
);
|
msg.push_str(&format!(
|
||||||
|
"\nhint: run `marqdo ext add web` (installs under {}), or set MARQDO_EXT",
|
||||||
|
user_ext.display()
|
||||||
|
));
|
||||||
|
} else if env::var_os("MARQDO_EXT").is_none() {
|
||||||
|
msg.push_str(&format!(
|
||||||
|
"\nhint: looked under {}; set MARQDO_EXT to override",
|
||||||
|
user_ext.display()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
bail!("{msg}");
|
bail!("{msg}");
|
||||||
}
|
}
|
||||||
@@ -194,6 +202,8 @@ fn ext_search_roots() -> Vec<PathBuf> {
|
|||||||
if let Ok(h) = env::var("MARQDO_EXT") {
|
if let Ok(h) = env::var("MARQDO_EXT") {
|
||||||
roots.push(PathBuf::from(h));
|
roots.push(PathBuf::from(h));
|
||||||
}
|
}
|
||||||
|
// Default install root from `marqdo ext add` (~/.marqdo/ext)
|
||||||
|
roots.push(crate::ext_cli::default_user_ext_dir());
|
||||||
if let Ok(cwd) = env::current_dir() {
|
if let Ok(cwd) = env::current_dir() {
|
||||||
roots.push(cwd.join("ext"));
|
roots.push(cwd.join("ext"));
|
||||||
}
|
}
|
||||||
@@ -318,7 +328,10 @@ mod tests {
|
|||||||
"{msg}"
|
"{msg}"
|
||||||
);
|
);
|
||||||
assert!(
|
assert!(
|
||||||
msg.contains("hint: set MARQDO_EXT to the directory that contains web/"),
|
msg.contains("hint:")
|
||||||
|
&& (msg.contains("marqdo ext add")
|
||||||
|
|| msg.contains("MARQDO_EXT")
|
||||||
|
|| msg.contains(".marqdo/ext")),
|
||||||
"{msg}"
|
"{msg}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user