update api chapterlesson
This commit is contained in:
parent
2fc0fb7a76
commit
5c2b5d55aa
11 changed files with 855 additions and 85 deletions
|
|
@ -109,3 +109,81 @@ export async function getPresignedUrl(
|
|||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all objects in a path prefix
|
||||
*/
|
||||
export async function listObjects(prefix: string): Promise<{ name: string; size: number; lastModified: Date }[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const objects: { name: string; size: number; lastModified: Date }[] = [];
|
||||
const stream = minioClient.listObjectsV2(config.s3.bucket, prefix, true);
|
||||
|
||||
stream.on('data', (obj) => {
|
||||
if (obj.name) {
|
||||
objects.push({
|
||||
name: obj.name,
|
||||
size: obj.size || 0,
|
||||
lastModified: obj.lastModified || new Date(),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('error', (err) => {
|
||||
logger.error(`Error listing objects: ${err}`);
|
||||
reject(err);
|
||||
});
|
||||
|
||||
stream.on('end', () => {
|
||||
resolve(objects);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* List folders in a path prefix
|
||||
* Uses listObjectsV2 with recursive=false to get folder prefixes
|
||||
*/
|
||||
export async function listFolders(prefix: string): Promise<string[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const folders = new Set<string>();
|
||||
const stream = minioClient.listObjectsV2(config.s3.bucket, prefix, false);
|
||||
|
||||
stream.on('data', (obj: any) => {
|
||||
if (obj.prefix) {
|
||||
// Direct folder prefix
|
||||
folders.add(obj.prefix);
|
||||
} else if (obj.name) {
|
||||
// Extract folder part from file path
|
||||
const path = obj.name.replace(prefix, '');
|
||||
const folder = path.split('/')[0];
|
||||
|
||||
if (folder && path.includes('/')) {
|
||||
folders.add(prefix + folder + '/');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('error', (err) => {
|
||||
logger.error(`Error listing folders: ${err}`);
|
||||
reject(err);
|
||||
});
|
||||
|
||||
stream.on('end', () => {
|
||||
resolve(Array.from(folders));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attachments folder path for a lesson
|
||||
*/
|
||||
export function getAttachmentsFolder(courseId: number, lessonId: number): string {
|
||||
return `courses/${courseId}/lessons/${lessonId}/attachments/`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get video folder path for a lesson
|
||||
*/
|
||||
export function getVideoFolder(courseId: number, lessonId: number): string {
|
||||
return `courses/${courseId}/lessons/${lessonId}/video/`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue