carnet api nc

This commit is contained in:
alma 2025-04-20 15:10:03 +02:00
parent 61f603d002
commit 6a71516251
2 changed files with 11 additions and 14 deletions

View File

@ -5,16 +5,13 @@ 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;
// Use a single PrismaClient instance
declare global {
var prisma: PrismaClient | undefined;
}
const prisma = new PrismaClient();
const prisma = global.prisma || new PrismaClient();
if (process.env.NODE_ENV !== 'production') global.prisma = prisma;
async function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
@ -69,9 +66,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 as any).webDAVCredentials.findUnique({
let credentials = await prisma.webDAVCredentials.findUnique({
where: { userId },
}) as WebDAVCredentials | null;
});
if (credentials) {
// Verify existing credentials still work
@ -90,7 +87,7 @@ async function getWebDAVCredentials(nextcloudUrl: string, username: string, admi
}
// If verification failed, delete the old credentials
await (prisma as any).webDAVCredentials.delete({
await prisma.webDAVCredentials.delete({
where: { userId },
});
}
@ -130,13 +127,13 @@ async function getWebDAVCredentials(nextcloudUrl: string, username: string, admi
}
// Store the new credentials
credentials = await (prisma as any).webDAVCredentials.create({
credentials = await prisma.webDAVCredentials.create({
data: {
userId,
username,
password: newPassword,
},
}) as WebDAVCredentials;
});
// Create required folder structure
await createFolder(nextcloudUrl, username, newPassword, 'Private');

View File

@ -8,7 +8,7 @@ generator client {
datasource db {
provider = "postgresql"
url = env("NEWSDB_URL")
url = env("DATABASE_URL")
}
model User {