streamby-core 0.5.0 → 0.7.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 +4 -8
- package/dist/middleware/createRouter.js +25 -7
- package/dist/services/presign.d.ts +2 -0
- package/dist/services/presign.js +9 -0
- package/dist/services/project.d.ts +1 -0
- package/dist/services/project.js +2 -4
- package/dist/types/index.d.ts +2 -4
- package/package.json +1 -1
package/dist/adapters/s3.js
CHANGED
|
@@ -12,17 +12,13 @@ function createS3Adapter(config) {
|
|
|
12
12
|
},
|
|
13
13
|
});
|
|
14
14
|
return {
|
|
15
|
-
async getPresignedUrl(
|
|
16
|
-
const key = type === 'project-image'
|
|
17
|
-
? `projects/${projectId}/image-${Date.now()}-${filename}`
|
|
18
|
-
: `${projectId}/${filename}`;
|
|
15
|
+
async getPresignedUrl(filename, contentType) {
|
|
19
16
|
const command = new client_s3_1.PutObjectCommand({
|
|
20
17
|
Bucket: config.bucket,
|
|
21
|
-
Key:
|
|
22
|
-
ContentType:
|
|
18
|
+
Key: `uploads/${filename}`,
|
|
19
|
+
ContentType: contentType,
|
|
23
20
|
});
|
|
24
|
-
|
|
25
|
-
return { url, key };
|
|
21
|
+
return (0, s3_request_presigner_1.getSignedUrl)(s3, command, { expiresIn: 3600 });
|
|
26
22
|
},
|
|
27
23
|
async uploadFile(req, projectId) {
|
|
28
24
|
const file = req.body?.file;
|
|
@@ -8,6 +8,7 @@ const express_1 = __importDefault(require("express"));
|
|
|
8
8
|
const s3_1 = require("../adapters/s3");
|
|
9
9
|
const file_1 = require("../services/file");
|
|
10
10
|
const project_1 = require("../services/project");
|
|
11
|
+
const presign_1 = require("../services/presign");
|
|
11
12
|
function createStreamByRouter(config) {
|
|
12
13
|
const router = express_1.default.Router();
|
|
13
14
|
const adapter = config.adapter || (() => {
|
|
@@ -27,19 +28,18 @@ function createStreamByRouter(config) {
|
|
|
27
28
|
res.status(401).json({ logged: false });
|
|
28
29
|
}
|
|
29
30
|
});
|
|
30
|
-
router.post('/upload-
|
|
31
|
+
router.post('/upload-url', async (req, res) => {
|
|
31
32
|
try {
|
|
32
33
|
const auth = await config.authProvider(req);
|
|
33
34
|
if (auth.role !== 'admin' && auth.role !== 'editor') {
|
|
34
35
|
return res.status(403).json({ error: 'Permission denied' });
|
|
35
36
|
}
|
|
36
|
-
const { filename,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return res.status(400).json({ error: 'Missing filename or projectId' });
|
|
37
|
+
const { filename, contentType } = req.body;
|
|
38
|
+
if (!filename || !contentType) {
|
|
39
|
+
return res.status(400).json({ error: 'Missing filename or contentType' });
|
|
40
40
|
}
|
|
41
|
-
const
|
|
42
|
-
res.
|
|
41
|
+
const url = await (0, presign_1.getPresignedUrl)(adapter, filename, contentType);
|
|
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,6 +59,24 @@ 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) => {
|
|
63
|
+
try {
|
|
64
|
+
const auth = await config.authProvider(req);
|
|
65
|
+
if (auth.role !== 'admin' && auth.role !== 'editor') {
|
|
66
|
+
return res.status(403).json({ error: 'Permission denied' });
|
|
67
|
+
}
|
|
68
|
+
const projectId = req.params.id;
|
|
69
|
+
const { image } = req.body;
|
|
70
|
+
if (!image) {
|
|
71
|
+
return res.status(400).json({ error: 'Missing image key' });
|
|
72
|
+
}
|
|
73
|
+
const updated = await config.projectProvider.updateImage(projectId, image);
|
|
74
|
+
res.status(200).json(updated);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
res.status(500).json({ error: 'Failed to update project image', details: err.message });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
62
80
|
router.post('/upload', async (req, res) => {
|
|
63
81
|
try {
|
|
64
82
|
const auth = await config.authProvider(req);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPresignedUrl = getPresignedUrl;
|
|
4
|
+
async function getPresignedUrl(adapter, filename, contentType) {
|
|
5
|
+
if (!('getPresignedUrl' in adapter)) {
|
|
6
|
+
throw new Error('StorageAdapter does not support presigned URLs');
|
|
7
|
+
}
|
|
8
|
+
return adapter.getPresignedUrl(filename, contentType);
|
|
9
|
+
}
|
package/dist/services/project.js
CHANGED
|
@@ -8,10 +8,7 @@ async function createProjectService(req, projectProvider) {
|
|
|
8
8
|
}
|
|
9
9
|
const newProject = await projectProvider.create({
|
|
10
10
|
name,
|
|
11
|
-
description: description || ''
|
|
12
|
-
rootFolders: [],
|
|
13
|
-
allowUpload: true,
|
|
14
|
-
allowSharing: false
|
|
11
|
+
description: description || ''
|
|
15
12
|
});
|
|
16
13
|
return {
|
|
17
14
|
success: true,
|
|
@@ -19,6 +16,7 @@ async function createProjectService(req, projectProvider) {
|
|
|
19
16
|
id: newProject.id,
|
|
20
17
|
name: newProject.name,
|
|
21
18
|
description: newProject.description,
|
|
19
|
+
image: newProject.image,
|
|
22
20
|
settings: newProject.settings,
|
|
23
21
|
rootFolders: newProject.rootFolders || [],
|
|
24
22
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,12 +7,9 @@ export interface S3Config {
|
|
|
7
7
|
}
|
|
8
8
|
export type StorageProviderType = 's3';
|
|
9
9
|
export interface StorageAdapter {
|
|
10
|
-
getPresignedUrl(projectId: string, filename: string, type?: string): Promise<{
|
|
11
|
-
url: string;
|
|
12
|
-
key: string;
|
|
13
|
-
}>;
|
|
14
10
|
uploadFile(req: Request, projectId: string): Promise<any>;
|
|
15
11
|
listFiles(projectId: string): Promise<any[]>;
|
|
12
|
+
getPresignedUrl?: (filename: string, contentType: string) => Promise<string>;
|
|
16
13
|
}
|
|
17
14
|
export interface ProjectInfo {
|
|
18
15
|
id: string;
|
|
@@ -47,6 +44,7 @@ export interface AuthContext {
|
|
|
47
44
|
export type AuthProvider = (req: Request) => Promise<AuthContext>;
|
|
48
45
|
export interface ProjectProvider {
|
|
49
46
|
getById(projectId: string): Promise<ProjectInfo>;
|
|
47
|
+
updateImage: (projectId: string, imageKey: string) => Promise<ProjectInfo>;
|
|
50
48
|
create(data: {
|
|
51
49
|
name: string;
|
|
52
50
|
image?: string;
|