streamby-core 0.7.1 → 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.
- package/dist/adapters/s3.js +5 -3
- package/dist/middleware/createRouter.js +12 -12
- package/dist/services/presign.d.ts +1 -1
- package/dist/services/presign.js +2 -2
- package/dist/services/project.d.ts +1 -1
- package/dist/services/project.js +1 -1
- package/dist/types/index.d.ts +4 -4
- package/package.json +1 -1
package/dist/adapters/s3.js
CHANGED
|
@@ -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:
|
|
19
|
+
Key: key,
|
|
19
20
|
ContentType: contentType,
|
|
20
21
|
});
|
|
21
|
-
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
70
|
-
if (!
|
|
71
|
-
return res.status(400).json({ error: 'Missing
|
|
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.
|
|
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
|
|
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<
|
|
2
|
+
export declare function getPresignedUrl(adapter: StorageAdapter, filename: string, contentType: string, projectId: string): Promise<any>;
|
package/dist/services/presign.js
CHANGED
|
@@ -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
|
}
|
|
@@ -3,7 +3,7 @@ import { ProjectProvider } from '../types';
|
|
|
3
3
|
export declare function createProjectService(req: Request, projectProvider: ProjectProvider): Promise<{
|
|
4
4
|
success: boolean;
|
|
5
5
|
project: {
|
|
6
|
-
|
|
6
|
+
id: string;
|
|
7
7
|
name: string;
|
|
8
8
|
image: string | undefined;
|
|
9
9
|
description: string | undefined;
|
package/dist/services/project.js
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ 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<
|
|
12
|
+
getPresignedUrl?: (filename: string, contentType: string, projectId: string) => Promise<any>;
|
|
13
13
|
}
|
|
14
14
|
export interface ProjectInfo {
|
|
15
|
-
|
|
15
|
+
id: string;
|
|
16
16
|
name: string;
|
|
17
17
|
image?: string;
|
|
18
18
|
description?: string;
|
|
@@ -23,7 +23,7 @@ export interface ProjectInfo {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
export interface FolderNode {
|
|
26
|
-
|
|
26
|
+
id: string;
|
|
27
27
|
name: string;
|
|
28
28
|
children?: FolderNode[];
|
|
29
29
|
}
|
|
@@ -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
|
-
|
|
47
|
+
update(projectId: string, updates: Partial<Omit<ProjectInfo, 'id' | 'rootFolders'>>): Promise<ProjectInfo>;
|
|
48
48
|
create(data: {
|
|
49
49
|
name: string;
|
|
50
50
|
image?: string;
|