Измения в АПИ

This commit is contained in:
2025-08-07 18:33:28 +00:00
parent b2db578f5f
commit a1f1deea13
45 changed files with 1955 additions and 1119 deletions

View File

@@ -29,32 +29,26 @@ export async function connectToDatabase() {
return { db, client };
}
// Инициализация MongoDB
export async function initMongoDB() {
try {
const { db } = await connectToDatabase();
// Создаем уникальный индекс для избранного
await db.collection('favorites').createIndex(
{ userId: 1, mediaId: 1, mediaType: 1 },
{ unique: true }
);
console.log('MongoDB initialized successfully');
} catch (error) {
console.error('Error initializing MongoDB:', error);
throw error;
}
}
// Функция для сброса и создания индексов
export async function resetIndexes() {
const { db } = await connectToDatabase();
// Удаляем все индексы из коллекции favorites
await db.collection('favorites').dropIndexes();
// Создаем новый правильный индекс
await db.collection('favorites').createIndex(
{ userId: 1, mediaId: 1, mediaType: 1 },
{ unique: true }