initial commit

This commit is contained in:
2026-05-31 14:23:01 +02:00
commit e39fbca087
136 changed files with 58061 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
import { runCommand } from "../utils/process";
import { RmapiNode } from "../types";
import RemarkablePlugin from "../main";
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: this.plugin.app.vault.adapter.getBasePath() + "/.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");
}
}