Repository navigation
Expand file tree
/
Copy pathtest-combined.ts
More file actions
77 lines (64 loc) · 2.57 KB
/
Copy pathtest-combined.ts
File metadata and controls
77 lines (64 loc) · 2.57 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Server } from '@hocuspocus/server';
import { TiptapTransformer } from '@hocuspocus/transformer';
import * as Y from 'yjs';
import prisma from './src/lib/prisma';
import 'dotenv/config';
console.log('[Synapse] Starting engine (test-combined.ts)...');
const server = new Server({
port: 1234,
address: '0.0.0.0',
async onAuthenticate(data) {
return { user: { id: '1', name: 'Collaborateur' } };
},
async onLoadDocument(data) {
const { documentName } = data;
console.log(`[Synapse] 📥 Loading: ${documentName}`);
try {
if (documentName.startsWith('notion-')) {
const notionId = documentName.replace('notion-', '');
const notion = await prisma.notion.findUnique({
where: { notion_id: notionId },
});
if (notion) {
return TiptapTransformer.toYdoc(notion.notion_content || '', 'prosemirror');
}
} else if (documentName.startsWith('part-')) {
const partId = documentName.replace('part-', '');
const part = await prisma.part.findUnique({
where: { part_id: partId },
});
if (part) {
return TiptapTransformer.toYdoc(part.part_intro || '', 'prosemirror');
}
}
} catch (error) {
console.error(`[Synapse] ❌ Load Error:`, error);
}
return new Y.Doc();
},
async onStoreDocument(data) {
const { documentName, document } = data;
console.log(`[Synapse] 💾 Storing: ${documentName}`);
try {
const html = TiptapTransformer.fromYdoc(document, 'prosemirror');
if (documentName.startsWith('notion-')) {
const notionId = documentName.replace('notion-', '');
await prisma.notion.update({
where: { notion_id: notionId },
data: { notion_content: html },
});
} else if (documentName.startsWith('part-')) {
const partId = documentName.replace('part-', '');
await prisma.part.update({
where: { part_id: partId },
data: { part_intro: html },
});
}
} catch (error) {
console.error(`[Synapse] ❌ Store Error:`, error);
}
},
async onConnect() { console.log('[Synapse] 🚀 Connect'); },
});
server.listen();
console.log('[Synapse] 🛰️ Running on ws://192.168.1.160:1234');