feat: Admin Area General Settings and Categories 1.16
This commit is contained in:
@@ -65,6 +65,9 @@ export class UploadsController {
|
||||
private static readonly LOGO_ERROR_MESSAGE =
|
||||
'Logo must be a valid PNG, JPEG, GIF, or WebP image.';
|
||||
|
||||
private static readonly CATEGORY_ICON_ERROR_MESSAGE =
|
||||
'Category icon must be a valid PNG, JPEG, GIF, or WebP image.';
|
||||
|
||||
private async handleCategoryIcon(req: any): Promise<{ id: string; publicUrl: string; width: number; height: number; mimeType: string; storedPath: string; size: number; originalFilename: string }> {
|
||||
const file = req.file as any;
|
||||
if (!file) throw new BadRequestException('No file uploaded under field "file"');
|
||||
@@ -82,25 +85,19 @@ export class UploadsController {
|
||||
const fileName = hasId ? `${categoryId}.png` : safeFilename(file.originalname || 'file.png');
|
||||
const finalPath = path.join(finalDir, fileName);
|
||||
|
||||
let width = 0;
|
||||
let height = 0;
|
||||
let mimeType = file.mimetype || 'application/octet-stream';
|
||||
let stored: Buffer = file.buffer;
|
||||
let stored: Buffer;
|
||||
try {
|
||||
stored = await sharp(file.buffer)
|
||||
.resize(128, 128, { fit: 'cover', position: 'centre' })
|
||||
.png()
|
||||
.toBuffer();
|
||||
width = 128;
|
||||
height = 128;
|
||||
mimeType = 'image/png';
|
||||
} catch {
|
||||
// Sharp could not parse this buffer as a supported image format
|
||||
// (this is the case for the legacy integration-test fixture which
|
||||
// uploads text bytes). Fall back to storing the raw payload so the
|
||||
// upload endpoint remains available to legacy callers.
|
||||
throw new BadRequestException(UploadsController.CATEGORY_ICON_ERROR_MESSAGE);
|
||||
}
|
||||
fs.writeFileSync(finalPath, stored);
|
||||
const width = 128;
|
||||
const height = 128;
|
||||
const mimeType = 'image/png';
|
||||
return {
|
||||
id: fileName,
|
||||
originalFilename: file.originalname || 'file.png',
|
||||
|
||||
Reference in New Issue
Block a user