streamby-core 0.7.2 → 0.8.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.
@@ -12,13 +12,15 @@ function createS3Adapter(config) {
12
12
  },
13
13
  });
14
14
  return {
15
- async getPresignedUrl(filename, contentType) {
15
+ async getPresignedUrl(filename, contentType, projectId) {
16
+ const key = `projects/${projectId}/file-${Date.now()}-${filename}`;
16
17
  const command = new client_s3_1.PutObjectCommand({
17
18
  Bucket: config.bucket,
18
- Key: `uploads/${filename}`,
19
+ Key: key,
19
20
  ContentType: contentType,
20
21
  });
21
- return (0, s3_request_presigner_1.getSignedUrl)(s3, command, { expiresIn: 3600 });
22
+ const url = await (0, s3_request_presigner_1.getSignedUrl)(s3, command, { expiresIn: 60 });
23
+ return { url, key };
22
24
  },
23
25
  async uploadFile(req, projectId) {
24
26
  const file = req.body?.file;
@@ -34,12 +34,12 @@ function createStreamByRouter(config) {
34
34
  if (auth.role !== 'admin' && auth.role !== 'editor') {
35
35
  return res.status(403).json({ error: 'Permission denied' });
36
36
  }
37
- const { filename, contentType } = req.body;
38
- if (!filename || !contentType) {
39
- return res.status(400).json({ error: 'Missing filename or contentType' });
37
+ const { filename, contentType, projectId } = req.body;
38
+ if (!filename || !contentType || !projectId) {
39
+ return res.status(400).json({ error: 'Missing filename, contentType, or projectId' });
40
40
  }
41
- const url = await (0, presign_1.getPresignedUrl)(adapter, filename, contentType);
42
- res.json({ url });
41
+ const url = await (0, presign_1.getPresignedUrl)(adapter, filename, contentType, projectId);
42
+ res.json(url);
43
43
  }
44
44
  catch (err) {
45
45
  res.status(500).json({ error: 'Failed to generate presigned URL', details: err.message });
@@ -59,22 +59,22 @@ function createStreamByRouter(config) {
59
59
  res.status(500).json({ error: 'Failed to list files', details: err });
60
60
  }
61
61
  });
62
- router.patch('/projects/:id/image', async (req, res) => {
62
+ router.patch('/projects/:id', async (req, res) => {
63
63
  try {
64
64
  const auth = await config.authProvider(req);
65
65
  if (auth.role !== 'admin' && auth.role !== 'editor') {
66
66
  return res.status(403).json({ error: 'Permission denied' });
67
67
  }
68
68
  const projectId = req.params.id;
69
- const { image } = req.body;
70
- if (!image) {
71
- return res.status(400).json({ error: 'Missing image key' });
69
+ const updates = req.body;
70
+ if (!updates || typeof updates !== 'object') {
71
+ return res.status(400).json({ error: 'Missing updates payload' });
72
72
  }
73
- const updated = await config.projectProvider.updateImage(projectId, image);
74
- res.status(200).json(updated);
73
+ const updated = await config.projectProvider.update(projectId, updates);
74
+ res.status(200).json({ success: true, project: updated });
75
75
  }
76
76
  catch (err) {
77
- res.status(500).json({ error: 'Failed to update project image', details: err.message });
77
+ res.status(500).json({ error: 'Failed to update project', details: err.message });
78
78
  }
79
79
  });
80
80
  router.post('/upload', async (req, res) => {
@@ -1,2 +1,2 @@
1
1
  import { StorageAdapter } from '../types';
2
- export declare function getPresignedUrl(adapter: StorageAdapter, filename: string, contentType: string): Promise<string>;
2
+ export declare function getPresignedUrl(adapter: StorageAdapter, filename: string, contentType: string, projectId: string): Promise<any>;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPresignedUrl = getPresignedUrl;
4
- async function getPresignedUrl(adapter, filename, contentType) {
4
+ async function getPresignedUrl(adapter, filename, contentType, projectId) {
5
5
  if (!('getPresignedUrl' in adapter)) {
6
6
  throw new Error('StorageAdapter does not support presigned URLs');
7
7
  }
8
- return adapter.getPresignedUrl(filename, contentType);
8
+ return adapter.getPresignedUrl(filename, contentType, projectId);
9
9
  }
@@ -9,7 +9,7 @@ export type StorageProviderType = 's3';
9
9
  export interface StorageAdapter {
10
10
  uploadFile(req: Request, projectId: string): Promise<any>;
11
11
  listFiles(projectId: string): Promise<any[]>;
12
- getPresignedUrl?: (filename: string, contentType: string) => Promise<string>;
12
+ getPresignedUrl?: (filename: string, contentType: string, projectId: string) => Promise<any>;
13
13
  }
14
14
  export interface ProjectInfo {
15
15
  id: string;
@@ -44,7 +44,7 @@ export interface AuthContext {
44
44
  export type AuthProvider = (req: Request) => Promise<AuthContext>;
45
45
  export interface ProjectProvider {
46
46
  getById(projectId: string): Promise<ProjectInfo>;
47
- updateImage: (projectId: string, imageKey: string) => Promise<ProjectInfo>;
47
+ update(projectId: string, updates: Partial<Omit<ProjectInfo, 'id' | 'rootFolders'>>): Promise<ProjectInfo>;
48
48
  create(data: {
49
49
  name: string;
50
50
  image?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamby-core",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "StreamBy middleware framework for media storage management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",