streamby-core 0.9.22 → 0.10.1
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/db/initProjectModel.d.ts +240 -240
- package/dist/index.d.ts +4 -0
- package/dist/index.js +14 -2
- package/dist/middleware/createRouter.js +18 -9
- package/dist/services/auth.d.ts +1 -0
- package/dist/services/auth.js +9 -0
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { StreamByConfig, StorageAdapter } from './types';
|
|
1
2
|
export { initProjectModel } from './db/initProjectModel';
|
|
2
3
|
export { createStreamByRouter } from './middleware/createRouter';
|
|
3
4
|
export { createMongoProjectProvider } from './providers/mongoProjectProvider';
|
|
5
|
+
export declare function createStreamByApp(config: StreamByConfig & {
|
|
6
|
+
adapter?: StorageAdapter;
|
|
7
|
+
}): import("express-serve-static-core").Express;
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.createMongoProjectProvider = exports.createStreamByRouter = exports.initProjectModel = void 0;
|
|
7
|
+
exports.createStreamByApp = createStreamByApp;
|
|
8
|
+
const express_1 = __importDefault(require("express"));
|
|
9
|
+
const createRouter_1 = require("./middleware/createRouter");
|
|
4
10
|
var initProjectModel_1 = require("./db/initProjectModel");
|
|
5
11
|
Object.defineProperty(exports, "initProjectModel", { enumerable: true, get: function () { return initProjectModel_1.initProjectModel; } });
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "createStreamByRouter", { enumerable: true, get: function () { return
|
|
12
|
+
var createRouter_2 = require("./middleware/createRouter");
|
|
13
|
+
Object.defineProperty(exports, "createStreamByRouter", { enumerable: true, get: function () { return createRouter_2.createStreamByRouter; } });
|
|
8
14
|
var mongoProjectProvider_1 = require("./providers/mongoProjectProvider");
|
|
9
15
|
Object.defineProperty(exports, "createMongoProjectProvider", { enumerable: true, get: function () { return mongoProjectProvider_1.createMongoProjectProvider; } });
|
|
16
|
+
function createStreamByApp(config) {
|
|
17
|
+
const app = (0, express_1.default)();
|
|
18
|
+
app.use(express_1.default.json());
|
|
19
|
+
app.use((0, createRouter_1.createStreamByRouter)(config));
|
|
20
|
+
return app;
|
|
21
|
+
}
|
|
@@ -9,6 +9,9 @@ const s3_1 = require("../adapters/s3");
|
|
|
9
9
|
const file_1 = require("../services/file");
|
|
10
10
|
const project_1 = require("../services/project");
|
|
11
11
|
const presign_1 = require("../services/presign");
|
|
12
|
+
function isProjectMember(project, userId) {
|
|
13
|
+
return project.members?.some((m) => m.userId?.toString() === userId?.toString());
|
|
14
|
+
}
|
|
12
15
|
function createStreamByRouter(config) {
|
|
13
16
|
const router = express_1.default.Router();
|
|
14
17
|
const adapter = config.adapter || (() => {
|
|
@@ -36,7 +39,7 @@ function createStreamByRouter(config) {
|
|
|
36
39
|
}
|
|
37
40
|
const projectId = req.params.id;
|
|
38
41
|
if (!projectId) {
|
|
39
|
-
return res.status(400).json({ error: 'Missing
|
|
42
|
+
return res.status(400).json({ error: 'Missing projectId' });
|
|
40
43
|
}
|
|
41
44
|
const url = await (0, presign_1.getPresignedProjectImageUrl)(adapter, projectId);
|
|
42
45
|
res.json(url);
|
|
@@ -53,14 +56,14 @@ function createStreamByRouter(config) {
|
|
|
53
56
|
}
|
|
54
57
|
const projectId = req.params.id;
|
|
55
58
|
if (!projectId) {
|
|
56
|
-
return res.status(400).json({ error: 'Missing
|
|
59
|
+
return res.status(400).json({ error: 'Missing projectId' });
|
|
57
60
|
}
|
|
58
61
|
await (0, file_1.deleteProjectImage)(adapter, projectId);
|
|
59
62
|
const updated = await (0, project_1.deleteProjectImageService)(req, config.authProvider, config.projectProvider);
|
|
60
63
|
res.status(201).json(updated);
|
|
61
64
|
}
|
|
62
65
|
catch (err) {
|
|
63
|
-
res.status(500).json({ error: 'Failed to
|
|
66
|
+
res.status(500).json({ error: 'Failed to delete image', details: err.message });
|
|
64
67
|
}
|
|
65
68
|
});
|
|
66
69
|
router.post('/upload-url', async (req, res) => {
|
|
@@ -77,7 +80,7 @@ function createStreamByRouter(config) {
|
|
|
77
80
|
res.json(url);
|
|
78
81
|
}
|
|
79
82
|
catch (err) {
|
|
80
|
-
res.status(500).json({ error: 'Failed to generate
|
|
83
|
+
res.status(500).json({ error: 'Failed to generate upload URL', details: err.message });
|
|
81
84
|
}
|
|
82
85
|
});
|
|
83
86
|
router.get('/files', async (req, res) => {
|
|
@@ -117,14 +120,16 @@ function createStreamByRouter(config) {
|
|
|
117
120
|
const auth = await config.authProvider(req);
|
|
118
121
|
const projectId = req.params.id;
|
|
119
122
|
const project = await config.projectProvider.getById(projectId);
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
if (!project) {
|
|
124
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
125
|
+
}
|
|
126
|
+
if (!isProjectMember(project, auth.userId)) {
|
|
122
127
|
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
123
128
|
}
|
|
124
129
|
res.json({ project });
|
|
125
130
|
}
|
|
126
131
|
catch (err) {
|
|
127
|
-
res.status(
|
|
132
|
+
res.status(500).json({ error: 'Failed to fetch project', details: err.message });
|
|
128
133
|
}
|
|
129
134
|
});
|
|
130
135
|
router.post('/projects/create', async (req, res) => {
|
|
@@ -144,8 +149,12 @@ function createStreamByRouter(config) {
|
|
|
144
149
|
try {
|
|
145
150
|
const auth = await config.authProvider(req);
|
|
146
151
|
const projectId = req.params.id;
|
|
147
|
-
|
|
148
|
-
|
|
152
|
+
const project = await config.projectProvider.getById(projectId);
|
|
153
|
+
if (!project) {
|
|
154
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
155
|
+
}
|
|
156
|
+
if (!isProjectMember(project, auth.userId)) {
|
|
157
|
+
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
149
158
|
}
|
|
150
159
|
await config.projectProvider.delete(projectId);
|
|
151
160
|
await adapter.deleteProjectDirectory(projectId);
|
package/dist/services/auth.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ import { Request } from 'express';
|
|
|
2
2
|
import { StreamByConfig, AuthContext } from '../types';
|
|
3
3
|
export declare function resolveAuth(config: StreamByConfig, req: Request): Promise<AuthContext>;
|
|
4
4
|
export declare function checkRole(auth: AuthContext, required: 'viewer' | 'editor' | 'admin'): void;
|
|
5
|
+
export declare function dummyAuthProvider(req: Request): Promise<AuthContext>;
|
package/dist/services/auth.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveAuth = resolveAuth;
|
|
4
4
|
exports.checkRole = checkRole;
|
|
5
|
+
exports.dummyAuthProvider = dummyAuthProvider;
|
|
5
6
|
async function resolveAuth(config, req) {
|
|
6
7
|
const auth = await config.authProvider(req);
|
|
7
8
|
if (!auth ||
|
|
@@ -21,3 +22,11 @@ function checkRole(auth, required) {
|
|
|
21
22
|
throw new Error(`Insufficient role: requires ${required}, found ${auth.role}`);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
async function dummyAuthProvider(req) {
|
|
26
|
+
return {
|
|
27
|
+
userId: '67ad0832cae5e7e270ee086a',
|
|
28
|
+
username: 'dev-user',
|
|
29
|
+
projects: [],
|
|
30
|
+
role: 'admin'
|
|
31
|
+
};
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "streamby-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "StreamBy middleware framework for media storage management",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc",
|
|
12
12
|
"test": "vitest",
|
|
13
|
-
"dev": "
|
|
13
|
+
"dev": "ts-node-dev --respawn --clear dev.ts",
|
|
14
14
|
"prepublishOnly": "npm run build"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
@@ -32,14 +32,17 @@
|
|
|
32
32
|
"@aws-sdk/client-s3": "^3.528.0",
|
|
33
33
|
"@aws-sdk/s3-request-presigner": "^3.787.0",
|
|
34
34
|
"bcrypt": "^5.1.1",
|
|
35
|
+
"dotenv": "^16.5.0",
|
|
35
36
|
"express": "^4.0.0",
|
|
36
37
|
"mongoose": "^8.13.2"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@types/bcrypt": "^5.0.2",
|
|
40
41
|
"@types/express": "^4.17.17",
|
|
42
|
+
"@types/node": "^22.15.21",
|
|
41
43
|
"@types/supertest": "^6.0.3",
|
|
42
44
|
"supertest": "^7.1.0",
|
|
45
|
+
"ts-node-dev": "^2.0.0",
|
|
43
46
|
"typescript": "^5.8.3",
|
|
44
47
|
"vitest": "^3.1.1"
|
|
45
48
|
},
|