Skip to content

Commit 3a2f1fb

Browse files
committed
feat(api): add controller to get snippets with folder
1 parent 3724a5b commit 3a2f1fb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/services/api/server.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { store } from '../../store'
33
import { nanoid } from 'nanoid'
44
import { API_PORT } from '../../config'
55
import path from 'path'
6-
import type { DB, Snippet, Tag } from '@shared/types/main/db'
6+
import type { DB, Folder, Snippet, Tag } from '@shared/types/main/db'
77
import type { Server } from 'http'
88
import type { Socket } from 'net'
99
import { remove } from 'lodash'
10+
import type { SnippetWithFolder } from '@shared/types/renderer/store/snippets'
1011

1112
interface ServerWithDestroy extends Server {
1213
destroy: Function
@@ -50,6 +51,20 @@ export class ApiServer {
5051
}
5152
})
5253

54+
app.get('/snippets/embed-folder', (req, res) => {
55+
const snippets = router.db.get<SnippetWithFolder[]>('snippets').value()
56+
57+
const result = snippets.map(i => {
58+
const folder = router.db
59+
.get<Folder[]>('folders')
60+
.find(f => f.id === i.folderId)
61+
if (folder) i.folder = folder.value()
62+
return i
63+
})
64+
65+
res.status(200).send(result)
66+
})
67+
5368
app.post('/snippets/delete', (req, res) => {
5469
const ids: string[] = req.body.ids
5570
const snippets = router.db.get<Snippet[]>('snippets').value()

0 commit comments

Comments
 (0)