* Query the client for roots and update allowedLocalDirs with any file:// roots * that point to existing directories.
(server: Server)
| 952 | * that point to existing directories. |
| 953 | */ |
| 954 | async function refreshRoots(server: Server): Promise<void> { |
| 955 | if (!server.getClientCapabilities()?.roots) return; |
| 956 | |
| 957 | try { |
| 958 | const { roots } = await server.listRoots(); |
| 959 | allowedLocalDirs.clear(); |
| 960 | for (const root of roots) { |
| 961 | if (isFileUrl(root.uri)) { |
| 962 | const dir = fileUrlToPath(root.uri); |
| 963 | const resolved = path.resolve(dir); |
| 964 | try { |
| 965 | const s = fs.statSync(resolved); |
| 966 | if (s.isFile()) { |
| 967 | console.error( |
| 968 | `[pdf-server] Root is a file, not a directory (skipped): ${resolved}`, |
| 969 | ); |
| 970 | allowedLocalFiles.add(resolved); |
| 971 | } else if (s.isDirectory()) { |
| 972 | allowedLocalDirs.add(resolved); |
| 973 | console.error(`[pdf-server] Root directory allowed: ${resolved}`); |
| 974 | } |
| 975 | } catch { |
| 976 | // stat failed — skip non-existent roots |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 | } catch (err) { |
| 981 | console.error( |
| 982 | `[pdf-server] Failed to list roots: ${err instanceof Error ? err.message : err}`, |
| 983 | ); |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | // ============================================================================= |
| 988 | // PDF Form Field Extraction |
no test coverage detected
searching dependent graphs…