feat: add dedicated thumbnail upload endpoint for courses with old file cleanup and presigned URL generation.
This commit is contained in:
parent
b0383b78e9
commit
b303c50865
2 changed files with 78 additions and 15 deletions
|
|
@ -111,6 +111,29 @@ export class CoursesInstructorController {
|
|||
return await CoursesInstructorService.createCourse(value, decoded.id, thumbnail);
|
||||
}
|
||||
|
||||
/**
|
||||
* อัปโหลดรูป thumbnail ของคอร์ส
|
||||
* Upload course thumbnail image
|
||||
* @param courseId - รหัสคอร์ส / Course ID
|
||||
* @param file - ไฟล์รูปภาพ / Image file
|
||||
*/
|
||||
@Post('{courseId}/thumbnail')
|
||||
@Security('jwt', ['instructor'])
|
||||
@SuccessResponse('200', 'Thumbnail uploaded successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
@Response('400', 'Validation error')
|
||||
public async uploadThumbnail(
|
||||
@Request() request: any,
|
||||
@Path() courseId: number,
|
||||
@UploadedFile() file: Express.Multer.File
|
||||
): Promise<{ code: number; message: string; data: { course_id: number; thumbnail_url: string } }> {
|
||||
const token = request.headers.authorization?.replace('Bearer ', '');
|
||||
if (!token) throw new ValidationError('No token provided');
|
||||
if (!file.mimetype?.startsWith('image/')) throw new ValidationError('Only image files are allowed');
|
||||
|
||||
return await CoursesInstructorService.uploadThumbnail(token, courseId, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* ลบคอร์ส (เฉพาะผู้สอนหลักเท่านั้น)
|
||||
* Delete a course (only primary instructor can delete)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue