mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-01 22:36:51 -06:00
M8: Opening a file contacts no team library server it names until you check it (#1621)
* M8: opening a file contacts no team library server it names until you check it (#1097) * M8: translate the team library check strings (#1097) * M8: the Assets panel library test checks what allows a library, without its own fake link (Sonar duplication and coverage)
This commit is contained in:
@@ -85,6 +85,13 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
false,
|
||||
updates
|
||||
),
|
||||
spec!(
|
||||
"library.check",
|
||||
"Check team libraries for updates",
|
||||
"{library? (an enabled team library: id, name or link; all of this file's when omitted)} asks their servers for the latest version in the background, and from then on checks them by themselves: opening a file doesn't contact the server of a team library you haven't added or checked → {checking}",
|
||||
false,
|
||||
check
|
||||
),
|
||||
spec!(
|
||||
"library.acceptUpdates",
|
||||
"Accept library updates",
|
||||
@@ -524,6 +531,10 @@ fn add(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let raw = req_string(cmd, p, "path")?;
|
||||
let path = if is_server_link(&raw) { raw.trim().to_string() } else { absolute_path(raw.trim()) };
|
||||
let lib = s.load_library(&path)?;
|
||||
if is_server_link(&path) {
|
||||
// Added by you: its server may be checked for updates from now on (#1097).
|
||||
s.allow_library(&path);
|
||||
}
|
||||
let m = &lib.manifest;
|
||||
let doc = s.doc()?;
|
||||
if doc.published.as_ref().is_some_and(|me| me.manifest.id == m.id) {
|
||||
@@ -549,6 +560,27 @@ fn add(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// `library.check`: the user lets this file's team libraries (or one) be checked; they are asked now.
|
||||
fn check(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "library.check";
|
||||
let doc = s.doc()?;
|
||||
let links: Vec<String> = match string(p, "library") {
|
||||
Some(key) => {
|
||||
let l = find_link(doc, &key).ok_or_else(|| bad(cmd, format!("no enabled library `{key}` (library.list shows them)")))?;
|
||||
if !is_server_link(&l.path) {
|
||||
return Err(bad(cmd, format!("`{key}` is a library file, not a team library on a server")));
|
||||
}
|
||||
vec![l.path.clone()]
|
||||
}
|
||||
None => doc.libraries.enabled.iter().filter(|l| is_server_link(&l.path)).map(|l| l.path.clone()).collect(),
|
||||
};
|
||||
for l in &links {
|
||||
s.allow_library(l);
|
||||
}
|
||||
s.refresh_server_libraries();
|
||||
Ok(json!({"checking": links.len()}))
|
||||
}
|
||||
|
||||
fn remove(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "library.remove";
|
||||
let key = req_string(cmd, p, "id")?;
|
||||
|
||||
Reference in New Issue
Block a user