mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
- Fix setProjectCustomIcon using wrong property name (customIcon -> customIconPath) - Add currentProject state update to setProjectIcon and setProjectCustomIcon - Fix data URL regex to handle all formats (e.g., charset=utf-8 in GIFs) - Increase project icon size limit from 2MB to 5MB for animated GIFs - Add toast notifications for upload validation errors - Add image error fallback to folder icon in project switcher - Make HttpApiClient get/put methods public for store access - Fix TypeScript errors in app-store.ts (trashedAt type, font properties) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
/**
|
|
* POST /save-board-background endpoint - Save board background image
|
|
*/
|
|
|
|
import type { Request, Response } from 'express';
|
|
import * as secureFs from '../../../lib/secure-fs.js';
|
|
import path from 'path';
|
|
import { getErrorMessage, logError } from '../common.js';
|
|
import { getBoardDir } from '@automaker/platform';
|
|
|
|
export function createSaveBoardBackgroundHandler() {
|
|
return async (req: Request, res: Response): Promise<void> => {
|
|
try {
|
|
const { data, filename, mimeType, projectPath } = req.body as {
|
|
data: string;
|
|
filename: string;
|
|
mimeType: string;
|
|
projectPath: string;
|
|
};
|
|
|
|
if (!data || !filename || !projectPath) {
|
|
res.status(400).json({
|
|
success: false,
|
|
error: 'data, filename, and projectPath are required',
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Get board directory
|
|
const boardDir = getBoardDir(projectPath);
|
|
await secureFs.mkdir(boardDir, { recursive: true });
|
|
|
|
// Decode base64 data (remove data URL prefix if present)
|
|
// Use a regex that handles all data URL formats including those with extra params
|
|
// e.g., data:image/gif;charset=utf-8;base64,R0lGOD...
|
|
const base64Data = data.replace(/^data:[^,]+,/, '');
|
|
const buffer = Buffer.from(base64Data, 'base64');
|
|
|
|
// Use a fixed filename for the board background (overwrite previous)
|
|
const ext = path.extname(filename) || '.png';
|
|
const uniqueFilename = `background${ext}`;
|
|
const filePath = path.join(boardDir, uniqueFilename);
|
|
|
|
// Write file
|
|
await secureFs.writeFile(filePath, buffer);
|
|
|
|
// Return the absolute path
|
|
res.json({ success: true, path: filePath });
|
|
} catch (error) {
|
|
logError(error, 'Save board background failed');
|
|
res.status(500).json({ success: false, error: getErrorMessage(error) });
|
|
}
|
|
};
|
|
}
|