streamby-core 0.9.16 → 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
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.createS3Adapter = createS3Adapter;
|
|
7
4
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
8
5
|
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
9
|
-
const bcrypt_1 = __importDefault(require("bcrypt"));
|
|
10
6
|
function createS3Adapter(config) {
|
|
11
7
|
const s3 = new client_s3_1.S3Client({
|
|
12
8
|
region: config.region,
|
|
@@ -16,10 +12,19 @@ function createS3Adapter(config) {
|
|
|
16
12
|
},
|
|
17
13
|
});
|
|
18
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
|
+
},
|
|
19
26
|
async getPresignedUrl(filename, contentType, projectId) {
|
|
20
|
-
const
|
|
21
|
-
const hashed = await bcrypt_1.default.hash(filename, salt);
|
|
22
|
-
const key = `${projectId}/${contentType}/file-${Date.now()}-${hashed.replace(/\//g, '-')}`;
|
|
27
|
+
const key = `${projectId}/${contentType}/file-${Date.now()}`;
|
|
23
28
|
const command = new client_s3_1.PutObjectCommand({
|
|
24
29
|
Bucket: config.bucket,
|
|
25
30
|
Key: key,
|
|
@@ -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;
|