streamby-core 0.4.1 → 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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createS3Adapter = createS3Adapter;
|
|
4
|
+
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
4
5
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
5
6
|
function createS3Adapter(config) {
|
|
6
7
|
const s3 = new client_s3_1.S3Client({
|
|
@@ -11,6 +12,14 @@ function createS3Adapter(config) {
|
|
|
11
12
|
},
|
|
12
13
|
});
|
|
13
14
|
return {
|
|
15
|
+
async getPresignedUrl(filename, contentType) {
|
|
16
|
+
const command = new client_s3_1.PutObjectCommand({
|
|
17
|
+
Bucket: config.bucket,
|
|
18
|
+
Key: `uploads/${filename}`,
|
|
19
|
+
ContentType: contentType,
|
|
20
|
+
});
|
|
21
|
+
return (0, s3_request_presigner_1.getSignedUrl)(s3, command, { expiresIn: 3600 });
|
|
22
|
+
},
|
|
14
23
|
async uploadFile(req, projectId) {
|
|
15
24
|
const file = req.body?.file;
|
|
16
25
|
if (!file || !file.name || !file.buffer) {
|
|
@@ -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,6 +28,23 @@ function createStreamByRouter(config) {
|
|
|
27
28
|
res.status(401).json({ logged: false });
|
|
28
29
|
}
|
|
29
30
|
});
|
|
31
|
+
router.post('/upload-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 } = req.body;
|
|
38
|
+
if (!filename || !contentType) {
|
|
39
|
+
return res.status(400).json({ error: 'Missing filename or contentType' });
|
|
40
|
+
}
|
|
41
|
+
const url = await (0, presign_1.getPresignedUrl)(adapter, filename, contentType);
|
|
42
|
+
res.json({ url });
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
res.status(500).json({ error: 'Failed to generate presigned URL', details: err.message });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
30
48
|
router.get('/files', async (req, res) => {
|
|
31
49
|
try {
|
|
32
50
|
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/types/index.d.ts
CHANGED
|
@@ -9,10 +9,12 @@ 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<string>;
|
|
12
13
|
}
|
|
13
14
|
export interface ProjectInfo {
|
|
14
15
|
id: string;
|
|
15
16
|
name: string;
|
|
17
|
+
image?: string;
|
|
16
18
|
description?: string;
|
|
17
19
|
rootFolders?: FolderNode[];
|
|
18
20
|
settings?: {
|
|
@@ -35,6 +37,7 @@ export interface StreamByConfig {
|
|
|
35
37
|
}
|
|
36
38
|
export interface AuthContext {
|
|
37
39
|
userId: string;
|
|
40
|
+
username: string;
|
|
38
41
|
projects: string[];
|
|
39
42
|
role: 'viewer' | 'editor' | 'admin';
|
|
40
43
|
}
|
|
@@ -43,6 +46,7 @@ export interface ProjectProvider {
|
|
|
43
46
|
getById(projectId: string): Promise<ProjectInfo>;
|
|
44
47
|
create(data: {
|
|
45
48
|
name: string;
|
|
49
|
+
image?: string;
|
|
46
50
|
description?: string;
|
|
47
51
|
allowUpload?: boolean;
|
|
48
52
|
allowSharing?: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "streamby-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "StreamBy middleware framework for media storage management",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@aws-sdk/client-s3": "^3.528.0",
|
|
33
|
+
"@aws-sdk/s3-request-presigner": "^3.787.0",
|
|
33
34
|
"express": "^4.0.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|