streamby-core 0.21.1 → 0.21.3

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.
@@ -5,14 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createStreamByRouter = createStreamByRouter;
7
7
  const express_1 = __importDefault(require("express"));
8
- const file_1 = require("../services/file");
9
- const presign_1 = require("../services/presign");
10
8
  const manager_1 = require("../models/manager");
11
9
  const storage_1 = require("../providers/storage");
12
10
  const connectionManager_1 = require("../adapters/database/connectionManager");
13
- function isProjectMember(project, userId) {
14
- return project.members?.some((m) => m.userId?.toString() === userId?.toString());
15
- }
11
+ const auth_1 = require("./routes/auth");
12
+ const database_1 = require("./routes/database");
13
+ const file_1 = require("./routes/file");
14
+ const project_1 = require("./routes/project");
15
+ const export_1 = require("./routes/export");
16
16
  function createStreamByRouter(config) {
17
17
  const router = express_1.default.Router();
18
18
  (0, connectionManager_1.initConnections)(config.databases || []);
@@ -21,386 +21,15 @@ function createStreamByRouter(config) {
21
21
  const allDbIds = config.databases.map(db => db.id);
22
22
  (0, manager_1.registerModel)('projects', allDbIds, 'projects');
23
23
  (0, manager_1.registerModel)('exports', allDbIds, 'exports');
24
- }
25
- const Project = (0, manager_1.getModel)('projects');
26
- const Export = (0, manager_1.getModel)('exports');
27
- router.get('/auth', async (req, res) => {
28
- try {
29
- const auth = await config.authProvider(req);
30
- if (!auth ||
31
- !auth.userId ||
32
- !auth.role) {
33
- throw new Error('Invalid or missing authentication context');
34
- }
35
- return res.status(200).json({ logged: true, ...auth });
36
- }
37
- catch (err) {
38
- return res.status(401).json({ logged: false });
39
- }
40
- });
41
- router.get('/databases', async (req, res) => {
42
- try {
43
- const auth = await config.authProvider(req);
44
- if (!auth ||
45
- !auth.userId ||
46
- !auth.role) {
47
- return res.status(401).json({ error: 'Unauthorized' });
48
- }
49
- const connectedDbIds = (0, connectionManager_1.getConnectedIds)();
50
- const databases = (config.databases || [])
51
- .filter(db => connectedDbIds.includes(db.id))
52
- .map(db => ({ name: db.id, value: db.type }));
53
- res.status(200).json({ databases });
54
- }
55
- catch (err) {
56
- res.status(500).json({ error: 'Failed to get databases' });
57
- }
58
- });
59
- router.get('/upload-project-image-url/:id', async (req, res) => {
60
- try {
61
- const auth = await config.authProvider(req);
62
- if (!auth ||
63
- !auth.userId ||
64
- !auth.role) {
65
- return res.status(401).json({ error: 'Unauthorized' });
66
- }
67
- if (auth.role !== 'admin' && auth.role !== 'editor') {
68
- return res.status(403).json({ error: 'Permission denied' });
69
- }
70
- const projectId = req.params.id;
71
- if (!projectId) {
72
- return res.status(400).json({ error: 'Missing projectId' });
73
- }
74
- const url = await (0, presign_1.getPresignedProjectImageUrl)(adapter, projectId);
75
- res.json(url);
76
- }
77
- catch (err) {
78
- res.status(500).json({ error: 'Failed to generate presigned URL', details: err.message });
79
- }
80
- });
81
- router.delete('/delete-project-image-url/:id', async (req, res) => {
82
- try {
83
- const auth = await config.authProvider(req);
84
- if (!auth ||
85
- !auth.userId ||
86
- !auth.role) {
87
- return res.status(401).json({ error: 'Unauthorized' });
88
- }
89
- if (auth.role !== 'admin' && auth.role !== 'editor') {
90
- return res.status(403).json({ error: 'Permission denied' });
91
- }
92
- const projectId = req.params.id;
93
- if (!projectId) {
94
- return res.status(400).json({ error: 'Missing projectId' });
95
- }
96
- await (0, file_1.deleteProjectImage)(adapter, projectId);
97
- const updated = await Project.update({ _id: projectId }, { image: '' });
98
- res.status(201).json(updated);
99
- }
100
- catch (err) {
101
- res.status(500).json({ error: 'Failed to delete image', details: err.message });
102
- }
103
- });
104
- router.get('/files', async (req, res) => {
105
- try {
106
- const auth = await config.authProvider(req);
107
- if (!auth ||
108
- !auth.userId ||
109
- !auth.role) {
110
- return res.status(401).json({ error: 'Unauthorized' });
111
- }
112
- const projectId = (req.query.projectId || req.headers['x-project-id']);
113
- if (!projectId) {
114
- return res.status(403).json({ error: 'Unauthorized or missing projectId' });
115
- }
116
- const files = await (0, file_1.listFilesService)(adapter, req, projectId);
117
- res.json(files);
118
- }
119
- catch (err) {
120
- res.status(500).json({ error: 'Failed to list files', details: err });
121
- }
122
- });
123
- router.get('/projects', async (req, res) => {
124
- try {
125
- const auth = await config.authProvider(req);
126
- if (!auth ||
127
- !auth.userId ||
128
- !auth.role) {
129
- return res.status(401).json({ error: 'Unauthorized' });
130
- }
131
- const archivedQuery = req.query.archived;
132
- const filterArchived = archivedQuery !== undefined ? String(archivedQuery).toLowerCase() === 'true' : undefined;
133
- const allProjects = await Project.find({}); // Fetch all projects
134
- const projects = allProjects
135
- .filter(project => {
136
- const isMember = project.members?.some((m) => m.userId?.toString() === auth.userId?.toString());
137
- if (!isMember)
138
- return false;
139
- if (filterArchived !== undefined) {
140
- const currentUserMember = project.members?.find((member) => member.userId === auth.userId);
141
- return currentUserMember ? (currentUserMember.archived || false) === filterArchived : false;
142
- }
143
- return true;
144
- })
145
- .map(project => {
146
- const currentUserMember = project.members?.find((member) => member.userId === auth.userId);
147
- return {
148
- id: project._id || project.id,
149
- dbType: project.dbType,
150
- name: project.name,
151
- image: project.image || '',
152
- archived: currentUserMember ? currentUserMember.archived || false : false,
153
- };
154
- });
155
- res.json({ projects });
156
- }
157
- catch (err) {
158
- console.error('Error in /projects endpoint:', err);
159
- res.status(500).json({ error: 'Failed to list projects', details: err });
160
- }
161
- });
162
- router.post('/projects/create', async (req, res) => {
163
- try {
164
- const auth = await config.authProvider(req);
165
- if (!auth ||
166
- !auth.userId ||
167
- !auth.role) {
168
- return res.status(401).json({ error: 'Unauthorized' });
169
- }
170
- if (auth.role !== 'admin' && auth.role !== 'editor') {
171
- return res.status(403).json({ error: 'Permission denied' });
172
- }
173
- const { name, description, dbType } = req.body;
174
- const newProject = await Project.create({
175
- dbType: dbType || 'nosql',
176
- name,
177
- description: description || '',
178
- members: [{ userId: auth.userId, role: "admin", archived: false }]
179
- });
180
- res.status(201).json({ project: { ...newProject, id: newProject._id || newProject.id, _id: undefined } });
181
- }
182
- catch (err) {
183
- res.status(500).json({ error: 'Failed to create project', details: err.message });
184
- }
185
- });
186
- router.get('/projects/:id', async (req, res) => {
187
- try {
188
- const auth = await config.authProvider(req);
189
- if (!auth ||
190
- !auth.userId ||
191
- !auth.role) {
192
- return res.status(401).json({ error: 'Unauthorized' });
193
- }
194
- const projectId = req.params.id;
195
- const project = await Project.findOne({ _id: projectId });
196
- if (!project) {
197
- return res.status(404).json({ error: 'Project not found' });
198
- }
199
- if (!isProjectMember(project, auth.userId)) {
200
- return res.status(403).json({ error: 'Unauthorized project access' });
201
- }
202
- res.json({ project: { ...project, id: project._id || project.id, _id: undefined } });
24
+ const mainDb = config.databases.find(db => db.main);
25
+ if (mainDb) {
26
+ (0, manager_1.registerModel)('users', [mainDb.id], 'users');
203
27
  }
204
- catch (err) {
205
- res.status(500).json({ error: 'Failed to fetch project', details: err.message });
206
- }
207
- });
208
- router.patch('/projects/:id', async (req, res) => {
209
- try {
210
- const auth = await config.authProvider(req);
211
- if (!auth ||
212
- !auth.userId ||
213
- !auth.role) {
214
- return res.status(401).json({ error: 'Unauthorized' });
215
- }
216
- if (auth.role !== 'admin' && auth.role !== 'editor') {
217
- return res.status(403).json({ error: 'Permission denied' });
218
- }
219
- const projectId = req.params.id;
220
- const updates = req.body;
221
- const project = await Project.findOne({ _id: projectId });
222
- if (!project) {
223
- return res.status(404).json({ error: 'Project not found' });
224
- }
225
- if (!updates || typeof updates !== 'object') {
226
- return res.status(400).json({ error: 'Missing updates payload' });
227
- }
228
- if (!isProjectMember(project, auth.userId)) {
229
- return res.status(403).json({ error: 'Unauthorized project access' });
230
- }
231
- const updated = await Project.update({ _id: projectId }, updates);
232
- if (!updated) {
233
- return res.status(404).json({ error: 'Project not found or not updated' });
234
- }
235
- res.status(200).json({ success: true, project: { ...updated, id: updated._id || updated.id, _id: undefined } });
236
- }
237
- catch (err) {
238
- res.status(500).json({ error: 'Failed to update project', details: err.message });
239
- }
240
- });
241
- router.delete('/projects/:id', async (req, res) => {
242
- try {
243
- const auth = await config.authProvider(req);
244
- if (!auth ||
245
- !auth.userId ||
246
- !auth.role) {
247
- return res.status(401).json({ error: 'Unauthorized' });
248
- }
249
- const projectId = req.params.id;
250
- const project = await Project.findOne({ _id: projectId });
251
- if (!project) {
252
- return res.status(404).json({ error: 'Project not found' });
253
- }
254
- if (!isProjectMember(project, auth.userId)) {
255
- return res.status(403).json({ error: 'Unauthorized project access' });
256
- }
257
- await Project.delete({ _id: projectId });
258
- res.status(200).json({ success: true });
259
- }
260
- catch (err) {
261
- res.status(500).json({ error: 'Failed to delete project', details: err.message });
262
- }
263
- });
264
- router.patch('/projects/:id/archive', async (req, res) => {
265
- try {
266
- const auth = await config.authProvider(req);
267
- if (!auth ||
268
- !auth.userId ||
269
- !auth.role) {
270
- return res.status(401).json({ error: 'Unauthorized' });
271
- }
272
- const projectId = req.params.id;
273
- const project = await Project.findOne({ _id: projectId });
274
- if (!project || !isProjectMember(project, auth.userId)) {
275
- return res.status(403).json({ error: 'Unauthorized project access' });
276
- }
277
- await Project.update({ _id: projectId, "members.userId": auth.userId }, { "members.$.archived": true, "members.$.archivedBy": auth.userId, "members.$.archivedAt": new Date() });
278
- const updatedProject = await Project.findOne({ _id: projectId }); // Fetch the updated project
279
- const projects = (await Project.find({ members: { $elemMatch: { userId: auth.userId } } })).map(project => {
280
- const currentUserMember = project.members?.find((member) => member.userId === auth.userId);
281
- return {
282
- id: project._id || project.id,
283
- dbType: project.dbType,
284
- name: project.name,
285
- image: project.image || '',
286
- archived: currentUserMember ? currentUserMember.archived || false : false,
287
- };
288
- });
289
- // Replace the old project with the updated one in the list
290
- const finalProjects = projects.map(p => p.id === (updatedProject?._id || updatedProject?.id) ? ({ ...updatedProject, id: updatedProject._id || updatedProject.id, _id: undefined }) : p);
291
- res.status(200).json({ success: true, projects: finalProjects });
292
- }
293
- catch (err) {
294
- res.status(500).json({ error: 'Failed to archive project', details: err.message });
295
- }
296
- });
297
- router.patch('/projects/:id/unarchive', async (req, res) => {
298
- try {
299
- const auth = await config.authProvider(req);
300
- if (!auth ||
301
- !auth.userId ||
302
- !auth.role) {
303
- return res.status(401).json({ error: 'Unauthorized' });
304
- }
305
- const projectId = req.params.id;
306
- const project = await Project.findOne({ _id: projectId });
307
- if (!project || !isProjectMember(project, auth.userId)) {
308
- return res.status(403).json({ error: 'Unauthorized project access' });
309
- }
310
- await Project.update({ _id: projectId, "members.userId": auth.userId }, { "members.$.archived": false, "members.$.archivedBy": null, "members.$.archivedAt": null });
311
- const updatedProject = await Project.findOne({ _id: projectId }); // Fetch the updated project
312
- const projects = (await Project.find({ members: { $elemMatch: { userId: auth.userId } } })).map(project => {
313
- const currentUserMember = project.members?.find((member) => member.userId === auth.userId);
314
- return {
315
- id: project._id || project.id,
316
- dbType: project.dbType,
317
- name: project.name,
318
- image: project.image || '',
319
- archived: currentUserMember ? currentUserMember.archived || false : false,
320
- };
321
- });
322
- // Replace the old project with the updated one in the list
323
- const finalProjects = projects.map(p => p.id === (updatedProject?._id || updatedProject?.id) ? ({ ...updatedProject, id: updatedProject._id || updatedProject.id, _id: undefined }) : p);
324
- res.status(200).json({ success: true, projects: finalProjects });
325
- }
326
- catch (err) {
327
- res.status(500).json({ error: 'Failed to unarchive project', details: err.message });
328
- }
329
- });
330
- router.get('/projects/:id/exports/:export_id', async (req, res) => {
331
- try {
332
- const auth = await config.authProvider(req);
333
- if (!auth ||
334
- !auth.userId ||
335
- !auth.role) {
336
- return res.status(401).json({ error: 'Unauthorized' });
337
- }
338
- const projectId = req.params.id;
339
- const exportId = req.params.export_id;
340
- const project = await Project.findOne({ _id: projectId });
341
- if (!project) {
342
- return res.status(404).json({ error: 'Project not found' });
343
- }
344
- if (!isProjectMember(project, auth.userId)) {
345
- return res.status(403).json({ error: 'Unauthorized access' });
346
- }
347
- const data = await Export.findOne({ _id: exportId });
348
- res.json({ data: { ...data, id: data._id || data.id, _id: undefined } });
349
- }
350
- catch (err) {
351
- res.status(500).json({ error: 'Failed to fetch export data', details: err.message });
352
- }
353
- });
354
- router.post('/projects/:id/exports', async (req, res) => {
355
- try {
356
- const auth = await config.authProvider(req);
357
- if (!auth ||
358
- !auth.userId ||
359
- !auth.role) {
360
- return res.status(401).json({ error: 'Unauthorized' });
361
- }
362
- const projectId = req.params.id;
363
- const { name, description, collectionName } = req.body;
364
- if (!name || !collectionName) {
365
- return res.status(400).json({ error: 'Missing export name or collectionName' });
366
- }
367
- const project = await Project.findOne({ _id: projectId });
368
- if (!project || !isProjectMember(project, auth.userId)) {
369
- return res.status(403).json({ error: 'Unauthorized project access' });
370
- }
371
- const newExport = await Export.create({
372
- name,
373
- description,
374
- collectionName,
375
- projectId
376
- });
377
- res.status(201).json({ data: { ...newExport, id: newExport._id || newExport.id, _id: undefined } });
378
- }
379
- catch (err) {
380
- res.status(500).json({ error: 'Failed to create export', details: err.message });
381
- }
382
- });
383
- router.get('/projects/:id/members', async (req, res) => {
384
- try {
385
- const auth = await config.authProvider(req);
386
- if (!auth ||
387
- !auth.userId ||
388
- !auth.role) {
389
- return res.status(401).json({ error: 'Unauthorized' });
390
- }
391
- const projectId = req.params.id;
392
- const project = await Project.findOne({ _id: projectId });
393
- if (!project) {
394
- return res.status(404).json({ error: 'Project not found' });
395
- }
396
- if (!isProjectMember(project, auth.userId)) {
397
- return res.status(403).json({ error: 'Unauthorized project access' });
398
- }
399
- res.json({ members: project.members });
400
- }
401
- catch (err) {
402
- res.status(500).json({ error: 'Failed to fetch project members', details: err.message });
403
- }
404
- });
28
+ }
29
+ router.use((0, auth_1.authRouter)(config));
30
+ router.use((0, database_1.databaseRouter)(config));
31
+ router.use((0, file_1.fileRouter)(config));
32
+ router.use((0, project_1.projectRouter)(config));
33
+ router.use((0, export_1.exportRouter)(config));
405
34
  return router;
406
35
  }
@@ -0,0 +1,3 @@
1
+ import { Router } from 'express';
2
+ import { StreamByConfig } from '../../types';
3
+ export declare function authRouter(config: StreamByConfig): Router;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authRouter = authRouter;
4
+ const express_1 = require("express");
5
+ function authRouter(config) {
6
+ const router = (0, express_1.Router)();
7
+ router.get('/auth', async (req, res) => {
8
+ try {
9
+ const auth = await config.authProvider(req);
10
+ if (!auth ||
11
+ !auth.userId ||
12
+ !auth.role) {
13
+ throw new Error('Invalid or missing authentication context');
14
+ }
15
+ return res.status(200).json({ logged: true, ...auth });
16
+ }
17
+ catch (err) {
18
+ return res.status(401).json({ logged: false });
19
+ }
20
+ });
21
+ return router;
22
+ }
@@ -0,0 +1,3 @@
1
+ import { Router } from 'express';
2
+ import { StreamByConfig } from '../../types';
3
+ export declare function databaseRouter(config: StreamByConfig): Router;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.databaseRouter = databaseRouter;
4
+ const express_1 = require("express");
5
+ const connectionManager_1 = require("../../adapters/database/connectionManager");
6
+ function databaseRouter(config) {
7
+ const router = (0, express_1.Router)();
8
+ router.get('/databases', async (req, res) => {
9
+ try {
10
+ const auth = await config.authProvider(req);
11
+ if (!auth ||
12
+ !auth.userId ||
13
+ !auth.role) {
14
+ return res.status(401).json({ error: 'Unauthorized' });
15
+ }
16
+ const connectedDbIds = (0, connectionManager_1.getConnectedIds)();
17
+ const databases = (config.databases || [])
18
+ .filter(db => connectedDbIds.includes(db.id))
19
+ .map(db => ({ name: db.id, value: db.type }));
20
+ res.status(200).json({ databases });
21
+ }
22
+ catch (err) {
23
+ res.status(500).json({ error: 'Failed to get databases' });
24
+ }
25
+ });
26
+ return router;
27
+ }
@@ -0,0 +1,3 @@
1
+ import { Router } from 'express';
2
+ import { StreamByConfig } from '../../types';
3
+ export declare function exportRouter(config: StreamByConfig): Router;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exportRouter = exportRouter;
4
+ const express_1 = require("express");
5
+ const manager_1 = require("../../models/manager");
6
+ const auth_1 = require("../../utils/auth");
7
+ function exportRouter(config) {
8
+ const router = (0, express_1.Router)();
9
+ const Project = (0, manager_1.getModel)('projects');
10
+ const Export = (0, manager_1.getModel)('exports');
11
+ router.get('/projects/:id/exports/:export_id', async (req, res) => {
12
+ try {
13
+ const auth = await config.authProvider(req);
14
+ if (!auth ||
15
+ !auth.userId ||
16
+ !auth.role) {
17
+ return res.status(401).json({ error: 'Unauthorized' });
18
+ }
19
+ const projectId = req.params.id;
20
+ const exportId = req.params.export_id;
21
+ const project = await Project.findOne({ _id: projectId });
22
+ if (!project) {
23
+ return res.status(404).json({ error: 'Project not found' });
24
+ }
25
+ if (!(0, auth_1.isProjectMember)(project, auth.userId)) {
26
+ return res.status(403).json({ error: 'Unauthorized access' });
27
+ }
28
+ const data = await Export.findOne({ _id: exportId });
29
+ res.json({ data: { ...data, id: data._id || data.id, _id: undefined } });
30
+ }
31
+ catch (err) {
32
+ res.status(500).json({ error: 'Failed to fetch export data', details: err.message });
33
+ }
34
+ });
35
+ router.post('/projects/:id/exports', async (req, res) => {
36
+ try {
37
+ const auth = await config.authProvider(req);
38
+ if (!auth ||
39
+ !auth.userId ||
40
+ !auth.role) {
41
+ return res.status(401).json({ error: 'Unauthorized' });
42
+ }
43
+ const projectId = req.params.id;
44
+ const { name, description, collectionName } = req.body;
45
+ if (!name || !collectionName) {
46
+ return res.status(400).json({ error: 'Missing export name or collectionName' });
47
+ }
48
+ const project = await Project.findOne({ _id: projectId });
49
+ if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
50
+ return res.status(403).json({ error: 'Unauthorized project access' });
51
+ }
52
+ const newExport = await Export.create({
53
+ name,
54
+ description,
55
+ collectionName,
56
+ projectId
57
+ });
58
+ res.status(201).json({ data: { ...newExport, id: newExport._id || newExport.id, _id: undefined } });
59
+ }
60
+ catch (err) {
61
+ res.status(500).json({ error: 'Failed to create export', details: err.message });
62
+ }
63
+ });
64
+ return router;
65
+ }
@@ -0,0 +1,5 @@
1
+ import { Router } from 'express';
2
+ import { StreamByConfig, StorageAdapter } from '../../types';
3
+ export declare function fileRouter(config: StreamByConfig & {
4
+ adapter?: StorageAdapter;
5
+ }): Router;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fileRouter = fileRouter;
4
+ const express_1 = require("express");
5
+ const file_1 = require("../../services/file");
6
+ const presign_1 = require("../../services/presign");
7
+ const storage_1 = require("../../providers/storage");
8
+ const manager_1 = require("../../models/manager");
9
+ function fileRouter(config) {
10
+ const router = (0, express_1.Router)();
11
+ const adapter = config.adapter || (0, storage_1.createStorageProvider)(config.storageProviders);
12
+ const Project = (0, manager_1.getModel)('projects');
13
+ router.get('/upload-project-image-url/:id', async (req, res) => {
14
+ try {
15
+ const auth = await config.authProvider(req);
16
+ if (!auth ||
17
+ !auth.userId ||
18
+ !auth.role) {
19
+ return res.status(401).json({ error: 'Unauthorized' });
20
+ }
21
+ if (auth.role !== 'admin' && auth.role !== 'editor') {
22
+ return res.status(403).json({ error: 'Permission denied' });
23
+ }
24
+ const projectId = req.params.id;
25
+ if (!projectId) {
26
+ return res.status(400).json({ error: 'Missing projectId' });
27
+ }
28
+ const response = await (0, presign_1.getPresignedProjectImageUrl)(adapter, projectId);
29
+ res.status(200).json(response);
30
+ }
31
+ catch (err) {
32
+ res.status(500).json({ error: 'Failed to generate presigned URL', details: err.message });
33
+ }
34
+ });
35
+ router.delete('/delete-project-image-url/:id', async (req, res) => {
36
+ try {
37
+ const auth = await config.authProvider(req);
38
+ if (!auth ||
39
+ !auth.userId ||
40
+ !auth.role) {
41
+ return res.status(401).json({ error: 'Unauthorized' });
42
+ }
43
+ if (auth.role !== 'admin' && auth.role !== 'editor') {
44
+ return res.status(403).json({ error: 'Permission denied' });
45
+ }
46
+ const projectId = req.params.id;
47
+ if (!projectId) {
48
+ return res.status(400).json({ error: 'Missing projectId' });
49
+ }
50
+ await (0, file_1.deleteProjectImage)(adapter, projectId);
51
+ const updated = await Project.update({ _id: projectId }, { image: '' });
52
+ res.status(201).json(updated);
53
+ }
54
+ catch (err) {
55
+ res.status(500).json({ error: 'Failed to delete image', details: err.message });
56
+ }
57
+ });
58
+ router.get('/files', async (req, res) => {
59
+ try {
60
+ const auth = await config.authProvider(req);
61
+ if (!auth ||
62
+ !auth.userId ||
63
+ !auth.role) {
64
+ return res.status(401).json({ error: 'Unauthorized' });
65
+ }
66
+ const projectId = (req.query.projectId || req.headers['x-project-id']);
67
+ if (!projectId) {
68
+ return res.status(403).json({ error: 'Unauthorized or missing projectId' });
69
+ }
70
+ const files = await (0, file_1.listFilesService)(adapter, req, projectId);
71
+ res.json(files);
72
+ }
73
+ catch (err) {
74
+ res.status(500).json({ error: 'Failed to list files', details: err });
75
+ }
76
+ });
77
+ return router;
78
+ }
@@ -0,0 +1,3 @@
1
+ import { Router } from 'express';
2
+ import { StreamByConfig } from '../../types';
3
+ export declare function projectRouter(config: StreamByConfig): Router;