mac csc link

This commit is contained in:
nicwands
2026-02-25 21:37:51 -05:00
parent d21076a785
commit 949f14f0e1
14 changed files with 3035 additions and 1171 deletions

View File

@@ -1,9 +1,9 @@
"use strict";
const utils = require("@electron-toolkit/utils");
const electron = require("electron");
const path = require("path");
const filesystemPlugin = require("takerofnotes-plugin-filesystem");
const fs = require("fs/promises");
const matter = require("gray-matter");
const path = require("path");
const flexsearch = require("flexsearch");
const crypto = require("crypto");
class PluginRegistry {
@@ -23,96 +23,28 @@ class PluginRegistry {
return Array.from(this.plugins.values());
}
}
class BaseNotesAdapter {
constructor(config = {}) {
this.config = config;
}
async init() {
throw new Error("init() not implemented");
}
async getAll() {
throw new Error("getAll() not implemented");
}
async create(note) {
throw new Error("create() not implemented");
}
async update(note) {
throw new Error("update() not implemented");
}
async delete(id) {
throw new Error("delete() not implemented");
}
}
class FileSystemNotesAdapter extends BaseNotesAdapter {
constructor(config) {
super();
for (const field in config) {
this[field] = config[field];
}
}
async init() {
await fs.mkdir(this.notesDir, { recursive: true });
}
async getAll() {
const files = await fs.readdir(this.notesDir);
const notes = [];
for (const file of files) {
if (!file.endsWith(".md")) continue;
const fullPath = path.join(this.notesDir, file);
const raw = await fs.readFile(fullPath, "utf8");
const parsed = matter(raw);
notes.push({
...parsed.data,
content: parsed.content
});
}
return notes;
}
async create(note) {
await this._write(note);
}
async update(note) {
await this._write(note);
}
async delete(id) {
const filePath = path.join(this.notesDir, `${id}.md`);
await fs.unlink(filePath);
}
async _write(note) {
const filePath = path.join(this.notesDir, `${note.id}.md`);
const fileContent = matter.stringify(note.content, {
id: note.id,
title: note.title,
category: note.category ?? null,
createdAt: note.createdAt,
updatedAt: note.updatedAt
});
await fs.writeFile(filePath, fileContent, "utf8");
}
}
const filesystemPlugin = {
id: "filesystem",
name: "Local Filesystem",
description: "Stores notes as markdown files locally.",
version: "1.0.0",
configSchema: [
{
key: "notesDir",
label: "Notes Directory",
type: "directory",
default: path.join(electron.app.getPath("userData"), "notes"),
required: true
}
],
createAdapter(config) {
return new FileSystemNotesAdapter(config);
}
};
const USER_DATA_STRING = "__DEFAULT_USER_DATA__";
class PluginConfig {
constructor(defaultPlugin) {
this.defaultPlugin = defaultPlugin;
this.configPath = path.join(electron.app.getPath("userData"), "config.json");
}
// Helper to replace placeholders with dynamic values, recursively
_resolveDefaults(config) {
if (Array.isArray(config)) {
return config.map((item) => this._resolveDefaults(item));
} else if (config && typeof config === "object") {
const resolved = {};
for (const [key, value] of Object.entries(config)) {
resolved[key] = this._resolveDefaults(value);
}
return resolved;
} else if (typeof config === "string" && config.includes(USER_DATA_STRING)) {
return config.replace(USER_DATA_STRING, electron.app.getPath("userData"));
} else {
return config;
}
}
async load() {
let parsed;
try {
@@ -131,15 +63,21 @@ class PluginConfig {
adapterConfig: defaultConfig
};
await this.write(parsed);
} else {
parsed.adapterConfig = this._resolveDefaults(parsed.adapterConfig);
}
return parsed;
}
async write(configObject) {
const dir = path.dirname(this.configPath);
await fs.mkdir(dir, { recursive: true });
const resolvedConfig = {
...configObject,
adapterConfig: this._resolveDefaults(configObject.adapterConfig)
};
await fs.writeFile(
this.configPath,
JSON.stringify(configObject, null, 2),
JSON.stringify(resolvedConfig, null, 2),
"utf8"
);
}
@@ -297,7 +235,7 @@ electron.app.whenReady().then(async () => {
createNoteWindow(noteId);
});
const registry = new PluginRegistry();
registry.register(filesystemPlugin);
registry.register(filesystemPlugin.default);
const config = await new PluginConfig(filesystemPlugin).load();
const plugin = registry.get(config.activeAdapter);
const adapter = plugin.createAdapter(config.adapterConfig);