streamby-core 0.8.1 → 0.9.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,8 +1,12 @@
|
|
|
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.createS3Adapter = createS3Adapter;
|
|
4
7
|
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
5
8
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
9
|
+
const bcrypt_1 = __importDefault(require("bcrypt"));
|
|
6
10
|
function createS3Adapter(config) {
|
|
7
11
|
const s3 = new client_s3_1.S3Client({
|
|
8
12
|
region: config.region,
|
|
@@ -13,14 +17,17 @@ function createS3Adapter(config) {
|
|
|
13
17
|
});
|
|
14
18
|
return {
|
|
15
19
|
async getPresignedUrl(filename, contentType, projectId) {
|
|
16
|
-
const
|
|
20
|
+
const salt = await bcrypt_1.default.genSalt();
|
|
21
|
+
const hashedPassword = await bcrypt_1.default.hash(filename, salt);
|
|
22
|
+
const key = `${projectId}/${contentType}/file-${Date.now()}-${hashedPassword}`;
|
|
17
23
|
const command = new client_s3_1.PutObjectCommand({
|
|
18
24
|
Bucket: config.bucket,
|
|
19
25
|
Key: key,
|
|
20
26
|
ContentType: contentType,
|
|
21
27
|
});
|
|
22
28
|
const url = await (0, s3_request_presigner_1.getSignedUrl)(s3, command, { expiresIn: 60 });
|
|
23
|
-
|
|
29
|
+
const publicUrl = `https://${config.bucket}.s3.${config.region}.amazonaws.com/${key}`;
|
|
30
|
+
return { url, publicUrl };
|
|
24
31
|
},
|
|
25
32
|
async listFiles(projectId) {
|
|
26
33
|
const command = new client_s3_1.ListObjectsV2Command({
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Connection, Model, Document } from 'mongoose';
|
|
2
|
+
export interface FolderNode {
|
|
3
|
+
name: string;
|
|
4
|
+
children?: FolderNode[];
|
|
5
|
+
}
|
|
6
|
+
export interface ProjectDoc extends Document {
|
|
7
|
+
name: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
image?: string;
|
|
10
|
+
rootFolders?: FolderNode[];
|
|
11
|
+
allowUpload: boolean;
|
|
12
|
+
allowSharing: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function initProjectModel(conn: Connection): Model<ProjectDoc>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initProjectModel = initProjectModel;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
let ProjectModel = null;
|
|
6
|
+
function initProjectModel(conn) {
|
|
7
|
+
if (ProjectModel)
|
|
8
|
+
return ProjectModel;
|
|
9
|
+
const folderNodeSchema = new mongoose_1.Schema({
|
|
10
|
+
name: { type: String, required: true },
|
|
11
|
+
children: [{ type: Object }],
|
|
12
|
+
}, { _id: false });
|
|
13
|
+
const projectSchema = new mongoose_1.Schema({
|
|
14
|
+
name: { type: String, required: true },
|
|
15
|
+
description: { type: String },
|
|
16
|
+
image: { type: String },
|
|
17
|
+
rootFolders: [folderNodeSchema],
|
|
18
|
+
allowUpload: { type: Boolean, default: true },
|
|
19
|
+
allowSharing: { type: Boolean, default: false },
|
|
20
|
+
}, { timestamps: true });
|
|
21
|
+
ProjectModel = conn.model('Project', projectSchema);
|
|
22
|
+
return ProjectModel;
|
|
23
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMongoProjectProvider = createMongoProjectProvider;
|
|
4
|
+
function createMongoProjectProvider(ProjectModel) {
|
|
5
|
+
return {
|
|
6
|
+
async getById(projectId) {
|
|
7
|
+
const project = await ProjectModel.findById(projectId);
|
|
8
|
+
if (!project)
|
|
9
|
+
throw new Error('Project not found');
|
|
10
|
+
return formatProject(project);
|
|
11
|
+
},
|
|
12
|
+
async create(data) {
|
|
13
|
+
const newProject = await ProjectModel.create({
|
|
14
|
+
name: data.name,
|
|
15
|
+
description: data.description || '',
|
|
16
|
+
image: data.image || '',
|
|
17
|
+
rootFolders: data.rootFolders || [],
|
|
18
|
+
allowUpload: data.allowUpload ?? true,
|
|
19
|
+
allowSharing: data.allowSharing ?? false,
|
|
20
|
+
});
|
|
21
|
+
return formatProject(newProject);
|
|
22
|
+
},
|
|
23
|
+
async update(projectId, updates) {
|
|
24
|
+
const updated = await ProjectModel.findByIdAndUpdate(projectId, updates, { new: true });
|
|
25
|
+
if (!updated)
|
|
26
|
+
throw new Error('Project not found');
|
|
27
|
+
return formatProject(updated);
|
|
28
|
+
},
|
|
29
|
+
async list(userId) {
|
|
30
|
+
const query = userId ? { members: userId } : {};
|
|
31
|
+
const all = await ProjectModel.find(query);
|
|
32
|
+
return all.map(formatProject);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function formatProject(doc) {
|
|
37
|
+
return {
|
|
38
|
+
id: doc._id.toString(),
|
|
39
|
+
name: doc.name,
|
|
40
|
+
description: doc.description,
|
|
41
|
+
image: doc.image,
|
|
42
|
+
rootFolders: doc.rootFolders || [],
|
|
43
|
+
settings: {
|
|
44
|
+
allowUpload: doc.allowUpload,
|
|
45
|
+
allowSharing: doc.allowSharing,
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Request } from 'express';
|
|
2
|
+
import { Connection } from 'mongoose';
|
|
2
3
|
export interface S3Config {
|
|
3
4
|
bucket: string;
|
|
4
5
|
region: string;
|
|
@@ -33,6 +34,7 @@ export interface StreamByConfig {
|
|
|
33
34
|
};
|
|
34
35
|
authProvider: AuthProvider;
|
|
35
36
|
projectProvider: ProjectProvider;
|
|
37
|
+
dbConnection?: Connection;
|
|
36
38
|
}
|
|
37
39
|
export interface AuthContext {
|
|
38
40
|
userId: string;
|
|
@@ -42,6 +44,7 @@ export interface AuthContext {
|
|
|
42
44
|
}
|
|
43
45
|
export type AuthProvider = (req: Request) => Promise<AuthContext>;
|
|
44
46
|
export interface ProjectProvider {
|
|
47
|
+
list(userId?: string): Promise<ProjectInfo[]>;
|
|
45
48
|
getById(projectId: string): Promise<ProjectInfo>;
|
|
46
49
|
update(projectId: string, updates: Partial<Omit<ProjectInfo, 'id' | 'rootFolders'>>): Promise<ProjectInfo>;
|
|
47
50
|
create(data: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "streamby-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "StreamBy middleware framework for media storage management",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,9 +31,12 @@
|
|
|
31
31
|
"dependencies": {
|
|
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
|
+
"express": "^4.0.0",
|
|
36
|
+
"mongoose": "^8.13.2"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
39
|
+
"@types/bcrypt": "^5.0.2",
|
|
37
40
|
"@types/express": "^4.17.17",
|
|
38
41
|
"@types/supertest": "^6.0.3",
|
|
39
42
|
"supertest": "^7.1.0",
|