streamby-core 0.5.0 → 0.6.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
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 });
|
|
@@ -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/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;
|