"""查笔记迁移为什么没生效。""" import base64 import json import sys import time import urllib.error import urllib.request try: sys.stdout.reconfigure(encoding="utf-8", errors="replace") except Exception: pass URL = "http://127.0.0.1:15199" D = "/storage/emulated/0/Android/data/com.doubao.lynxclone/files/tools" def call(path, payload=None, method="POST", timeout=90): data = json.dumps(payload, ensure_ascii=False).encode("utf-8") if payload is not None else None req = urllib.request.Request( URL + path, data=data, method=method, headers={"Content-Type": "application/json; charset=utf-8"}, ) try: with urllib.request.urlopen(req, timeout=timeout) as r: return json.loads(r.read().decode("utf-8")) except urllib.error.HTTPError as e: return json.loads(e.read().decode("utf-8", "replace")) probe = r''' import os, sys, json sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) TOOL = {"name": "probe_nt", "description": "x", "parameters": {"type": "object", "properties": {}}} def run(args): import notes out = {} out["notes_dir"] = notes.notes_dir() out["legacy_dir"] = notes._LEGACY_DIR out["same"] = os.path.abspath(notes.notes_dir()) == notes._LEGACY_DIR out["new_exists"] = os.path.isdir(notes.notes_dir()) try: out["new_files"] = os.listdir(notes.notes_dir()) except Exception as e: out["new_err"] = f"{type(e).__name__}: {e}" out["legacy_exists"] = os.path.isdir(notes._LEGACY_DIR) try: out["legacy_files"] = os.listdir(notes._LEGACY_DIR) except Exception as e: out["legacy_err"] = f"{type(e).__name__}: {e}" marker = os.path.join(notes.notes_dir(), ".migrated") out["marker_exists"] = os.path.exists(marker) # 手动跑一次迁移看报什么 try: notes._migrate_once(notes.notes_dir()) out["migrate_ran"] = True out["new_files_after"] = os.listdir(notes.notes_dir()) except Exception as e: import traceback out["migrate_err"] = f"{type(e).__name__}: {e}" out["migrate_tb"] = traceback.format_exc()[-700:] # paths 里那个值 try: import paths out["paths_notes_dir"] = paths.get().notes_dir except Exception as e: out["paths_err"] = f"{type(e).__name__}: {e}" return out ''' b64 = base64.b64encode(probe.encode("utf-8")).decode() w = ("import base64,os;" "open(os.path.join('%s','probe_nt.py'),'wb').write(base64.b64decode('%s'));" "print('ok')" % (D, b64)) call("/api/tools/run", {"name": "python_run", "args": {"code": w, "timeout": 30}}) time.sleep(1) call("/api/tools", None, "GET") r = call("/api/tools/run", {"name": "probe_nt", "args": {}}) print(json.dumps((r or {}).get("result"), ensure_ascii=False, indent=1)[:1600])