collabdocchat 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SHijinghao1
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,501 @@
1
+ # CollabDocChat
2
+
3
+ <div align="center">
4
+
5
+ ![CollabDocChat Logo](https://img.shields.io/badge/CollabDocChat-v1.0.0-blue)
6
+ ![License](https://img.shields.io/badge/license-MIT-green)
7
+ ![Node](https://img.shields.io/badge/node-%3E%3D16.0.0-brightgreen)
8
+ ![MongoDB](https://img.shields.io/badge/MongoDB-%3E%3D5.0-green)
9
+
10
+ **开源的实时协作文档聊天平台**
11
+
12
+ 集成任务管理 · 多人文档编辑 · 智能点名 · 即时通讯
13
+
14
+ [快速开始](#快速开始) · [功能特性](#功能特性) · [技术栈](#技术栈) · [贡献指南](#贡献指南)
15
+
16
+ </div>
17
+
18
+ ---
19
+
20
+ ## 📖 项目简介
21
+
22
+ **CollabDocChat** 是一个轻量级的开源协作平台,专为学习和办公场景设计。它将即时通讯、多人实时文档编辑、任务管理和互动点名功能整合在一起,提供一站式的群体协作解决方案。
23
+
24
+ ### 🎯 核心定位
25
+
26
+ - **轻量级**:相比飞书、钉钉等重型工具,更加简洁易用
27
+ - **开源免费**:完全开源,可自由部署和定制
28
+ - **实时协作**:基于 WebSocket 的实时同步技术
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
+ - 编辑记录
78
+ - 群组列表
79
+
80
+ ---
81
+
82
+ ## 🛠 技术栈
83
+
84
+ ### 后端
85
+ - **Node.js** + **Express** - 服务器框架
86
+ - **MongoDB** + **Mongoose** - 数据库
87
+ - **WebSocket (ws)** - 实时通信
88
+ - **JWT** - 身份认证
89
+ - **Yjs** - CRDT 实时协作算法
90
+
91
+ ### 前端
92
+ - **原生 JavaScript** - 无框架依赖
93
+ - **Vite** - 构建工具
94
+ - **CSS3** - 现代化 UI 设计
95
+ - **WebSocket API** - 实时通信
96
+
97
+ ### 核心技术
98
+ - **CRDT (Conflict-free Replicated Data Type)** - 无冲突文档同步
99
+ - **WebSocket** - 双向实时通信
100
+ - **JWT** - 无状态身份验证
101
+
102
+ ---
103
+
104
+ ## 🚀 快速开始
105
+
106
+ ### 环境要求
107
+
108
+ - Node.js >= 16.0.0
109
+ - MongoDB >= 5.0
110
+ - npm 或 yarn
111
+
112
+ ### 安装步骤
113
+
114
+ 1. **克隆项目**
115
+
116
+ ```bash
117
+ git clone https://github.com/yourusername/collabdocchat.git
118
+ cd collabdocchat
119
+ ```
120
+
121
+ 2. **安装依赖**
122
+
123
+ ```bash
124
+ npm install
125
+ ```
126
+
127
+ 3. **配置环境变量**
128
+
129
+ 复制 `.env.example` 为 `.env` 并修改配置:
130
+
131
+ ```bash
132
+ cp .env.example .env
133
+ ```
134
+
135
+ 编辑 `.env` 文件:
136
+
137
+ ```env
138
+ PORT=3000
139
+ MONGODB_URI=mongodb://localhost:27017/collabdocchat
140
+ JWT_SECRET=your_super_secret_jwt_key_change_this
141
+ CLIENT_URL=http://localhost:5173
142
+ ```
143
+
144
+ 4. **启动 MongoDB**
145
+
146
+ ```bash
147
+ # Windows
148
+ mongod
149
+
150
+ # macOS/Linux
151
+ sudo systemctl start mongod
152
+ ```
153
+
154
+ 5. **启动项目**
155
+
156
+ ```bash
157
+ # 开发模式(同时启动前后端)
158
+ npm run dev
159
+
160
+ # 或分别启动
161
+ npm run server # 后端服务器
162
+ npm run client # 前端开发服务器
163
+ ```
164
+
165
+ 6. **访问应用**
166
+
167
+ 打开浏览器访问:`http://localhost:5173`
168
+
169
+ ---
170
+
171
+ ## 📁 项目结构
172
+
173
+ ```
174
+ CollabDocChat/
175
+ ├── server/ # 后端代码
176
+ │ ├── models/ # 数据模型
177
+ │ │ ├── User.js
178
+ │ │ ├── Group.js
179
+ │ │ ├── Document.js
180
+ │ │ └── Task.js
181
+ │ ├── routes/ # API 路由
182
+ │ │ ├── auth.js
183
+ │ │ ├── groups.js
184
+ │ │ ├── documents.js
185
+ │ │ └── tasks.js
186
+ │ ├── middleware/ # 中间件
187
+ │ │ └── auth.js
188
+ │ ├── websocket/ # WebSocket 处理
189
+ │ │ └── index.js
190
+ │ └── index.js # 服务器入口
191
+ ├── src/ # 前端代码
192
+ │ ├── pages/ # 页面组件
193
+ │ │ ├── login.js
194
+ │ │ ├── admin-dashboard.js
195
+ │ │ └── user-dashboard.js
196
+ │ ├── services/ # 服务层
197
+ │ │ ├── api.js
198
+ │ │ ├── auth.js
199
+ │ │ └── websocket.js
200
+ │ ├── styles/ # 样式文件
201
+ │ │ └── main.css
202
+ │ └── main.js # 前端入口
203
+ ├── package.json
204
+ ├── vite.config.js
205
+ ├── .env.example
206
+ └── README.md
207
+ ```
208
+
209
+ ---
210
+
211
+ ## 🔌 API 文档
212
+
213
+ ### 认证接口
214
+
215
+ #### 注册
216
+ ```http
217
+ POST /api/auth/register
218
+ Content-Type: application/json
219
+
220
+ {
221
+ "username": "string",
222
+ "email": "string",
223
+ "password": "string",
224
+ "role": "admin" | "user"
225
+ }
226
+ ```
227
+
228
+ #### 登录
229
+ ```http
230
+ POST /api/auth/login
231
+ Content-Type: application/json
232
+
233
+ {
234
+ "email": "string",
235
+ "password": "string"
236
+ }
237
+ ```
238
+
239
+ ### 群组接口
240
+
241
+ #### 获取群组列表
242
+ ```http
243
+ GET /api/groups
244
+ Authorization: Bearer {token}
245
+ ```
246
+
247
+ #### 创建群组(管理员)
248
+ ```http
249
+ POST /api/groups
250
+ Authorization: Bearer {token}
251
+ Content-Type: application/json
252
+
253
+ {
254
+ "name": "string",
255
+ "description": "string",
256
+ "members": ["userId1", "userId2"]
257
+ }
258
+ ```
259
+
260
+ #### 随机点名(管理员)
261
+ ```http
262
+ POST /api/groups/:id/call
263
+ Authorization: Bearer {token}
264
+ Content-Type: application/json
265
+
266
+ {
267
+ "count": 1
268
+ }
269
+ ```
270
+
271
+ ### 文档接口
272
+
273
+ #### 获取群组文档
274
+ ```http
275
+ GET /api/documents/group/:groupId
276
+ Authorization: Bearer {token}
277
+ ```
278
+
279
+ #### 创建文档
280
+ ```http
281
+ POST /api/documents
282
+ Authorization: Bearer {token}
283
+ Content-Type: application/json
284
+
285
+ {
286
+ "title": "string",
287
+ "content": "string",
288
+ "groupId": "string",
289
+ "permission": "readonly" | "editable"
290
+ }
291
+ ```
292
+
293
+ #### 更新文档
294
+ ```http
295
+ PATCH /api/documents/:id
296
+ Authorization: Bearer {token}
297
+ Content-Type: application/json
298
+
299
+ {
300
+ "content": "string"
301
+ }
302
+ ```
303
+
304
+ ### 任务接口
305
+
306
+ #### 获取我的任务
307
+ ```http
308
+ GET /api/tasks/my
309
+ Authorization: Bearer {token}
310
+ ```
311
+
312
+ #### 创建任务(管理员)
313
+ ```http
314
+ POST /api/tasks
315
+ Authorization: Bearer {token}
316
+ Content-Type: application/json
317
+
318
+ {
319
+ "title": "string",
320
+ "description": "string",
321
+ "groupId": "string",
322
+ "assignedTo": ["userId1"],
323
+ "relatedDocument": "documentId",
324
+ "deadline": "2024-12-31"
325
+ }
326
+ ```
327
+
328
+ ---
329
+
330
+ ## 🔄 WebSocket 事件
331
+
332
+ ### 客户端发送
333
+
334
+ ```javascript
335
+ // 认证
336
+ { type: 'auth', token: 'jwt_token' }
337
+
338
+ // 加入群组
339
+ { type: 'join_group', groupId: 'group_id' }
340
+
341
+ // 发送聊天消息
342
+ { type: 'chat_message', groupId: 'group_id', username: 'user', content: 'message' }
343
+
344
+ // 同步文档
345
+ { type: 'document_sync', documentId: 'doc_id', content: 'text', cursorPosition: 0 }
346
+
347
+ // 响应点名
348
+ { type: 'call_response', groupId: 'group_id', username: 'user' }
349
+
350
+ // 输入状态
351
+ { type: 'typing', documentId: 'doc_id', username: 'user', isTyping: true }
352
+ ```
353
+
354
+ ### 服务器推送
355
+
356
+ ```javascript
357
+ // 认证成功
358
+ { type: 'auth_success', userId: 'user_id', role: 'admin' }
359
+
360
+ // 聊天消息
361
+ { type: 'chat_message', groupId: 'group_id', userId: 'user_id', username: 'user', content: 'message', timestamp: 'ISO8601' }
362
+
363
+ // 文档更新
364
+ { type: 'document_update', documentId: 'doc_id', content: 'text', userId: 'user_id', timestamp: 'ISO8601' }
365
+
366
+ // 用户离线
367
+ { type: 'user_offline', userId: 'user_id' }
368
+ ```
369
+
370
+ ---
371
+
372
+ ## 🎨 界面预览
373
+
374
+ ### 登录页面
375
+ - 现代化渐变背景
376
+ - 流畅的动画效果
377
+ - 登录/注册切换
378
+
379
+ ### 管理员仪表板
380
+ - 群组管理面板
381
+ - 任务发布界面
382
+ - 文档权限控制
383
+ - 随机点名功能
384
+
385
+ ### 用户仪表板
386
+ - 任务列表
387
+ - 实时文档编辑器
388
+ - 群组聊天
389
+ - 在线状态显示
390
+
391
+ ---
392
+
393
+ ## 🤝 贡献指南
394
+
395
+ 我们欢迎所有形式的贡献!
396
+
397
+ ### 如何贡献
398
+
399
+ 1. Fork 本项目
400
+ 2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
401
+ 3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
402
+ 4. 推送到分支 (`git push origin feature/AmazingFeature`)
403
+ 5. 开启 Pull Request
404
+
405
+ ### 代码规范
406
+
407
+ - 使用 ES6+ 语法
408
+ - 遵循 ESLint 规则
409
+ - 添加必要的注释
410
+ - 编写清晰的提交信息
411
+
412
+ ---
413
+
414
+ ## 📦 发布到 npm
415
+
416
+ ### 准备发布
417
+
418
+ 1. **更新版本号**
419
+
420
+ ```bash
421
+ npm version patch # 1.0.0 -> 1.0.1
422
+ npm version minor # 1.0.0 -> 1.1.0
423
+ npm version major # 1.0.0 -> 2.0.0
424
+ ```
425
+
426
+ 2. **登录 npm**
427
+
428
+ ```bash
429
+ npm login
430
+ ```
431
+
432
+ 3. **发布包**
433
+
434
+ ```bash
435
+ npm publish
436
+ ```
437
+
438
+ ### 使用 npm 包
439
+
440
+ ```bash
441
+ npm install collabdocchat
442
+ ```
443
+
444
+ ---
445
+
446
+ ## 📄 开源协议
447
+
448
+ 本项目采用 [MIT License](LICENSE) 开源协议。
449
+
450
+ ---
451
+
452
+ ## 🙏 致谢
453
+
454
+ 感谢以下开源项目:
455
+
456
+ - [Express](https://expressjs.com/) - Web 框架
457
+ - [MongoDB](https://www.mongodb.com/) - 数据库
458
+ - [Yjs](https://github.com/yjs/yjs) - CRDT 算法
459
+ - [Vite](https://vitejs.dev/) - 构建工具
460
+
461
+ ---
462
+
463
+ ## 📞 联系方式
464
+
465
+ - **项目主页**: [https://github.com/yourusername/collabdocchat](https://github.com/yourusername/collabdocchat)
466
+ - **问题反馈**: [Issues](https://github.com/yourusername/collabdocchat/issues)
467
+ - **邮箱**: your.email@example.com
468
+
469
+ ---
470
+
471
+ ## 🗺 路线图
472
+
473
+ ### v1.1.0 (计划中)
474
+ - [ ] 文件上传功能
475
+ - [ ] 富文本编辑器
476
+ - [ ] 消息通知系统
477
+ - [ ] 移动端适配
478
+
479
+ ### v1.2.0 (计划中)
480
+ - [ ] 视频会议集成
481
+ - [ ] 屏幕共享
482
+ - [ ] 白板功能
483
+ - [ ] 插件系统
484
+
485
+ ### v2.0.0 (未来)
486
+ - [ ] 微服务架构
487
+ - [ ] Docker 部署
488
+ - [ ] 多语言支持
489
+ - [ ] AI 助手集成
490
+
491
+ ---
492
+
493
+ <div align="center">
494
+
495
+ **⭐ 如果这个项目对你有帮助,请给我们一个 Star!⭐**
496
+
497
+ Made with ❤️ by CollabDocChat Team
498
+
499
+ </div>
500
+
501
+
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "collabdocchat",
3
+ "version": "1.0.0",
4
+ "description": "开源的实时协作文档聊天平台 - 集成任务管理、多人文档编辑、智能点名功能",
5
+ "main": "./server/index.js",
6
+ "type": "module",
7
+ "files": [
8
+ "server",
9
+ "src",
10
+ "README.md",
11
+ "LICENSE",
12
+ "package.json"
13
+ ],
14
+ "keywords": [
15
+ "collaboration",
16
+ "real-time",
17
+ "document-editing",
18
+ "chat",
19
+ "task-management",
20
+ "websocket",
21
+ "crdt",
22
+ "open-source",
23
+ "collaborative-editing",
24
+ "yjs",
25
+ "mongodb",
26
+ "express"
27
+ ],
28
+ "author": "shijinghao",
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/shijinghao/collabdocchat.git"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/shijinghao/collabdocchat/issues"
36
+ },
37
+ "homepage": "https://github.com/shijinghao/collabdocchat#readme",
38
+ "engines": {
39
+ "node": ">=16.0.0",
40
+ "npm": ">=7.0.0"
41
+ },
42
+ "scripts": {
43
+ "dev": "concurrently \"npm run server\" \"npm run client\"",
44
+ "server": "nodemon server/index.js",
45
+ "client": "vite",
46
+ "build": "vite build",
47
+ "preview": "vite preview",
48
+ "start": "node server/index.js",
49
+ "prepublishOnly": "npm run build"
50
+ },
51
+ "dependencies": {
52
+ "express": "^4.18.2",
53
+ "ws": "^8.14.2",
54
+ "mongoose": "^8.0.3",
55
+ "jsonwebtoken": "^9.0.2",
56
+ "bcryptjs": "^2.4.3",
57
+ "cors": "^2.8.5",
58
+ "dotenv": "^16.3.1",
59
+ "yjs": "^13.6.10",
60
+ "y-websocket": "^1.5.0",
61
+ "quill": "^1.3.7",
62
+ "quill-cursors": "^4.0.2"
63
+ },
64
+ "devDependencies": {
65
+ "vite": "^5.0.8",
66
+ "nodemon": "^3.0.2",
67
+ "concurrently": "^8.2.2"
68
+ }
69
+ }
70
+
@@ -0,0 +1,63 @@
1
+ import express from 'express';
2
+ import { createServer } from 'http';
3
+ import { WebSocketServer } from 'ws';
4
+ import cors from 'cors';
5
+ import dotenv from 'dotenv';
6
+ import mongoose from 'mongoose';
7
+ import authRoutes from './routes/auth.js';
8
+ import taskRoutes from './routes/tasks.js';
9
+ import documentRoutes from './routes/documents.js';
10
+ import groupRoutes from './routes/groups.js';
11
+ import auditRoutes from './routes/audit.js';
12
+ import fileRoutes from './routes/files.js';
13
+ import { setupWebSocket } from './websocket/index.js';
14
+ import { initDefaultAdmin } from './utils/initAdmin.js';
15
+
16
+ dotenv.config();
17
+
18
+ const app = express();
19
+ const server = createServer(app);
20
+ const wss = new WebSocketServer({ server });
21
+
22
+ // 中间件
23
+ app.use(cors({
24
+ origin: process.env.CLIENT_URL || 'http://localhost:5173',
25
+ credentials: true
26
+ }));
27
+ app.use(express.json());
28
+
29
+ // 数据库连接
30
+ mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/collabdocchat')
31
+ .then(async () => {
32
+ console.log('✅ MongoDB 连接成功');
33
+ // 初始化默认管理员账户
34
+ await initDefaultAdmin();
35
+ })
36
+ .catch(err => console.error('❌ MongoDB 连接失败:', err));
37
+
38
+ // 静态文件服务(用于文件下载)
39
+ app.use('/uploads', express.static('uploads'));
40
+
41
+ // API 路由
42
+ app.use('/api/auth', authRoutes);
43
+ app.use('/api/tasks', taskRoutes);
44
+ app.use('/api/documents', documentRoutes);
45
+ app.use('/api/groups', groupRoutes);
46
+ app.use('/api/audit', auditRoutes);
47
+ app.use('/api/files', fileRoutes);
48
+
49
+ // WebSocket 设置
50
+ setupWebSocket(wss);
51
+
52
+ // 健康检查
53
+ app.get('/health', (req, res) => {
54
+ res.json({ status: 'ok', timestamp: new Date().toISOString() });
55
+ });
56
+
57
+ const PORT = process.env.PORT || 3000;
58
+ server.listen(PORT, () => {
59
+ console.log(`🚀 服务器运行在 http://localhost:${PORT}`);
60
+ console.log(`🔌 WebSocket 服务器运行在 ws://localhost:${PORT}`);
61
+ });
62
+
63
+
@@ -0,0 +1,26 @@
1
+ import jwt from 'jsonwebtoken';
2
+
3
+ export const authenticate = (req, res, next) => {
4
+ try {
5
+ const token = req.headers.authorization?.split(' ')[1];
6
+
7
+ if (!token) {
8
+ return res.status(401).json({ message: '未授权:缺少令牌' });
9
+ }
10
+
11
+ const decoded = jwt.verify(token, process.env.JWT_SECRET);
12
+ req.user = decoded;
13
+ next();
14
+ } catch (error) {
15
+ return res.status(401).json({ message: '未授权:无效的令牌' });
16
+ }
17
+ };
18
+
19
+ export const isAdmin = (req, res, next) => {
20
+ if (req.user.role !== 'admin') {
21
+ return res.status(403).json({ message: '权限不足:需要管理员权限' });
22
+ }
23
+ next();
24
+ };
25
+
26
+