From 61f603d00241a5415098d5ec7fd182b057347ac8 Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 20 Apr 2025 14:52:45 +0200 Subject: [PATCH] carnet api nc --- app/api/nextcloud/status/route.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/api/nextcloud/status/route.ts b/app/api/nextcloud/status/route.ts index 15bb706e..60189318 100644 --- a/app/api/nextcloud/status/route.ts +++ b/app/api/nextcloud/status/route.ts @@ -5,6 +5,15 @@ import { DOMParser } from '@xmldom/xmldom'; import { Buffer } from 'buffer'; import { PrismaClient } from '@prisma/client'; +interface WebDAVCredentials { + id: string; + userId: string; + username: string; + password: string; + createdAt: Date; + updatedAt: Date; +} + const prisma = new PrismaClient(); async function sleep(ms: number) { @@ -60,9 +69,9 @@ async function createFolder(nextcloudUrl: string, username: string, password: st async function getWebDAVCredentials(nextcloudUrl: string, username: string, adminUsername: string, adminPassword: string, userId: string) { try { // Check if credentials exist in database - let credentials = await prisma.webDAVCredentials.findUnique({ + let credentials = await (prisma as any).webDAVCredentials.findUnique({ where: { userId }, - }); + }) as WebDAVCredentials | null; if (credentials) { // Verify existing credentials still work @@ -81,7 +90,7 @@ async function getWebDAVCredentials(nextcloudUrl: string, username: string, admi } // If verification failed, delete the old credentials - await prisma.webDAVCredentials.delete({ + await (prisma as any).webDAVCredentials.delete({ where: { userId }, }); } @@ -121,13 +130,13 @@ async function getWebDAVCredentials(nextcloudUrl: string, username: string, admi } // Store the new credentials - credentials = await prisma.webDAVCredentials.create({ + credentials = await (prisma as any).webDAVCredentials.create({ data: { userId, username, password: newPassword, }, - }); + }) as WebDAVCredentials; // Create required folder structure await createFolder(nextcloudUrl, username, newPassword, 'Private');