Spaces:
Running
Running
import { v4 as uuidv4 } from 'uuid'; | |
// 内存存储,用于开发和测试 | |
class MemoryStorageService { | |
constructor() { | |
this.storage = new Map(); // userId -> Map<pptId, pptData> | |
} | |
// 获取用户的所有PPT列表 | |
async getUserPPTList(userId) { | |
const userStorage = this.storage.get(userId) || new Map(); | |
const pptList = Array.from(userStorage.entries()).map(([pptId, pptData]) => ({ | |
name: pptId, | |
title: pptData.title || '未命名演示文稿', | |
lastModified: pptData.updatedAt, | |
repoIndex: 0, | |
repoUrl: 'memory://local' | |
})); | |
return pptList; | |
} | |
// 获取PPT数据 | |
async getFile(userId, fileName) { | |
const pptId = fileName.replace('.json', ''); | |
const userStorage = this.storage.get(userId) || new Map(); | |
const pptData = userStorage.get(pptId); | |
if (!pptData) { | |
return null; | |
} | |
return { | |
content: pptData, | |
sha: 'memory-sha' | |
}; | |
} | |
// 保存PPT数据 | |
async saveFile(userId, fileName, data) { | |
const pptId = fileName.replace('.json', ''); | |
if (!this.storage.has(userId)) { | |
this.storage.set(userId, new Map()); | |
} | |
const userStorage = this.storage.get(userId); | |
userStorage.set(pptId, { | |
...data, | |
updatedAt: new Date().toISOString() | |
}); | |
return { success: true }; | |
} | |
// 删除PPT | |
async deleteFile(userId, fileName) { | |
const pptId = fileName.replace('.json', ''); | |
const userStorage = this.storage.get(userId); | |
if (!userStorage || !userStorage.has(pptId)) { | |
throw new Error('File not found'); | |
} | |
userStorage.delete(pptId); | |
return { success: true }; | |
} | |
} | |
export default new MemoryStorageService(); |