streamby-core 0.28.6 → 0.29.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/README.md +283 -283
- package/dist/adapters/database/connectionManager.js +63 -63
- package/dist/adapters/database/sql.js +1 -1
- package/dist/middleware/createRouter.js +6 -0
- package/dist/middleware/routes/production.d.ts +3 -0
- package/dist/middleware/routes/production.js +362 -0
- package/dist/middleware/routes/project.js +4 -3
- package/dist/middleware/routes/rights.d.ts +3 -0
- package/dist/middleware/routes/rights.js +80 -0
- package/dist/middleware/routes/workflow.d.ts +3 -0
- package/dist/middleware/routes/workflow.js +157 -0
- package/dist/models/Model.js +9 -9
- package/dist/utils/crypto.d.ts +3 -0
- package/dist/utils/crypto.js +32 -0
- package/package.json +63 -63
|
@@ -43,83 +43,83 @@ const getConnection = (id) => {
|
|
|
43
43
|
exports.getConnection = getConnection;
|
|
44
44
|
const ensureTablesExist = async (pool) => {
|
|
45
45
|
try {
|
|
46
|
-
await pool.query(`
|
|
47
|
-
CREATE SCHEMA IF NOT EXISTS streamby;
|
|
48
|
-
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
46
|
+
await pool.query(`
|
|
47
|
+
CREATE SCHEMA IF NOT EXISTS streamby;
|
|
48
|
+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
49
49
|
`);
|
|
50
50
|
// Migrate id column from UUID to TEXT if it was created with the old schema
|
|
51
|
-
await pool.query(`
|
|
52
|
-
DO $$ BEGIN
|
|
53
|
-
ALTER TABLE streamby.projects ALTER COLUMN id TYPE TEXT USING id::text;
|
|
54
|
-
ALTER TABLE streamby.projects ALTER COLUMN id SET DEFAULT uuid_generate_v4()::text;
|
|
55
|
-
EXCEPTION WHEN OTHERS THEN NULL; END $$;
|
|
51
|
+
await pool.query(`
|
|
52
|
+
DO $$ BEGIN
|
|
53
|
+
ALTER TABLE streamby.projects ALTER COLUMN id TYPE TEXT USING id::text;
|
|
54
|
+
ALTER TABLE streamby.projects ALTER COLUMN id SET DEFAULT uuid_generate_v4()::text;
|
|
55
|
+
EXCEPTION WHEN OTHERS THEN NULL; END $$;
|
|
56
56
|
`);
|
|
57
|
-
await pool.query(`
|
|
58
|
-
CREATE TABLE IF NOT EXISTS streamby.projects (
|
|
59
|
-
id TEXT PRIMARY KEY DEFAULT uuid_generate_v4()::text,
|
|
60
|
-
name VARCHAR(255) NOT NULL,
|
|
61
|
-
description TEXT,
|
|
62
|
-
image TEXT,
|
|
63
|
-
"allowedOrigin" JSONB DEFAULT '[]',
|
|
64
|
-
exports JSONB DEFAULT '[]',
|
|
65
|
-
credentials JSONB DEFAULT '[]',
|
|
66
|
-
"apiConnections" JSONB DEFAULT '[]',
|
|
67
|
-
"dbConnections" JSONB DEFAULT '[]',
|
|
68
|
-
"dbType" VARCHAR(50) NOT NULL DEFAULT 'sql',
|
|
69
|
-
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
70
|
-
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
71
|
-
);
|
|
57
|
+
await pool.query(`
|
|
58
|
+
CREATE TABLE IF NOT EXISTS streamby.projects (
|
|
59
|
+
id TEXT PRIMARY KEY DEFAULT uuid_generate_v4()::text,
|
|
60
|
+
name VARCHAR(255) NOT NULL,
|
|
61
|
+
description TEXT,
|
|
62
|
+
image TEXT,
|
|
63
|
+
"allowedOrigin" JSONB DEFAULT '[]',
|
|
64
|
+
exports JSONB DEFAULT '[]',
|
|
65
|
+
credentials JSONB DEFAULT '[]',
|
|
66
|
+
"apiConnections" JSONB DEFAULT '[]',
|
|
67
|
+
"dbConnections" JSONB DEFAULT '[]',
|
|
68
|
+
"dbType" VARCHAR(50) NOT NULL DEFAULT 'sql',
|
|
69
|
+
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
70
|
+
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
71
|
+
);
|
|
72
72
|
`);
|
|
73
73
|
console.log('✅ "projects" table ensured to exist.');
|
|
74
74
|
// Add JSONB columns to existing tables that predate this schema version
|
|
75
|
-
await pool.query(`
|
|
76
|
-
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS "allowedOrigin" JSONB DEFAULT '[]';
|
|
77
|
-
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS exports JSONB DEFAULT '[]';
|
|
78
|
-
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS credentials JSONB DEFAULT '[]';
|
|
79
|
-
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS "apiConnections" JSONB DEFAULT '[]';
|
|
80
|
-
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS "dbConnections" JSONB DEFAULT '[]';
|
|
75
|
+
await pool.query(`
|
|
76
|
+
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS "allowedOrigin" JSONB DEFAULT '[]';
|
|
77
|
+
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS exports JSONB DEFAULT '[]';
|
|
78
|
+
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS credentials JSONB DEFAULT '[]';
|
|
79
|
+
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS "apiConnections" JSONB DEFAULT '[]';
|
|
80
|
+
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS "dbConnections" JSONB DEFAULT '[]';
|
|
81
81
|
`);
|
|
82
82
|
// Ensure dbType exists with a non-null default
|
|
83
|
-
await pool.query(`
|
|
84
|
-
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS "dbType" VARCHAR(50) NOT NULL DEFAULT 'sql';
|
|
83
|
+
await pool.query(`
|
|
84
|
+
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS "dbType" VARCHAR(50) NOT NULL DEFAULT 'sql';
|
|
85
85
|
`);
|
|
86
|
-
await pool.query(`
|
|
87
|
-
CREATE TABLE IF NOT EXISTS streamby.project_members (
|
|
88
|
-
id TEXT PRIMARY KEY DEFAULT uuid_generate_v4()::text,
|
|
89
|
-
"projectId" TEXT NOT NULL REFERENCES streamby.projects(id) ON DELETE CASCADE,
|
|
90
|
-
"userId" VARCHAR(255) NOT NULL,
|
|
91
|
-
role VARCHAR(255) NOT NULL DEFAULT 'member',
|
|
92
|
-
status VARCHAR(50) NOT NULL DEFAULT 'active',
|
|
93
|
-
archived BOOLEAN NOT NULL DEFAULT FALSE,
|
|
94
|
-
"archivedBy" VARCHAR(255),
|
|
95
|
-
"archivedAt" TIMESTAMP WITH TIME ZONE,
|
|
96
|
-
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
97
|
-
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
98
|
-
UNIQUE ("projectId", "userId")
|
|
99
|
-
);
|
|
86
|
+
await pool.query(`
|
|
87
|
+
CREATE TABLE IF NOT EXISTS streamby.project_members (
|
|
88
|
+
id TEXT PRIMARY KEY DEFAULT uuid_generate_v4()::text,
|
|
89
|
+
"projectId" TEXT NOT NULL REFERENCES streamby.projects(id) ON DELETE CASCADE,
|
|
90
|
+
"userId" VARCHAR(255) NOT NULL,
|
|
91
|
+
role VARCHAR(255) NOT NULL DEFAULT 'member',
|
|
92
|
+
status VARCHAR(50) NOT NULL DEFAULT 'active',
|
|
93
|
+
archived BOOLEAN NOT NULL DEFAULT FALSE,
|
|
94
|
+
"archivedBy" VARCHAR(255),
|
|
95
|
+
"archivedAt" TIMESTAMP WITH TIME ZONE,
|
|
96
|
+
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
97
|
+
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
98
|
+
UNIQUE ("projectId", "userId")
|
|
99
|
+
);
|
|
100
100
|
`);
|
|
101
|
-
await pool.query(`
|
|
102
|
-
ALTER TABLE streamby.project_members ADD COLUMN IF NOT EXISTS status VARCHAR(50) NOT NULL DEFAULT 'active';
|
|
101
|
+
await pool.query(`
|
|
102
|
+
ALTER TABLE streamby.project_members ADD COLUMN IF NOT EXISTS status VARCHAR(50) NOT NULL DEFAULT 'active';
|
|
103
103
|
`);
|
|
104
104
|
console.log('✅ "project_members" table ensured to exist.');
|
|
105
105
|
// Migrate projectId FK column from UUID to TEXT if table predates this schema version
|
|
106
|
-
await pool.query(`
|
|
107
|
-
DO $$ BEGIN
|
|
108
|
-
ALTER TABLE streamby.project_members DROP CONSTRAINT IF EXISTS project_members_projectId_fkey;
|
|
109
|
-
ALTER TABLE streamby.project_members ALTER COLUMN "projectId" TYPE TEXT;
|
|
110
|
-
ALTER TABLE streamby.project_members ADD CONSTRAINT project_members_projectid_fkey
|
|
111
|
-
FOREIGN KEY ("projectId") REFERENCES streamby.projects(id) ON DELETE CASCADE;
|
|
112
|
-
EXCEPTION WHEN OTHERS THEN NULL; END $$;
|
|
106
|
+
await pool.query(`
|
|
107
|
+
DO $$ BEGIN
|
|
108
|
+
ALTER TABLE streamby.project_members DROP CONSTRAINT IF EXISTS project_members_projectId_fkey;
|
|
109
|
+
ALTER TABLE streamby.project_members ALTER COLUMN "projectId" TYPE TEXT;
|
|
110
|
+
ALTER TABLE streamby.project_members ADD CONSTRAINT project_members_projectid_fkey
|
|
111
|
+
FOREIGN KEY ("projectId") REFERENCES streamby.projects(id) ON DELETE CASCADE;
|
|
112
|
+
EXCEPTION WHEN OTHERS THEN NULL; END $$;
|
|
113
113
|
`);
|
|
114
|
-
await pool.query(`
|
|
115
|
-
CREATE TABLE IF NOT EXISTS streamby.exports (
|
|
116
|
-
id TEXT PRIMARY KEY DEFAULT uuid_generate_v4()::text,
|
|
117
|
-
"projectId" TEXT NOT NULL REFERENCES streamby.projects(id) ON DELETE CASCADE,
|
|
118
|
-
status VARCHAR(50) NOT NULL DEFAULT 'pending',
|
|
119
|
-
"filePath" TEXT,
|
|
120
|
-
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
121
|
-
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
122
|
-
);
|
|
114
|
+
await pool.query(`
|
|
115
|
+
CREATE TABLE IF NOT EXISTS streamby.exports (
|
|
116
|
+
id TEXT PRIMARY KEY DEFAULT uuid_generate_v4()::text,
|
|
117
|
+
"projectId" TEXT NOT NULL REFERENCES streamby.projects(id) ON DELETE CASCADE,
|
|
118
|
+
status VARCHAR(50) NOT NULL DEFAULT 'pending',
|
|
119
|
+
"filePath" TEXT,
|
|
120
|
+
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
121
|
+
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
122
|
+
);
|
|
123
123
|
`);
|
|
124
124
|
console.log('✅ "exports" table ensured to exist.');
|
|
125
125
|
}
|
|
@@ -10,7 +10,7 @@ function serializeForPg(v) {
|
|
|
10
10
|
}
|
|
11
11
|
const createSQLExportTable = async (connection, projectId, exportName, nodeSchema) => {
|
|
12
12
|
const exportId = (0, crypto_1.randomUUID)();
|
|
13
|
-
await connection.query(`INSERT INTO "exports" (id, "projectId", node_schema, name, method, created_at, updated_at)
|
|
13
|
+
await connection.query(`INSERT INTO "exports" (id, "projectId", node_schema, name, method, created_at, updated_at)
|
|
14
14
|
VALUES ($1, $2, $3, $4, 'GET', NOW(), NOW())`, [exportId, projectId, nodeSchema ? JSON.stringify(nodeSchema) : null, exportName]);
|
|
15
15
|
return { exportId };
|
|
16
16
|
};
|
|
@@ -29,6 +29,9 @@ const renderFarm_1 = require("./routes/renderFarm");
|
|
|
29
29
|
const review_1 = require("./routes/review");
|
|
30
30
|
const distribution_1 = require("./routes/distribution");
|
|
31
31
|
const ai_1 = require("./routes/ai");
|
|
32
|
+
const production_1 = require("./routes/production");
|
|
33
|
+
const rights_1 = require("./routes/rights");
|
|
34
|
+
const workflow_1 = require("./routes/workflow");
|
|
32
35
|
function createStreamByRouter(config) {
|
|
33
36
|
const router = express_1.default.Router();
|
|
34
37
|
if (config.encrypt)
|
|
@@ -81,5 +84,8 @@ function createStreamByRouter(config) {
|
|
|
81
84
|
router.use((0, review_1.reviewRouter)(config));
|
|
82
85
|
router.use((0, distribution_1.distributionRouter)(config));
|
|
83
86
|
router.use((0, ai_1.aiRouter)(config));
|
|
87
|
+
router.use((0, production_1.productionRouter)(config));
|
|
88
|
+
router.use((0, rights_1.rightsRouter)(config));
|
|
89
|
+
router.use((0, workflow_1.workflowRouter)(config));
|
|
84
90
|
return router;
|
|
85
91
|
}
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.productionRouter = productionRouter;
|
|
7
|
+
const express_1 = require("express");
|
|
8
|
+
const auth_1 = require("../../utils/auth");
|
|
9
|
+
const connectionManager_1 = require("../../adapters/database/connectionManager");
|
|
10
|
+
const manager_1 = require("../../models/manager");
|
|
11
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
12
|
+
function getDb() {
|
|
13
|
+
const ids = (0, connectionManager_1.getConnectedIds)().filter(id => (0, connectionManager_1.getConnection)(id).type === 'nosql');
|
|
14
|
+
if (!ids.length)
|
|
15
|
+
return null;
|
|
16
|
+
return (0, connectionManager_1.getConnection)(ids[0]).client.db();
|
|
17
|
+
}
|
|
18
|
+
function productionRouter(_config) {
|
|
19
|
+
const router = (0, express_1.Router)();
|
|
20
|
+
const Project = (0, manager_1.getModel)('projects');
|
|
21
|
+
// ── Sequences ──────────────────────────────────────────────────────────────
|
|
22
|
+
router.get('/projects/:projectId/production/sequences', async (req, res) => {
|
|
23
|
+
try {
|
|
24
|
+
const auth = req.auth;
|
|
25
|
+
const { projectId } = req.params;
|
|
26
|
+
const project = await Project.findOne({ _id: projectId });
|
|
27
|
+
if (!project)
|
|
28
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
29
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
30
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
31
|
+
const db = getDb();
|
|
32
|
+
if (!db)
|
|
33
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
34
|
+
const sequences = await db.collection('production_sequences')
|
|
35
|
+
.find({ projectId })
|
|
36
|
+
.sort({ order: 1, createdAt: 1 })
|
|
37
|
+
.toArray();
|
|
38
|
+
res.json({ sequences });
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
res.status(500).json({ message: err.message });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
router.post('/projects/:projectId/production/sequences', async (req, res) => {
|
|
45
|
+
try {
|
|
46
|
+
const auth = req.auth;
|
|
47
|
+
const { projectId } = req.params;
|
|
48
|
+
const { name, description, order } = req.body;
|
|
49
|
+
if (!name)
|
|
50
|
+
return res.status(400).json({ message: 'name is required' });
|
|
51
|
+
const project = await Project.findOne({ _id: projectId });
|
|
52
|
+
if (!project)
|
|
53
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
54
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
55
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
56
|
+
const db = getDb();
|
|
57
|
+
if (!db)
|
|
58
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
59
|
+
const now = new Date();
|
|
60
|
+
const sequence = {
|
|
61
|
+
id: crypto_1.default.randomUUID(),
|
|
62
|
+
projectId,
|
|
63
|
+
name,
|
|
64
|
+
description: description ?? null,
|
|
65
|
+
order: order ?? 0,
|
|
66
|
+
createdBy: auth.userId,
|
|
67
|
+
createdAt: now,
|
|
68
|
+
updatedAt: now,
|
|
69
|
+
};
|
|
70
|
+
await db.collection('production_sequences').insertOne({ ...sequence });
|
|
71
|
+
res.status(201).json({ sequence });
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
res.status(500).json({ message: err.message });
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
router.patch('/projects/:projectId/production/sequences/:seqId', async (req, res) => {
|
|
78
|
+
try {
|
|
79
|
+
const auth = req.auth;
|
|
80
|
+
const { projectId, seqId } = req.params;
|
|
81
|
+
const project = await Project.findOne({ _id: projectId });
|
|
82
|
+
if (!project)
|
|
83
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
84
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
85
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
86
|
+
const db = getDb();
|
|
87
|
+
if (!db)
|
|
88
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
89
|
+
const { name, description, order } = req.body;
|
|
90
|
+
const $set = { updatedAt: new Date() };
|
|
91
|
+
if (name !== undefined)
|
|
92
|
+
$set.name = name;
|
|
93
|
+
if (description !== undefined)
|
|
94
|
+
$set.description = description;
|
|
95
|
+
if (order !== undefined)
|
|
96
|
+
$set.order = order;
|
|
97
|
+
const result = await db.collection('production_sequences').findOneAndUpdate({ id: seqId, projectId }, { $set }, { returnDocument: 'after' });
|
|
98
|
+
if (!result)
|
|
99
|
+
return res.status(404).json({ message: 'Sequence not found' });
|
|
100
|
+
res.json({ sequence: result });
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
res.status(500).json({ message: err.message });
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
router.delete('/projects/:projectId/production/sequences/:seqId', async (req, res) => {
|
|
107
|
+
try {
|
|
108
|
+
const auth = req.auth;
|
|
109
|
+
const { projectId, seqId } = req.params;
|
|
110
|
+
const project = await Project.findOne({ _id: projectId });
|
|
111
|
+
if (!project)
|
|
112
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
113
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
114
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
115
|
+
const db = getDb();
|
|
116
|
+
if (!db)
|
|
117
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
118
|
+
await db.collection('production_sequences').deleteOne({ id: seqId, projectId });
|
|
119
|
+
await db.collection('production_shots').deleteMany({ sequenceId: seqId, projectId });
|
|
120
|
+
res.json({ message: 'Sequence deleted' });
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
res.status(500).json({ message: err.message });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
// ── Shots ──────────────────────────────────────────────────────────────────
|
|
127
|
+
router.get('/projects/:projectId/production/sequences/:seqId/shots', async (req, res) => {
|
|
128
|
+
try {
|
|
129
|
+
const auth = req.auth;
|
|
130
|
+
const { projectId, seqId } = req.params;
|
|
131
|
+
const project = await Project.findOne({ _id: projectId });
|
|
132
|
+
if (!project)
|
|
133
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
134
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
135
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
136
|
+
const db = getDb();
|
|
137
|
+
if (!db)
|
|
138
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
139
|
+
const shots = await db.collection('production_shots')
|
|
140
|
+
.find({ sequenceId: seqId, projectId })
|
|
141
|
+
.sort({ order: 1, createdAt: 1 })
|
|
142
|
+
.toArray();
|
|
143
|
+
res.json({ shots });
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
res.status(500).json({ message: err.message });
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
router.post('/projects/:projectId/production/sequences/:seqId/shots', async (req, res) => {
|
|
150
|
+
try {
|
|
151
|
+
const auth = req.auth;
|
|
152
|
+
const { projectId, seqId } = req.params;
|
|
153
|
+
const { name, description, status, assignedTo, assetId, exportId, dueDate, order } = req.body;
|
|
154
|
+
if (!name)
|
|
155
|
+
return res.status(400).json({ message: 'name is required' });
|
|
156
|
+
const project = await Project.findOne({ _id: projectId });
|
|
157
|
+
if (!project)
|
|
158
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
159
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
160
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
161
|
+
const db = getDb();
|
|
162
|
+
if (!db)
|
|
163
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
164
|
+
const now = new Date();
|
|
165
|
+
const shot = {
|
|
166
|
+
id: crypto_1.default.randomUUID(),
|
|
167
|
+
sequenceId: seqId,
|
|
168
|
+
projectId,
|
|
169
|
+
name,
|
|
170
|
+
description: description ?? null,
|
|
171
|
+
order: order ?? 0,
|
|
172
|
+
status: status ?? 'todo',
|
|
173
|
+
assignedTo: assignedTo ?? [],
|
|
174
|
+
assetId: assetId ?? null,
|
|
175
|
+
exportId: exportId ?? null,
|
|
176
|
+
dueDate: dueDate ? new Date(dueDate) : null,
|
|
177
|
+
createdBy: auth.userId,
|
|
178
|
+
createdAt: now,
|
|
179
|
+
updatedAt: now,
|
|
180
|
+
};
|
|
181
|
+
await db.collection('production_shots').insertOne({ ...shot });
|
|
182
|
+
res.status(201).json({ shot });
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
res.status(500).json({ message: err.message });
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
router.patch('/projects/:projectId/production/shots/:shotId', async (req, res) => {
|
|
189
|
+
try {
|
|
190
|
+
const auth = req.auth;
|
|
191
|
+
const { projectId, shotId } = req.params;
|
|
192
|
+
const project = await Project.findOne({ _id: projectId });
|
|
193
|
+
if (!project)
|
|
194
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
195
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
196
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
197
|
+
const db = getDb();
|
|
198
|
+
if (!db)
|
|
199
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
200
|
+
const { name, description, status, assignedTo, assetId, exportId, dueDate, order } = req.body;
|
|
201
|
+
const $set = { updatedAt: new Date() };
|
|
202
|
+
if (name !== undefined)
|
|
203
|
+
$set.name = name;
|
|
204
|
+
if (description !== undefined)
|
|
205
|
+
$set.description = description;
|
|
206
|
+
if (status !== undefined)
|
|
207
|
+
$set.status = status;
|
|
208
|
+
if (assignedTo !== undefined)
|
|
209
|
+
$set.assignedTo = assignedTo;
|
|
210
|
+
if (assetId !== undefined)
|
|
211
|
+
$set.assetId = assetId;
|
|
212
|
+
if (exportId !== undefined)
|
|
213
|
+
$set.exportId = exportId;
|
|
214
|
+
if (dueDate !== undefined)
|
|
215
|
+
$set.dueDate = dueDate ? new Date(dueDate) : null;
|
|
216
|
+
if (order !== undefined)
|
|
217
|
+
$set.order = order;
|
|
218
|
+
const result = await db.collection('production_shots').findOneAndUpdate({ id: shotId, projectId }, { $set }, { returnDocument: 'after' });
|
|
219
|
+
if (!result)
|
|
220
|
+
return res.status(404).json({ message: 'Shot not found' });
|
|
221
|
+
res.json({ shot: result });
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
res.status(500).json({ message: err.message });
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
router.delete('/projects/:projectId/production/shots/:shotId', async (req, res) => {
|
|
228
|
+
try {
|
|
229
|
+
const auth = req.auth;
|
|
230
|
+
const { projectId, shotId } = req.params;
|
|
231
|
+
const project = await Project.findOne({ _id: projectId });
|
|
232
|
+
if (!project)
|
|
233
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
234
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
235
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
236
|
+
const db = getDb();
|
|
237
|
+
if (!db)
|
|
238
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
239
|
+
await db.collection('production_shots').deleteOne({ id: shotId, projectId });
|
|
240
|
+
await db.collection('production_tasks').deleteMany({ shotId, projectId });
|
|
241
|
+
res.json({ message: 'Shot deleted' });
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
res.status(500).json({ message: err.message });
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
// ── Tasks ──────────────────────────────────────────────────────────────────
|
|
248
|
+
router.get('/projects/:projectId/production/shots/:shotId/tasks', async (req, res) => {
|
|
249
|
+
try {
|
|
250
|
+
const auth = req.auth;
|
|
251
|
+
const { projectId, shotId } = req.params;
|
|
252
|
+
const project = await Project.findOne({ _id: projectId });
|
|
253
|
+
if (!project)
|
|
254
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
255
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
256
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
257
|
+
const db = getDb();
|
|
258
|
+
if (!db)
|
|
259
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
260
|
+
const tasks = await db.collection('production_tasks')
|
|
261
|
+
.find({ shotId, projectId })
|
|
262
|
+
.sort({ createdAt: 1 })
|
|
263
|
+
.toArray();
|
|
264
|
+
res.json({ tasks });
|
|
265
|
+
}
|
|
266
|
+
catch (err) {
|
|
267
|
+
res.status(500).json({ message: err.message });
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
router.post('/projects/:projectId/production/shots/:shotId/tasks', async (req, res) => {
|
|
271
|
+
try {
|
|
272
|
+
const auth = req.auth;
|
|
273
|
+
const { projectId, shotId } = req.params;
|
|
274
|
+
const { name, status, priority, assignedTo, dueDate, notes } = req.body;
|
|
275
|
+
if (!name)
|
|
276
|
+
return res.status(400).json({ message: 'name is required' });
|
|
277
|
+
const project = await Project.findOne({ _id: projectId });
|
|
278
|
+
if (!project)
|
|
279
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
280
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
281
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
282
|
+
const db = getDb();
|
|
283
|
+
if (!db)
|
|
284
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
285
|
+
const now = new Date();
|
|
286
|
+
const task = {
|
|
287
|
+
id: crypto_1.default.randomUUID(),
|
|
288
|
+
shotId,
|
|
289
|
+
projectId,
|
|
290
|
+
name,
|
|
291
|
+
status: status ?? 'todo',
|
|
292
|
+
priority: priority ?? 'medium',
|
|
293
|
+
assignedTo: assignedTo ?? null,
|
|
294
|
+
dueDate: dueDate ? new Date(dueDate) : null,
|
|
295
|
+
notes: notes ?? null,
|
|
296
|
+
createdBy: auth.userId,
|
|
297
|
+
createdAt: now,
|
|
298
|
+
updatedAt: now,
|
|
299
|
+
};
|
|
300
|
+
await db.collection('production_tasks').insertOne({ ...task });
|
|
301
|
+
res.status(201).json({ task });
|
|
302
|
+
}
|
|
303
|
+
catch (err) {
|
|
304
|
+
res.status(500).json({ message: err.message });
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
router.patch('/projects/:projectId/production/shots/:shotId/tasks/:taskId', async (req, res) => {
|
|
308
|
+
try {
|
|
309
|
+
const auth = req.auth;
|
|
310
|
+
const { projectId, shotId, taskId } = req.params;
|
|
311
|
+
const project = await Project.findOne({ _id: projectId });
|
|
312
|
+
if (!project)
|
|
313
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
314
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
315
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
316
|
+
const db = getDb();
|
|
317
|
+
if (!db)
|
|
318
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
319
|
+
const { name, status, priority, assignedTo, dueDate, notes } = req.body;
|
|
320
|
+
const $set = { updatedAt: new Date() };
|
|
321
|
+
if (name !== undefined)
|
|
322
|
+
$set.name = name;
|
|
323
|
+
if (status !== undefined)
|
|
324
|
+
$set.status = status;
|
|
325
|
+
if (priority !== undefined)
|
|
326
|
+
$set.priority = priority;
|
|
327
|
+
if (assignedTo !== undefined)
|
|
328
|
+
$set.assignedTo = assignedTo;
|
|
329
|
+
if (dueDate !== undefined)
|
|
330
|
+
$set.dueDate = dueDate ? new Date(dueDate) : null;
|
|
331
|
+
if (notes !== undefined)
|
|
332
|
+
$set.notes = notes;
|
|
333
|
+
const result = await db.collection('production_tasks').findOneAndUpdate({ id: taskId, shotId, projectId }, { $set }, { returnDocument: 'after' });
|
|
334
|
+
if (!result)
|
|
335
|
+
return res.status(404).json({ message: 'Task not found' });
|
|
336
|
+
res.json({ task: result });
|
|
337
|
+
}
|
|
338
|
+
catch (err) {
|
|
339
|
+
res.status(500).json({ message: err.message });
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
router.delete('/projects/:projectId/production/shots/:shotId/tasks/:taskId', async (req, res) => {
|
|
343
|
+
try {
|
|
344
|
+
const auth = req.auth;
|
|
345
|
+
const { projectId, shotId, taskId } = req.params;
|
|
346
|
+
const project = await Project.findOne({ _id: projectId });
|
|
347
|
+
if (!project)
|
|
348
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
349
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
350
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
351
|
+
const db = getDb();
|
|
352
|
+
if (!db)
|
|
353
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
354
|
+
await db.collection('production_tasks').deleteOne({ id: taskId, shotId, projectId });
|
|
355
|
+
res.json({ message: 'Task deleted' });
|
|
356
|
+
}
|
|
357
|
+
catch (err) {
|
|
358
|
+
res.status(500).json({ message: err.message });
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
return router;
|
|
362
|
+
}
|
|
@@ -74,7 +74,7 @@ function projectRouter(config) {
|
|
|
74
74
|
if (auth.role !== 'admin' && auth.role !== 'editor') {
|
|
75
75
|
return res.status(403).json({ message: 'Permission denied' });
|
|
76
76
|
}
|
|
77
|
-
const { name, description, image, allowedOrigin, public: isPublic = true } = req.body;
|
|
77
|
+
const { name, description, image, allowedOrigin, public: isPublic = true, category } = req.body;
|
|
78
78
|
if (isPublic === false && req.subscription === 'freemium') {
|
|
79
79
|
return res.status(403).json({ error: 'Private projects require a subscriber plan' });
|
|
80
80
|
}
|
|
@@ -95,6 +95,7 @@ function projectRouter(config) {
|
|
|
95
95
|
image: image || '',
|
|
96
96
|
allowedOrigin: allowedOrigin || [],
|
|
97
97
|
public: isPublic,
|
|
98
|
+
category: category || null,
|
|
98
99
|
members: [{ userId: auth.userId, username: user.username, role: "admin", status: "active", archived: false }],
|
|
99
100
|
});
|
|
100
101
|
const allProjects = await Project.find({});
|
|
@@ -246,7 +247,7 @@ function projectRouter(config) {
|
|
|
246
247
|
}
|
|
247
248
|
if (project.dbType === 'sql') {
|
|
248
249
|
const connection = (0, connectionManager_1.getConnection)(config.databases?.find(db => db.main)?.id || '').client;
|
|
249
|
-
await sql_1.sqlAdapter.update(connection, 'project_members', { projectId: projectId, userId: auth.userId }, { archived: true, archivedBy: auth.userId, archivedAt: new Date() });
|
|
250
|
+
await sql_1.sqlAdapter.update(connection, 'project_members', { projectId: projectId, userId: auth.userId }, { archived: true, archivedBy: auth.userId, archivedAt: new Date() }, 'streamby');
|
|
250
251
|
}
|
|
251
252
|
else {
|
|
252
253
|
const memberIndex = project.members.findIndex((member) => member.userId === auth.userId);
|
|
@@ -284,7 +285,7 @@ function projectRouter(config) {
|
|
|
284
285
|
}
|
|
285
286
|
if (project.dbType === 'sql') {
|
|
286
287
|
const connection = (0, connectionManager_1.getConnection)(config.databases?.find(db => db.main)?.id || '').client;
|
|
287
|
-
await sql_1.sqlAdapter.update(connection, 'project_members', { projectId: projectId, userId: auth.userId }, { archived: false, archivedBy: null, archivedAt: null });
|
|
288
|
+
await sql_1.sqlAdapter.update(connection, 'project_members', { projectId: projectId, userId: auth.userId }, { archived: false, archivedBy: null, archivedAt: null }, 'streamby');
|
|
288
289
|
}
|
|
289
290
|
else {
|
|
290
291
|
const memberIndex = project.members.findIndex((member) => member.userId === auth.userId);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rightsRouter = rightsRouter;
|
|
4
|
+
const express_1 = require("express");
|
|
5
|
+
const auth_1 = require("../../utils/auth");
|
|
6
|
+
const connectionManager_1 = require("../../adapters/database/connectionManager");
|
|
7
|
+
const manager_1 = require("../../models/manager");
|
|
8
|
+
function getDb() {
|
|
9
|
+
const ids = (0, connectionManager_1.getConnectedIds)().filter(id => (0, connectionManager_1.getConnection)(id).type === 'nosql');
|
|
10
|
+
if (!ids.length)
|
|
11
|
+
return null;
|
|
12
|
+
return (0, connectionManager_1.getConnection)(ids[0]).client.db();
|
|
13
|
+
}
|
|
14
|
+
function rightsRouter(_config) {
|
|
15
|
+
const router = (0, express_1.Router)();
|
|
16
|
+
const Project = (0, manager_1.getModel)('projects');
|
|
17
|
+
// GET /projects/:projectId/assets/:assetId/rights
|
|
18
|
+
router.get('/projects/:projectId/assets/:assetId/rights', async (req, res) => {
|
|
19
|
+
try {
|
|
20
|
+
const auth = req.auth;
|
|
21
|
+
const { projectId, assetId } = req.params;
|
|
22
|
+
const project = await Project.findOne({ _id: projectId });
|
|
23
|
+
if (!project)
|
|
24
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
25
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
26
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
27
|
+
const db = getDb();
|
|
28
|
+
if (!db)
|
|
29
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
30
|
+
const rights = await db.collection('asset_rights').findOne({ assetId, projectId });
|
|
31
|
+
res.json({ rights: rights ?? null });
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
res.status(500).json({ message: err.message });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
// PUT /projects/:projectId/assets/:assetId/rights (upsert)
|
|
38
|
+
router.put('/projects/:projectId/assets/:assetId/rights', async (req, res) => {
|
|
39
|
+
try {
|
|
40
|
+
const auth = req.auth;
|
|
41
|
+
const { projectId, assetId } = req.params;
|
|
42
|
+
const project = await Project.findOne({ _id: projectId });
|
|
43
|
+
if (!project)
|
|
44
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
45
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId))
|
|
46
|
+
return res.status(403).json({ message: 'Unauthorized' });
|
|
47
|
+
const db = getDb();
|
|
48
|
+
if (!db)
|
|
49
|
+
return res.status(500).json({ message: 'Database not available' });
|
|
50
|
+
const { rightsHolder, licenseType, licenseUrl, territory, expiresAt, usageRestrictions, notes } = req.body;
|
|
51
|
+
const now = new Date();
|
|
52
|
+
const payload = {
|
|
53
|
+
assetId,
|
|
54
|
+
projectId,
|
|
55
|
+
licenseType: licenseType ?? 'unknown',
|
|
56
|
+
updatedBy: auth.userId,
|
|
57
|
+
updatedAt: now,
|
|
58
|
+
};
|
|
59
|
+
if (rightsHolder !== undefined)
|
|
60
|
+
payload.rightsHolder = rightsHolder;
|
|
61
|
+
if (licenseUrl !== undefined)
|
|
62
|
+
payload.licenseUrl = licenseUrl;
|
|
63
|
+
if (territory !== undefined)
|
|
64
|
+
payload.territory = territory;
|
|
65
|
+
if (expiresAt !== undefined)
|
|
66
|
+
payload.expiresAt = expiresAt ? new Date(expiresAt) : null;
|
|
67
|
+
if (usageRestrictions !== undefined)
|
|
68
|
+
payload.usageRestrictions = usageRestrictions;
|
|
69
|
+
if (notes !== undefined)
|
|
70
|
+
payload.notes = notes;
|
|
71
|
+
await db.collection('asset_rights').updateOne({ assetId, projectId }, { $set: payload }, { upsert: true });
|
|
72
|
+
const rights = await db.collection('asset_rights').findOne({ assetId, projectId });
|
|
73
|
+
res.json({ rights });
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
res.status(500).json({ message: err.message });
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return router;
|
|
80
|
+
}
|