streamby-core 0.17.0 → 0.18.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.
@@ -152,15 +152,16 @@ function createStreamByRouter(config) {
152
152
  router.get('/projects', async (req, res) => {
153
153
  try {
154
154
  const auth = await config.authProvider(req);
155
+ const archived = req.query.archived ? String(req.query.archived).toLowerCase() === 'true' : undefined;
155
156
  const projects = [];
156
157
  if (projectProviders.nosql) {
157
- projects.push(...await projectProviders.nosql.list(auth.userId));
158
+ projects.push(...await projectProviders.nosql.list(auth.userId, archived));
158
159
  }
159
160
  if (projectProviders.sql) {
160
- projects.push(...await projectProviders.sql.list(auth.userId));
161
+ projects.push(...await projectProviders.sql.list(auth.userId, archived));
161
162
  }
162
163
  if (projectProviders.default) {
163
- projects.push(...await projectProviders.default.list(auth.userId));
164
+ projects.push(...await projectProviders.default.list(auth.userId, archived));
164
165
  }
165
166
  res.json({ projects });
166
167
  }
@@ -276,8 +277,18 @@ function createStreamByRouter(config) {
276
277
  if (!project || !isProjectMember(project, auth.userId)) {
277
278
  return res.status(403).json({ error: 'Unauthorized project access' });
278
279
  }
279
- const result = await projectProvider.archive(projectId, auth.userId);
280
- res.status(200).json(result);
280
+ await projectProvider.archive(projectId, auth.userId);
281
+ const projects = [];
282
+ if (projectProviders.nosql) {
283
+ projects.push(...await projectProviders.nosql.list(auth.userId));
284
+ }
285
+ if (projectProviders.sql) {
286
+ projects.push(...await projectProviders.sql.list(auth.userId));
287
+ }
288
+ if (projectProviders.default) {
289
+ projects.push(...await projectProviders.default.list(auth.userId));
290
+ }
291
+ res.status(200).json({ success: true, projects });
281
292
  }
282
293
  catch (err) {
283
294
  res.status(500).json({ error: 'Failed to archive project', details: err.message });
@@ -295,8 +306,18 @@ function createStreamByRouter(config) {
295
306
  if (!project || !isProjectMember(project, auth.userId)) {
296
307
  return res.status(403).json({ error: 'Unauthorized project access' });
297
308
  }
298
- const result = await projectProvider.unarchive(projectId, auth.userId);
299
- res.status(200).json(result);
309
+ await projectProvider.unarchive(projectId, auth.userId);
310
+ const projects = [];
311
+ if (projectProviders.nosql) {
312
+ projects.push(...await projectProviders.nosql.list(auth.userId));
313
+ }
314
+ if (projectProviders.sql) {
315
+ projects.push(...await projectProviders.sql.list(auth.userId));
316
+ }
317
+ if (projectProviders.default) {
318
+ projects.push(...await projectProviders.default.list(auth.userId));
319
+ }
320
+ res.status(200).json({ success: true, projects });
300
321
  }
301
322
  catch (err) {
302
323
  res.status(500).json({ error: 'Failed to unarchive project', details: err.message });
@@ -38,10 +38,16 @@ function createMongooseProjectProvider(ProjectModel, ExportModel, adapter) {
38
38
  throw new Error('Project not found');
39
39
  return formatProject(updated);
40
40
  },
41
- async list(userId) {
42
- const all = await ProjectModel.find(userId
43
- ? { 'members': { $elemMatch: { userId } } }
44
- : {});
41
+ async list(userId, archived) {
42
+ const query = {};
43
+ if (userId) {
44
+ const elemMatch = { userId };
45
+ if (typeof archived === 'boolean') {
46
+ elemMatch.archived = archived;
47
+ }
48
+ query['members'] = { $elemMatch: elemMatch };
49
+ }
50
+ const all = await ProjectModel.find(query);
45
51
  return all.map(doc => formatProjectList(doc, userId));
46
52
  },
47
53
  async delete(projectId) {
@@ -58,9 +58,18 @@ function createPrismaProjectProvider(prisma, adapter) {
58
58
  throw new Error('Project not found');
59
59
  return formatProject(updated);
60
60
  },
61
- async list(userId) {
61
+ async list(userId, archived) {
62
+ const whereClause = {};
63
+ if (userId) {
64
+ whereClause.members = {
65
+ some: {
66
+ userId,
67
+ ...(typeof archived === 'boolean' && { archived }),
68
+ },
69
+ };
70
+ }
62
71
  const all = await prisma.project.findMany({
63
- where: userId ? { members: { some: { userId } } } : {},
72
+ where: whereClause,
64
73
  include: {
65
74
  members: true,
66
75
  },
@@ -24,7 +24,7 @@ function checkRole(auth, required) {
24
24
  }
25
25
  async function dummyAuthProvider(req) {
26
26
  return {
27
- userId: 'cd9912a7-e6bd-4c85-85fa-a21f5e19f2cb',
27
+ userId: 'c52c30eb-9d7c-4727-90e6-e0e88d6a5ffd',
28
28
  username: 'dev-user',
29
29
  projects: [],
30
30
  role: 'admin'
@@ -107,7 +107,7 @@ export interface ProjectProvider {
107
107
  success: boolean;
108
108
  projects: ProjectListInfo[];
109
109
  }>;
110
- list(userId?: string): Promise<ProjectListInfo[]>;
110
+ list(userId?: string, archived?: boolean): Promise<ProjectListInfo[]>;
111
111
  getById(projectId: string, populateMembers?: boolean): Promise<ProjectInfo | null>;
112
112
  delete(projectId: string): Promise<{
113
113
  success: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamby-core",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "StreamBy middleware framework for media storage management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",