49278723b1
- Use Node filesystem APIs instead of shell commands for temp cleanup - Add absolute path helpers for cross-platform compatibility - Generate both main.js and dist/main.js artifacts - Improve error handling in document downloader - Track additional document metadata in sync tracker - Replace Unix-specific `find` with recursive directory traversal The build system now generates two output files (main.js and dist/main.js) for better compatibility with Obsidian's plugin loading. Path handling has been centralized in new utilities to ensure cross-platform behavior, replacing shell commands that had Windows compatibility issues.
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import { runCommand } from "../utils/process";
|
|
import { RmapiNode } from "../types";
|
|
import RemarkablePlugin from "../main";
|
|
import { join } from "path";
|
|
import { getVaultBasePath } from "../utils/paths";
|
|
|
|
export class RmapiBridge {
|
|
plugin: RemarkablePlugin;
|
|
|
|
constructor(plugin: RemarkablePlugin) {
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
private getEnv(): Record<string, string> {
|
|
return {
|
|
RMAPI_HOST: this.plugin.settings.remarkableHost,
|
|
RMAPI_CONFIG: join(getVaultBasePath(this.plugin), ".obsidian", "rmapi"),
|
|
};
|
|
}
|
|
|
|
async runRmapi(args: string[]): Promise<{ stdout: string; stderr: string; code: number }> {
|
|
return runCommand(this.plugin.settings.rmapiBinaryPath, args, this.getEnv());
|
|
}
|
|
|
|
async list(path: string = "/"): Promise<RmapiNode[]> {
|
|
// flags must come before positional args for Go's flag parser
|
|
const { stdout, stderr, code } = await this.runRmapi(["ls", "--json", path]);
|
|
if (code !== 0) {
|
|
throw new Error(`rmapi ls failed: ${stderr || stdout}`);
|
|
}
|
|
try {
|
|
return JSON.parse(stdout) as RmapiNode[];
|
|
} catch (e) {
|
|
throw new Error(`Failed to parse rmapi output: ${e}`);
|
|
}
|
|
}
|
|
|
|
async downloadFile(remotePath: string, localPath: string): Promise<void> {
|
|
const { stdout, stderr, code } = await this.runRmapi(["get", remotePath, "-o", localPath]);
|
|
if (code !== 0) {
|
|
throw new Error(`rmapi get failed: ${stderr || stdout}`);
|
|
}
|
|
}
|
|
|
|
async downloadAnnotatedPdf(remotePath: string, localPath: string): Promise<void> {
|
|
const { stdout, stderr, code } = await this.runRmapi(["geta", remotePath, "-o", localPath]);
|
|
if (code !== 0) {
|
|
throw new Error(`rmapi geta failed: ${stderr || stdout}`);
|
|
}
|
|
}
|
|
|
|
async isAuthenticated(): Promise<boolean> {
|
|
const { code, stderr } = await this.runRmapi(["ls", "--json", "/"]);
|
|
// rmapi returns auth errors on stderr
|
|
return code === 0 && !stderr.includes("auth") && !stderr.includes("register");
|
|
}
|
|
}
|