update adapter to encrypted format

This commit is contained in:
nicwands
2026-03-02 11:57:30 -05:00
parent 8f86e354c0
commit 036a19bf88
15 changed files with 1167 additions and 118 deletions

View File

@@ -1,5 +1,4 @@
import { BaseNotesAdapter } from '@takerofnotes/plugin-sdk'
import matter from 'gray-matter'
import fs from 'fs/promises'
import path from 'path'
@@ -21,16 +20,13 @@ export default class FileSystemAdapter extends BaseNotesAdapter {
const notes = []
for (const file of files) {
if (!file.endsWith('.md')) continue
if (!file.endsWith('.json')) continue
const fullPath = path.join(this.notesDir, file)
const raw = await fs.readFile(fullPath, 'utf8')
const parsed = matter(raw)
const fileContent = await fs.readFile(fullPath, 'utf8')
const parsedFile = JSON.parse(fileContent)
notes.push({
...parsed.data,
content: parsed.content,
})
notes.push(parsedFile)
}
return notes
@@ -45,21 +41,15 @@ export default class FileSystemAdapter extends BaseNotesAdapter {
}
async delete(id) {
const filePath = path.join(this.notesDir, `${id}.md`)
const filePath = path.join(this.notesDir, `${id}.json`)
await fs.unlink(filePath)
}
async _write(note) {
const filePath = path.join(this.notesDir, `${note.id}.md`)
const filePath = path.join(this.notesDir, `${note.id}.json`)
const fileContent = matter.stringify(note.content, {
id: note.id,
title: note.title,
category: note.category ?? null,
createdAt: note.createdAt,
updatedAt: note.updatedAt,
})
const stringifiedNote = JSON.stringify(note)
await fs.writeFile(filePath, fileContent, 'utf8')
await fs.writeFile(filePath, stringifiedNote, 'utf8')
}
}

View File

@@ -6,7 +6,7 @@ export default definePlugin({
name: 'Filesystem',
description: 'Store notes as markdown files on your local filesystem',
version: '0.1.0',
apiVersion: '0.1.0',
apiVersion: '0.3.1',
configSchema: [
{
key: 'notesDir',