forked from gptscript-ai/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotion.ts
38 lines (33 loc) · 1.02 KB
/
notion.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use server';
import fs from 'fs';
import path from 'path';
import { WORKSPACE_DIR } from '@/config/env';
import { runSyncTool } from '@/actions/knowledge/tool';
export async function isNotionConfigured() {
return fs.existsSync(
path.join(
WORKSPACE_DIR(),
'knowledge',
'integrations',
'notion',
'metadata.json'
)
);
}
export async function getNotionFiles() {
const dir = path.join(WORKSPACE_DIR(), 'knowledge', 'integrations', 'notion');
const metadataFromFiles = fs.readFileSync(path.join(dir, 'metadata.json'));
const metadata = JSON.parse(metadataFromFiles.toString());
const result = new Map<string, { url: string; fileName: string }>();
for (const pageID in metadata) {
const filePath = path.join(dir, pageID, metadata[pageID].filename);
result.set(filePath, {
url: metadata[pageID].url,
fileName: path.basename(filePath),
});
}
return result;
}
export async function runNotionSync(authed: boolean): Promise<void> {
return runSyncTool(authed, 'notion');
}