File size: 1,780 Bytes
b7560a4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
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(); |