collabdocchat 2.0.8 → 2.0.9

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.
@@ -1,327 +1,265 @@
1
- const API_URL = 'http://localhost:3000/api';
2
-
3
- export class ApiService {
4
- constructor() {
5
- this.token = localStorage.getItem('token');
6
- }
7
-
8
- async request(endpoint, options = {}) {
9
- const response = await fetch(`${API_URL}${endpoint}`, {
10
- ...options,
11
- headers: {
12
- 'Content-Type': 'application/json',
13
- 'Authorization': `Bearer ${this.token}`,
14
- ...options.headers
15
- }
16
- });
17
-
18
- if (!response.ok) {
19
- const error = await response.json().catch(() => ({ message: '请求失败' }));
20
- console.error('API 错误:', {
21
- endpoint,
22
- status: response.status,
23
- error
24
- });
25
- throw new Error(error.message || `请求失败: ${response.status}`);
26
- }
27
-
28
- return await response.json();
29
- }
30
-
31
- // 群组相关
32
- async getGroups() {
33
- return await this.request('/groups');
34
- }
35
-
36
- async getAllGroups() {
37
- return await this.request('/groups/all');
38
- }
39
-
40
- async getGroup(groupId) {
41
- return await this.request(`/groups/${groupId}`);
42
- }
43
-
44
- async createGroup(name, description, members) {
45
- return await this.request('/groups', {
46
- method: 'POST',
47
- body: JSON.stringify({ name, description, members })
48
- });
49
- }
50
-
51
- async joinGroup(groupId) {
52
- return await this.request(`/groups/${groupId}/join`, {
53
- method: 'POST'
54
- });
55
- }
56
-
57
- async leaveGroup(groupId) {
58
- return await this.request(`/groups/${groupId}/leave`, {
59
- method: 'POST'
60
- });
61
- }
62
-
63
- async addMember(groupId, userId) {
64
- return await this.request(`/groups/${groupId}/members`, {
65
- method: 'POST',
66
- body: JSON.stringify({ userId })
67
- });
68
- }
69
-
70
- async removeMember(groupId, userId) {
71
- return await this.request(`/groups/${groupId}/members/${userId}`, {
72
- method: 'DELETE'
73
- });
74
- }
75
-
76
- async setMuteAll(groupId, enabled) {
77
- return await this.request(`/groups/${groupId}/mute/all`, {
78
- method: 'POST',
79
- body: JSON.stringify({ enabled })
80
- });
81
- }
82
-
83
- async setUserMute(groupId, userId, muted) {
84
- return await this.request(`/groups/${groupId}/mute/users/${userId}`, {
85
- method: 'POST',
86
- body: JSON.stringify({ muted })
87
- });
88
- }
89
-
90
- async getAllUsers() {
91
- return await this.request('/auth/users');
92
- }
93
-
94
- async getGroupMessages(groupId) {
95
- return await this.request(`/groups/${groupId}/messages`);
96
- }
97
-
98
- // 清除聊天记录(管理员�? async clearChatMessages(groupId, options = {}) {
99
- return await this.request(`/groups/${groupId}/messages`, {
100
- method: 'DELETE',
101
- body: JSON.stringify(options)
102
- });
103
- }
104
-
105
- // 清除指定用户的消息(管理员)
106
- async clearUserMessages(groupId, userId) {
107
- return await this.request(`/groups/${groupId}/messages/user/${userId}`, {
108
- method: 'DELETE'
109
- });
110
- }
111
-
112
- // 撤回消息
113
- async recallMessage(groupId, messageId) {
114
- return await this.request(`/groups/${groupId}/messages/${messageId}/recall`, {
115
- method: 'POST'
116
- });
117
- }
118
-
119
- // 标记消息为已�? async markMessageAsRead(groupId, messageId) {
120
- return await this.request(`/groups/${groupId}/messages/${messageId}/read`, {
121
- method: 'POST'
122
- });
123
- }
124
-
125
- // 批量标记消息为已�? async markMessagesAsRead(groupId, messageIds) {
126
- return await this.request(`/groups/${groupId}/messages/read-all`, {
127
- method: 'POST',
128
- body: JSON.stringify({ messageIds })
129
- });
130
- }
131
-
132
- // 获取未读消息数量
133
- async getUnreadCount(groupId) {
134
- return await this.request(`/groups/${groupId}/messages/unread-count`);
135
- }
136
-
137
- async randomCall(groupId, count = 1) {
138
- return await this.request(`/groups/${groupId}/call`, {
139
- method: 'POST',
140
- body: JSON.stringify({ count })
141
- });
142
- }
143
-
144
- // 任务相关
145
- async getTasks(groupId) {
146
- return await this.request(`/tasks/group/${groupId}`);
147
- }
148
-
149
- async getMyTasks() {
150
- return await this.request('/tasks/my');
151
- }
152
-
153
- async createTask(taskData) {
154
- return await this.request('/tasks', {
155
- method: 'POST',
156
- body: JSON.stringify(taskData)
157
- });
158
- }
159
-
160
- async updateTaskStatus(taskId, status) {
161
- return await this.request(`/tasks/${taskId}/status`, {
162
- method: 'PATCH',
163
- body: JSON.stringify({ status })
164
- });
165
- }
166
-
167
- async deleteTask(taskId) {
168
- return await this.request(`/tasks/${taskId}`, {
169
- method: 'DELETE'
170
- });
171
- }
172
-
173
- // 投票相关
174
- async submitPollVote(taskId, selectedOptions) {
175
- return await this.request(`/tasks/${taskId}/vote`, {
176
- method: 'POST',
177
- body: JSON.stringify({ selectedOptions })
178
- });
179
- }
180
-
181
- // 文档相关
182
- async getDocuments(groupId) {
183
- return await this.request(`/documents/group/${groupId}`);
184
- }
185
-
186
- async getDocument(documentId) {
187
- return await this.request(`/documents/${documentId}`);
188
- }
189
-
190
- async createDocument(title, content, groupId, permission = 'editable') {
191
- return await this.request('/documents', {
192
- method: 'POST',
193
- body: JSON.stringify({ title, content, groupId, permission })
194
- });
195
- }
196
-
197
- async updateDocument(documentId, content) {
198
- return await this.request(`/documents/${documentId}`, {
199
- method: 'PATCH',
200
- body: JSON.stringify({ content })
201
- });
202
- }
203
-
204
- async getDocumentVersions(documentId) {
205
- return await this.request(`/documents/${documentId}/versions`);
206
- }
207
-
208
- async deleteDocument(documentId) {
209
- return await this.request(`/documents/${documentId}`, {
210
- method: 'DELETE'
211
- });
212
- }
213
-
214
- // 审计日志相关
215
- async getAuditLogs(filters = {}, options = {}) {
216
- const params = new URLSearchParams();
217
-
218
- // 添加过滤条件
219
- Object.keys(filters).forEach(key => {
220
- if (filters[key]) {
221
- params.append(key, filters[key]);
222
- }
223
- });
224
-
225
- // 添加分页和排序选项
226
- Object.keys(options).forEach(key => {
227
- if (options[key]) {
228
- params.append(key, options[key]);
229
- }
230
- });
231
-
232
- const queryString = params.toString();
233
- return await this.request(`/audit${queryString ? '?' + queryString : ''}`);
234
- }
235
-
236
- async getUserActivityStats(userId, timeRange = {}) {
237
- const params = new URLSearchParams(timeRange);
238
- const queryString = params.toString();
239
- return await this.request(`/audit/user-stats/${userId}${queryString ? '?' + queryString : ''}`);
240
- }
241
-
242
- async getDocumentEditHistory(documentId, limit = 20) {
243
- return await this.request(`/audit/document-history/${documentId}?limit=${limit}`);
244
- }
245
-
246
- async getGroupAuditLogs(groupId, filters = {}, options = {}) {
247
- const params = new URLSearchParams();
248
-
249
- // 添加过滤条件
250
- Object.keys(filters).forEach(key => {
251
- if (filters[key]) {
252
- params.append(key, filters[key]);
253
- }
254
- });
255
-
256
- // 添加分页和排序选项
257
- Object.keys(options).forEach(key => {
258
- if (options[key]) {
259
- params.append(key, options[key]);
260
- }
261
- });
262
-
263
- const queryString = params.toString();
264
- return await this.request(`/audit/group/${groupId}${queryString ? '?' + queryString : ''}`);
265
- }
266
-
267
- // 获取单个任务详情
268
- async getTask(taskId) {
269
- return await this.request(`/tasks/${taskId}`);
270
- }
271
-
272
- async getAuditSummary(filters = {}) {
273
- const params = new URLSearchParams(filters);
274
- const queryString = params.toString();
275
- return await this.request(`/audit/stats/summary${queryString ? '?' + queryString : ''}`);
276
- }
277
-
278
- // 获取审计日志详情
279
- async getAuditLogDetail(logId) {
280
- return await this.request(`/audit/${logId}`);
281
- }
282
-
283
- // 文件相关
284
- async uploadFile(groupId, file, description = '') {
285
- const formData = new FormData();
286
- formData.append('file', file);
287
- formData.append('groupId', groupId);
288
- if (description) {
289
- formData.append('description', description);
290
- }
291
-
292
- const response = await fetch(`${API_URL}/files/upload`, {
293
- method: 'POST',
294
- headers: {
295
- 'Authorization': `Bearer ${this.token}`
296
- },
297
- body: formData
298
- });
299
-
300
- if (!response.ok) {
301
- const error = await response.json().catch(() => ({ message: '上传失败' }));
302
- throw new Error(error.message || '上传失败');
303
- }
304
-
305
- return await response.json();
306
- }
307
-
308
- async getGroupFiles(groupId) {
309
- return await this.request(`/files/group/${groupId}`);
310
- }
311
-
312
- async deleteFile(fileId) {
313
- return await this.request(`/files/${fileId}`, {
314
- method: 'DELETE'
315
- });
316
- }
317
-
318
- getFileDownloadUrl(fileId) {
319
- return `${API_URL}/files/${fileId}/download?token=${this.token}`;
320
- }
321
-
322
- getFileViewUrl(fileId) {
323
- return `${API_URL}/files/${fileId}/view?token=${this.token}`;
324
- }
325
- }
326
-
1
+ const API_URL = 'http://localhost:3000/api';
2
+
3
+ export class ApiService {
4
+ constructor() {
5
+ this.token = localStorage.getItem('token');
6
+ }
7
+
8
+ async request(endpoint, options = {}) {
9
+ const response = await fetch(`${API_URL}${endpoint}`, {
10
+ ...options,
11
+ headers: {
12
+ 'Content-Type': 'application/json',
13
+ 'Authorization': `Bearer ${this.token}`,
14
+ ...options.headers
15
+ }
16
+ });
17
+
18
+ if (!response.ok) {
19
+ const error = await response.json().catch(() => ({ message: '请求失败' }));
20
+ console.error('API 错误:', {
21
+ endpoint,
22
+ status: response.status,
23
+ error
24
+ });
25
+ throw new Error(error.message || `请求失败: ${response.status}`);
26
+ }
27
+
28
+ return await response.json();
29
+ }
30
+
31
+ // 群组相关
32
+ async getGroups() {
33
+ return await this.request('/groups');
34
+ }
35
+
36
+ async getAllGroups() {
37
+ return await this.request('/groups/all');
38
+ }
39
+
40
+ async getGroup(groupId) {
41
+ return await this.request(`/groups/${groupId}`);
42
+ }
43
+
44
+ async createGroup(name, description, members) {
45
+ return await this.request('/groups', {
46
+ method: 'POST',
47
+ body: JSON.stringify({ name, description, members })
48
+ });
49
+ }
50
+
51
+ async joinGroup(groupId) {
52
+ return await this.request(`/groups/${groupId}/join`, {
53
+ method: 'POST'
54
+ });
55
+ }
56
+
57
+ async leaveGroup(groupId) {
58
+ return await this.request(`/groups/${groupId}/leave`, {
59
+ method: 'POST'
60
+ });
61
+ }
62
+
63
+ async addMember(groupId, userId) {
64
+ return await this.request(`/groups/${groupId}/members`, {
65
+ method: 'POST',
66
+ body: JSON.stringify({ userId })
67
+ });
68
+ }
69
+
70
+ async removeMember(groupId, userId) {
71
+ return await this.request(`/groups/${groupId}/members/${userId}`, {
72
+ method: 'DELETE'
73
+ });
74
+ }
75
+
76
+ async setMuteAll(groupId, enabled) {
77
+ return await this.request(`/groups/${groupId}/mute/all`, {
78
+ method: 'POST',
79
+ body: JSON.stringify({ enabled })
80
+ });
81
+ }
82
+
83
+ async setUserMute(groupId, userId, muted) {
84
+ return await this.request(`/groups/${groupId}/mute/users/${userId}`, {
85
+ method: 'POST',
86
+ body: JSON.stringify({ muted })
87
+ });
88
+ }
89
+
90
+ async getAllUsers() {
91
+ return await this.request('/auth/users');
92
+ }
93
+
94
+ async getGroupMessages(groupId) {
95
+ return await this.request(`/groups/${groupId}/messages`);
96
+ }
97
+
98
+ async randomCall(groupId, count = 1) {
99
+ return await this.request(`/groups/${groupId}/call`, {
100
+ method: 'POST',
101
+ body: JSON.stringify({ count })
102
+ });
103
+ }
104
+
105
+ // 任务相关
106
+ async getTasks(groupId) {
107
+ return await this.request(`/tasks/group/${groupId}`);
108
+ }
109
+
110
+ async getMyTasks() {
111
+ return await this.request('/tasks/my');
112
+ }
113
+
114
+ async createTask(taskData) {
115
+ return await this.request('/tasks', {
116
+ method: 'POST',
117
+ body: JSON.stringify(taskData)
118
+ });
119
+ }
120
+
121
+ async updateTaskStatus(taskId, status) {
122
+ return await this.request(`/tasks/${taskId}/status`, {
123
+ method: 'PATCH',
124
+ body: JSON.stringify({ status })
125
+ });
126
+ }
127
+
128
+ async deleteTask(taskId) {
129
+ return await this.request(`/tasks/${taskId}`, {
130
+ method: 'DELETE'
131
+ });
132
+ }
133
+
134
+ // 文档相关
135
+ async getDocuments(groupId) {
136
+ return await this.request(`/documents/group/${groupId}`);
137
+ }
138
+
139
+ async getDocument(documentId) {
140
+ return await this.request(`/documents/${documentId}`);
141
+ }
142
+
143
+ async createDocument(title, content, groupId, permission = 'editable') {
144
+ return await this.request('/documents', {
145
+ method: 'POST',
146
+ body: JSON.stringify({ title, content, groupId, permission })
147
+ });
148
+ }
149
+
150
+ async updateDocument(documentId, content) {
151
+ return await this.request(`/documents/${documentId}`, {
152
+ method: 'PATCH',
153
+ body: JSON.stringify({ content })
154
+ });
155
+ }
156
+
157
+ async getDocumentVersions(documentId) {
158
+ return await this.request(`/documents/${documentId}/versions`);
159
+ }
160
+
161
+ async deleteDocument(documentId) {
162
+ return await this.request(`/documents/${documentId}`, {
163
+ method: 'DELETE'
164
+ });
165
+ }
166
+
167
+ // 审计日志相关
168
+ async getAuditLogs(filters = {}, options = {}) {
169
+ const params = new URLSearchParams();
170
+
171
+ // 添加过滤条件
172
+ Object.keys(filters).forEach(key => {
173
+ if (filters[key]) {
174
+ params.append(key, filters[key]);
175
+ }
176
+ });
177
+
178
+ // 添加分页和排序选项
179
+ Object.keys(options).forEach(key => {
180
+ if (options[key]) {
181
+ params.append(key, options[key]);
182
+ }
183
+ });
184
+
185
+ const queryString = params.toString();
186
+ return await this.request(`/audit${queryString ? '?' + queryString : ''}`);
187
+ }
188
+
189
+ async getUserActivityStats(userId, timeRange = {}) {
190
+ const params = new URLSearchParams(timeRange);
191
+ const queryString = params.toString();
192
+ return await this.request(`/audit/user-stats/${userId}${queryString ? '?' + queryString : ''}`);
193
+ }
194
+
195
+ async getDocumentEditHistory(documentId, limit = 20) {
196
+ return await this.request(`/audit/document-history/${documentId}?limit=${limit}`);
197
+ }
198
+
199
+ async getGroupAuditLogs(groupId, filters = {}, options = {}) {
200
+ const params = new URLSearchParams();
201
+
202
+ // 添加过滤条件
203
+ Object.keys(filters).forEach(key => {
204
+ if (filters[key]) {
205
+ params.append(key, filters[key]);
206
+ }
207
+ });
208
+
209
+ // 添加分页和排序选项
210
+ Object.keys(options).forEach(key => {
211
+ if (options[key]) {
212
+ params.append(key, options[key]);
213
+ }
214
+ });
215
+
216
+ const queryString = params.toString();
217
+ return await this.request(`/audit/group/${groupId}${queryString ? '?' + queryString : ''}`);
218
+ }
219
+
220
+ async getAuditSummary(filters = {}) {
221
+ const params = new URLSearchParams(filters);
222
+ const queryString = params.toString();
223
+ return await this.request(`/audit/stats/summary${queryString ? '?' + queryString : ''}`);
224
+ }
225
+
226
+ // 文件相关
227
+ async uploadFile(groupId, file, description = '') {
228
+ const formData = new FormData();
229
+ formData.append('file', file);
230
+ formData.append('groupId', groupId);
231
+ if (description) {
232
+ formData.append('description', description);
233
+ }
234
+
235
+ const response = await fetch(`${API_URL}/files/upload`, {
236
+ method: 'POST',
237
+ headers: {
238
+ 'Authorization': `Bearer ${this.token}`
239
+ },
240
+ body: formData
241
+ });
242
+
243
+ if (!response.ok) {
244
+ const error = await response.json().catch(() => ({ message: '上传失败' }));
245
+ throw new Error(error.message || '上传失败');
246
+ }
247
+
248
+ return await response.json();
249
+ }
250
+
251
+ async getGroupFiles(groupId) {
252
+ return await this.request(`/files/group/${groupId}`);
253
+ }
254
+
255
+ async deleteFile(fileId) {
256
+ return await this.request(`/files/${fileId}`, {
257
+ method: 'DELETE'
258
+ });
259
+ }
260
+
261
+ getFileDownloadUrl(fileId) {
262
+ return `${API_URL}/files/${fileId}/download?token=${this.token}`;
263
+ }
264
+ }
327
265