Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

chore improve obsidian cron thing

Louis Beaumont43e216055a4c
diff --git a/pipes/obsidian/src/app/api/settings/route.ts b/pipes/obsidian/src/app/api/settings/route.ts
index 6d4eba189..cb562eb55 100644
--- a/pipes/obsidian/src/app/api/settings/route.ts
+++ b/pipes/obsidian/src/app/api/settings/route.ts
@@ -1,36 +1,34 @@
// app/api/settings/route.ts
import { pipe } from "@screenpipe/js";
import { NextResponse } from "next/server";
-import type { Settings } from "@screenpipe/js";
import { promises as fs } from "fs";
import path from "path";
+import os from "os";
// Force Node.js runtime
export const runtime = "nodejs"; // Add this line
export const dynamic = "force-dynamic";
const DEFAULT_INTERVAL_MINUTES = 5;
+function getAppDataDir(): string {
+ const homeDir = os.homedir();
+ return path.join(homeDir, ".screenpipe");
+}
+
async function updateCronSchedule(intervalMinutes: number) {
try {
- const screenpipeDir = process.env.SCREENPIPE_DIR || process.cwd();
+ const screenpipeDir = process.env.SCREENPIPE_DIR || getAppDataDir();
const pipeConfigPath = path.join(
screenpipeDir,
"pipes",
"obsidian",
"pipe.json"
);
- const settingsPath = path.join(
- screenpipeDir,
- "pipes",
- "obsidian",
- "settings.json"
- );
console.log(`updating cron schedule at: ${pipeConfigPath}`);
// Load or initialize both configs
let config: any = {};
- let settings: any = {};
try {
const content = await fs.readFile(pipeConfigPath, "utf8");
@@ -42,20 +40,6 @@ async function updateCronSchedule(intervalMinutes: number) {
config = { crons: [] };
}
- try {
- const settingsContent = await fs.readFile(settingsPath, "utf8");
- settings = JSON.parse(settingsContent);
- } catch (err) {
- console.log(
- `no existing settings found, creating new one at ${settingsPath}`
- );
- settings = { interval: intervalMinutes * 60000 };
- }
-
- // Update settings
- settings.interval = intervalMinutes * 60000;
- await fs.writeFile(settingsPath, JSON.stringify(settings, null, 2));
-
// Update cron config
config.crons = [
{
@@ -84,7 +68,7 @@ export async function GET() {
}
// Load persisted settings if they exist
- const screenpipeDir = process.env.SCREENPIPE_DIR || process.cwd();
+ const screenpipeDir = process.env.SCREENPIPE_DIR || getAppDataDir();
const settingsPath = path.join(
screenpipeDir,
"pipes",