streamby-core 0.25.4 → 0.25.6
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.
|
@@ -77,7 +77,7 @@ class S3Adapter {
|
|
|
77
77
|
await this.s3.send(command);
|
|
78
78
|
}
|
|
79
79
|
async listFilesByCategory(projectId, category) {
|
|
80
|
-
const prefix =
|
|
80
|
+
const prefix = `${projectId}/${category}/`;
|
|
81
81
|
const command = new client_s3_1.ListObjectsV2Command({ Bucket: this.bucket, Prefix: prefix });
|
|
82
82
|
const result = await this.s3.send(command);
|
|
83
83
|
if (!result.Contents || result.Contents.length === 0)
|
|
@@ -115,6 +115,34 @@ function storageRouter(config) {
|
|
|
115
115
|
res.status(500).json({ message: 'Failed to generate upload URL', details: err.message });
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
|
+
router.get('/projects/:projectId/storage/lasts', async (req, res) => {
|
|
119
|
+
try {
|
|
120
|
+
const auth = await config.authProvider(req);
|
|
121
|
+
if (!auth || !auth.userId || !auth.role) {
|
|
122
|
+
return res.status(401).json({ message: 'Unauthorized' });
|
|
123
|
+
}
|
|
124
|
+
const { projectId } = req.params;
|
|
125
|
+
const project = await Project.findOne({ _id: projectId });
|
|
126
|
+
if (!project) {
|
|
127
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
128
|
+
}
|
|
129
|
+
if (!(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
130
|
+
return res.status(403).json({ message: 'Unauthorized access' });
|
|
131
|
+
}
|
|
132
|
+
if (!adapter.listFilesByCategory) {
|
|
133
|
+
return res.status(501).json({ message: 'Storage adapter does not support listing files by category' });
|
|
134
|
+
}
|
|
135
|
+
const results = await Promise.allSettled(VALID_CATEGORIES.map(category => adapter.listFilesByCategory(projectId, category)));
|
|
136
|
+
const allFiles = results.flatMap(result => result.status === 'fulfilled' ? result.value : []);
|
|
137
|
+
const latest = allFiles
|
|
138
|
+
.sort((a, b) => new Date(b.lastModified).getTime() - new Date(a.lastModified).getTime())
|
|
139
|
+
.slice(0, 12);
|
|
140
|
+
res.json({ data: latest });
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
res.status(500).json({ message: 'Failed to fetch latest files', details: err.message });
|
|
144
|
+
}
|
|
145
|
+
});
|
|
118
146
|
router.get('/projects/:projectId/storage/:category', async (req, res) => {
|
|
119
147
|
try {
|
|
120
148
|
const auth = await config.authProvider(req);
|