Skip to content

Commit

Permalink
✨ Stashpad note provider
Browse files Browse the repository at this point in the history
  • Loading branch information
homostellaris committed Jul 8, 2024
1 parent e244d1c commit 4cff744
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 31 deletions.
25 changes: 20 additions & 5 deletions components/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,43 @@ import dexieCloud from 'dexie-cloud-addon'
export interface Todo {
createdAt: Date
completedAt?: Date
note?: string // URL
role?: string
note?: Note // URL
role?: Role
starPoints?: string
title: string
}

interface List {
export interface Note {
uri: string
}

export interface Role {
title: string
}

export interface List {
order: string[] // Todo IDs
type: '#important'
}

export interface Setting {
key: string
value: any
}

export class DexieStarfocus extends Dexie {
todos!: Table<Todo>
lists!: Table<List>
settings!: Table<Setting>
todos!: Table<Todo>

constructor() {
super('starfocus', {
addons: [dexieCloud],
})
this.version(1).stores({
this.version(2).stores({
todos: '@id, createdAt, completedAt, title',
lists: 'type',
settings: '&key',
})
this.cloud.configure({
databaseUrl: 'https://zy0myinc2.dexie.cloud',
Expand Down
27 changes: 27 additions & 0 deletions components/notes/providers/Stashpad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { NoteProvider } from '.'

export default class Stashpad extends NoteProvider {
apiKey: string

constructor(apiKey) {
super()
this.apiKey = apiKey
}

create({ content }) {
return fetch('https://api.stashpad.live/v1/docs', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': this.apiKey,
},
body: JSON.stringify({
content,
access: 'public',
permission: 'write',
}),
})
.then(response => response.json())
.then(({ uri }) => uri)
}
}
10 changes: 10 additions & 0 deletions components/notes/providers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
enum NoteProviders {
Stashpad = 'stashpad',
Obsidian = 'obsidian',
}

export abstract class NoteProvider {
abstract create({ content }): Promise<string>
}

export default NoteProviders
12 changes: 12 additions & 0 deletions components/notes/useNoteProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import useSettings from '../settings/useSettings'
import NoteProviders from './providers'
import Stashpad from './providers/Stashpad'

export default function useNoteProvider() {
const noteProviderSettings = useSettings('#noteProvider')

if (noteProviderSettings?.type === NoteProviders.Stashpad) {
return new Stashpad(noteProviderSettings.apiKey)
}
return null
}
Loading

0 comments on commit 4cff744

Please sign in to comment.