streamby-core 0.9.17 → 0.9.18
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
CHANGED
|
@@ -12,6 +12,17 @@ function createS3Adapter(config) {
|
|
|
12
12
|
},
|
|
13
13
|
});
|
|
14
14
|
return {
|
|
15
|
+
async getPresignedProjectImageUrl(projectId) {
|
|
16
|
+
const key = `${projectId}/project-image`;
|
|
17
|
+
const command = new client_s3_1.PutObjectCommand({
|
|
18
|
+
Bucket: config.bucket,
|
|
19
|
+
Key: key,
|
|
20
|
+
ContentType: 'image/*',
|
|
21
|
+
});
|
|
22
|
+
const url = await (0, s3_request_presigner_1.getSignedUrl)(s3, command, { expiresIn: 60 });
|
|
23
|
+
const publicUrl = `https://${config.bucket}.s3.${config.region}.amazonaws.com/${encodeURIComponent(key)}`;
|
|
24
|
+
return { url, publicUrl };
|
|
25
|
+
},
|
|
15
26
|
async getPresignedUrl(filename, contentType, projectId) {
|
|
16
27
|
const key = `${projectId}/${contentType}/file-${Date.now()}`;
|
|
17
28
|
const command = new client_s3_1.PutObjectCommand({
|
|
@@ -28,6 +28,23 @@ function createStreamByRouter(config) {
|
|
|
28
28
|
res.status(401).json({ logged: false });
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
+
router.post('/upload-project-image-url', async (req, res) => {
|
|
32
|
+
try {
|
|
33
|
+
const auth = await config.authProvider(req);
|
|
34
|
+
if (auth.role !== 'admin' && auth.role !== 'editor') {
|
|
35
|
+
return res.status(403).json({ error: 'Permission denied' });
|
|
36
|
+
}
|
|
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
|
+
}
|
|
41
|
+
const url = await (0, presign_1.getPresignedProjectImageUrl)(adapter, filename);
|
|
42
|
+
res.json(url);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
res.status(500).json({ error: 'Failed to generate presigned URL', details: err.message });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
31
48
|
router.post('/upload-url', async (req, res) => {
|
|
32
49
|
try {
|
|
33
50
|
const auth = await config.authProvider(req);
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { StorageAdapter } from '../types';
|
|
2
2
|
export declare function getPresignedUrl(adapter: StorageAdapter, filename: string, contentType: string, projectId: string): Promise<any>;
|
|
3
|
+
export declare function getPresignedProjectImageUrl(adapter: StorageAdapter, projectId: string): Promise<any>;
|
package/dist/services/presign.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPresignedUrl = getPresignedUrl;
|
|
4
|
+
exports.getPresignedProjectImageUrl = getPresignedProjectImageUrl;
|
|
4
5
|
async function getPresignedUrl(adapter, filename, contentType, projectId) {
|
|
5
6
|
if (!('getPresignedUrl' in adapter)) {
|
|
6
7
|
throw new Error('StorageAdapter does not support presigned URLs');
|
|
7
8
|
}
|
|
8
9
|
return adapter.getPresignedUrl(filename, contentType, projectId);
|
|
9
10
|
}
|
|
11
|
+
async function getPresignedProjectImageUrl(adapter, projectId) {
|
|
12
|
+
if (!('getPresignedProjectImageUrl' in adapter)) {
|
|
13
|
+
throw new Error('StorageAdapter does not support presigned URLs');
|
|
14
|
+
}
|
|
15
|
+
return adapter.getPresignedProjectImageUrl(projectId);
|
|
16
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -9,8 +9,9 @@ export interface S3Config {
|
|
|
9
9
|
export type StorageProviderType = 's3';
|
|
10
10
|
export interface StorageAdapter {
|
|
11
11
|
listFiles(projectId: string): Promise<any[]>;
|
|
12
|
-
getPresignedUrl?: (filename: string, contentType: string, projectId: string) => Promise<any>;
|
|
13
12
|
deleteProjectDirectory: (projectId: string) => Promise<any>;
|
|
13
|
+
getPresignedUrl?: (filename: string, contentType: string, projectId: string) => Promise<any>;
|
|
14
|
+
getPresignedProjectImageUrl?: (projectId: string) => Promise<any>;
|
|
14
15
|
}
|
|
15
16
|
export interface ProjectInfo {
|
|
16
17
|
id: string;
|