update logging messages

This commit is contained in:
yctimlin
2025-08-07 16:11:22 +00:00
parent b1f2aacfad
commit a07a53c22a
2 changed files with 13 additions and 13 deletions
+1 -1
View File
@@ -157,7 +157,7 @@ function App() {
try {
const currentElements = excalidrawAPI.getSceneElements()
console.log('当前元素:', currentElements);
console.log('Current elements:', currentElements);
switch (data.type) {
case 'initial_elements':
+12 -12
View File
@@ -77,7 +77,7 @@ wss.on('connection', (ws) => {
// Schema validation
const CreateElementSchema = z.object({
id: z.string().optional(), // 允许传入ID,用于MCP同步
id: z.string().optional(), // Allow passing ID for MCP sync
type: z.enum(Object.values(EXCALIDRAW_ELEMENT_TYPES)),
x: z.number(),
y: z.number(),
@@ -142,7 +142,7 @@ app.post('/api/elements', (req, res) => {
const params = CreateElementSchema.parse(req.body);
logger.info('Creating element via API', { type: params.type });
// 优先使用传入的ID(用于MCP同步),否则生成新ID
// Prioritize passed ID (for MCP sync), otherwise generate new ID
const id = params.id || generateId();
const element = {
id,
@@ -357,7 +357,7 @@ app.post('/api/elements/batch', (req, res) => {
}
});
// Sync elements from frontend (覆盖式同步)
// Sync elements from frontend (overwrite sync)
app.post('/api/elements/sync', (req, res) => {
try {
const { elements: frontendElements, timestamp } = req.body;
@@ -367,7 +367,7 @@ app.post('/api/elements/sync', (req, res) => {
elementCount: frontendElements.length
});
// 验证输入数据
// Validate input data
if (!Array.isArray(frontendElements)) {
return res.status(400).json({
success: false,
@@ -375,23 +375,23 @@ app.post('/api/elements/sync', (req, res) => {
});
}
// 记录同步前的元素数量
// Record element count before sync
const beforeCount = elements.size;
// 1. 清空现有内存存储
// 1. Clear existing memory storage
elements.clear();
logger.info(`Cleared existing elements: ${beforeCount} elements removed`);
// 2. 批量写入新数据
// 2. Batch write new data
let successCount = 0;
const processedElements = [];
frontendElements.forEach((element, index) => {
try {
// 确保元素有ID,如果没有则生成一个
// Ensure element has ID, generate one if missing
const elementId = element.id || generateId();
// 添加服务端元数据
// Add server metadata
const processedElement = {
...element,
id: elementId,
@@ -401,7 +401,7 @@ app.post('/api/elements/sync', (req, res) => {
version: 1
};
// 存储到内存
// Store to memory
elements.set(elementId, processedElement);
processedElements.push(processedElement);
successCount++;
@@ -413,7 +413,7 @@ app.post('/api/elements/sync', (req, res) => {
logger.info(`Sync completed: ${successCount}/${frontendElements.length} elements synced`);
// 3. 广播同步事件给所有WebSocket客户端
// 3. Broadcast sync event to all WebSocket clients
broadcast({
type: 'elements_synced',
count: successCount,
@@ -421,7 +421,7 @@ app.post('/api/elements/sync', (req, res) => {
source: 'manual_sync'
});
// 4. 返回同步结果
// 4. Return sync results
res.json({
success: true,
message: `Successfully synced ${successCount} elements`,