`;
+ if (rest.length) h += group("", rest.slice(0, 300).map((f) => { const b = bot(f.bot) || {}; return ``; }).join(""));
+ }
+ h += ``;
+ el.innerHTML = h;
+ const qEl = $("lib-q");
+ qEl.oninput = () => { LIB.q = qEl.value; const pos = qEl.selectionStart; drawFiles(el); const n = $("lib-q"); n.focus(); n.setSelectionRange(pos, pos); };
+ el.querySelectorAll("[data-lk]").forEach((b) => b.onclick = () => { LIB.kind = b.dataset.lk; drawFiles(el); });
+ el.querySelectorAll("[data-lf]").forEach((b) => b.onclick = () => openFile(b.dataset.lf, b.dataset.ln));
+ // Thumbnails as they come into view (the brain's own small copies of the pictures).
+ const io = new IntersectionObserver((es) => es.forEach(async (e) => {
+ if (!e.isIntersecting) return;
+ io.unobserve(e.target);
+ try { const r = await api(base() + "api/preview/image?path=" + encodeURIComponent(e.target.dataset.thumb), {raw: true}); if (r.ok) e.target.src = URL.createObjectURL(await safeBlob(r)); } catch (_) {}
+ }), {root: el});
+ el.querySelectorAll("img[data-thumb]").forEach((i) => io.observe(i));
+}
// ---------- 日程 ----------
// What the bots are set to do, as on the computer's 日程: 即將執行 (each routine or workflow once,
// at its next time), then day by day from three days back to a week ahead — what ran on its own
diff --git a/src/app/library_ui.rs b/src/app/library_ui.rs
index 2bcc1e5..f5be264 100644
--- a/src/app/library_ui.rs
+++ b/src/app/library_ui.rs
@@ -60,6 +60,24 @@ pub(super) fn library_kind(name: &str) -> &'static str {
}
impl App {
+ /// 所有檔案 for the phone: the same files, newest first (at most 500).
+ pub(super) fn library_json(&self) -> serde_json::Value {
+ let mut seen = std::collections::HashSet::new();
+ let mut files = vec![];
+ for b in &self.state.bots {
+ for m in b.messages.iter().chain(b.threads.iter().flat_map(|(_, m)| m.iter())) {
+ for a in &m.attachments {
+ if a.path.is_empty() || !seen.insert(a.path.clone()) {
+ continue;
+ }
+ files.push((m.at, serde_json::json!({"name": a.name, "path": a.path, "bot": b.id, "at": m.at, "bytes": a.bytes, "kind": library_kind(&a.name), "there": std::path::Path::new(&a.path).exists(), "image": a.image})));
+ }
+ }
+ }
+ files.sort_by_key(|f| std::cmp::Reverse(f.0));
+ serde_json::json!({"ok": true, "files": files.into_iter().take(500).map(|f| f.1).collect::>()})
+ }
+
fn library_gather(&mut self) {
let mut seen = std::collections::HashSet::new();
let mut files = vec![];
diff --git a/src/app/remote_ui.rs b/src/app/remote_ui.rs
index 8a89cb9..44ef337 100644
--- a/src/app/remote_ui.rs
+++ b/src/app/remote_ui.rs
@@ -1506,7 +1506,7 @@ impl App {
// model and computer, a new chat, regenerate) plus looking and small chat things; making,
// changing or deleting bots, routines, memories, pages and settings stays the owner's.
let admin_ok = match action {
- "detail" | "settings" | "pages" | "search" | "export_bot" | "export_transcript" | "restart_bot" | "react" | "reply" | "resume" | "older" | "workflows" | "schedule" => true,
+ "detail" | "settings" | "pages" | "search" | "export_bot" | "export_transcript" | "restart_bot" | "react" | "reply" | "resume" | "older" | "workflows" | "schedule" | "library" => true,
"bot" => b["key"].as_str() == Some("unread"),
"box" => matches!(b["op"].as_str(), Some("wake" | "disk")),
_ => false,
@@ -1531,6 +1531,8 @@ impl App {
// 工作流 on the phone: each one's steps in order, what starts it, how its runs went, and
// the question it waits on — read here; run, stop, 繼續 and 停止 below.
"workflows" => json!({"ok": true, "workflows": self.state.workflows.iter().map(|w| self.workflow_json(w)).collect::>()}),
+ // 所有檔案 on the phone: every file the chats keep, across bots and conversations.
+ "library" => self.library_json(),
// 日程 on the phone: three days back to a week ahead — what ran on its own and how it
// went, what is coming — and 即將執行 (each thing once, soonest first).
"schedule" => {
@@ -2846,6 +2848,21 @@ mod phone_act_tests {
assert!(app.phone_act(&ctx, "workflow", &json!({"wf": 99, "do": "explode"}), "owner")["error"].is_string());
}
+ /// 所有檔案 on the phone: each attachment once (across bots and past conversations), newest
+ /// first, with its kind and whether it is still there.
+ #[test]
+ fn the_phone_reads_all_files() {
+ let (ctx, mut app) = demo();
+ let b0 = app.state.bots[0].id;
+ let b1 = app.state.bots[1].id;
+ let att = |name: &str, path: &str| crate::attach::Attachment { name: name.into(), path: path.into(), ..Default::default() };
+ app.state.bot_mut(b0).unwrap().messages.push(Message { at: 100, attachments: vec![att("a.png", "/nowhere/a.png")], ..Message::user("") });
+ app.state.bot_mut(b1).unwrap().messages.push(Message { at: 200, attachments: vec![att("b.md", "/nowhere/b.md"), att("a.png", "/nowhere/a.png")], ..Message::user("") });
+ let v = app.phone_act(&ctx, "library", &json!({}), "admin");
+ let files: Vec<(&str, &str, bool)> = v["files"].as_array().unwrap().iter().filter(|f| f["path"].as_str().unwrap_or("").starts_with("/nowhere/")).map(|f| (f["name"].as_str().unwrap(), f["kind"].as_str().unwrap(), f["there"].as_bool().unwrap())).collect();
+ assert_eq!(files, vec![("b.md", "doc", false), ("a.png", "image", false)]);
+ }
+
/// 日程 on the phone: the days around today and 即將執行, each thing once there.
#[test]
fn the_phone_reads_the_schedule() {
diff --git a/src/remote.rs b/src/remote.rs
index c1cf458..d28e9d9 100644
--- a/src/remote.rs
+++ b/src/remote.rs
@@ -1284,9 +1284,9 @@ pub(crate) fn lan_guard(action: &str, body: &Value, now: impl FnOnce() -> Value,
// Looking; chats, pages and memories; bots made, imported (with no tools, grants, team or
// running routines), deleted or restarted; models and keys; skills; signing in to ChatGPT;
// signing a phone out; a workflow looked at, run, stopped or answered (its steps run with
- // the bots' own settings, as when its schedule starts it); the 日程 — none of these
- // moves a guard.
- "search" | "detail" | "settings" | "pages" | "export_bot" | "export_transcript" | "import_bot" | "section_move" | "memory" | "app" | "group_chat" | "delete_bot" | "restart_bot" | "react" | "reply" | "resume" | "clear" | "delete_page" | "provider" | "device_remove" | "skill" | "chatgpt" | "workflows" | "workflow" | "schedule" => Guard::Keeps,
+ // the bots' own settings, as when its schedule starts it); the 日程, 所有檔案 — none of
+ // these moves a guard.
+ "search" | "detail" | "settings" | "pages" | "export_bot" | "export_transcript" | "import_bot" | "section_move" | "memory" | "app" | "group_chat" | "delete_bot" | "restart_bot" | "react" | "reply" | "resume" | "clear" | "delete_page" | "provider" | "device_remove" | "skill" | "chatgpt" | "workflows" | "workflow" | "schedule" | "library" => Guard::Keeps,
// An action this list doesn't name is refused, not let through (import_bot slipped by
// that way with a file's 「team」). A new one has to be put on one side or the other.
_ => Guard::Unknown,