AI Implementation feature(898): Admin Area General Settings and Categories 1.16 (#38)

This commit was merged in pull request #38.
This commit is contained in:
2026-07-22 19:19:46 +00:00
parent f62c77cf41
commit 113dd47371
11 changed files with 224 additions and 120 deletions
@@ -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',