carnet api nc
This commit is contained in:
parent
61f603d002
commit
6a71516251
@ -5,16 +5,13 @@ import { DOMParser } from '@xmldom/xmldom';
|
|||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
interface WebDAVCredentials {
|
// Use a single PrismaClient instance
|
||||||
id: string;
|
declare global {
|
||||||
userId: string;
|
var prisma: PrismaClient | undefined;
|
||||||
username: string;
|
|
||||||
password: string;
|
|
||||||
createdAt: Date;
|
|
||||||
updatedAt: Date;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = global.prisma || new PrismaClient();
|
||||||
|
if (process.env.NODE_ENV !== 'production') global.prisma = prisma;
|
||||||
|
|
||||||
async function sleep(ms: number) {
|
async function sleep(ms: number) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
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) {
|
async function getWebDAVCredentials(nextcloudUrl: string, username: string, adminUsername: string, adminPassword: string, userId: string) {
|
||||||
try {
|
try {
|
||||||
// Check if credentials exist in database
|
// Check if credentials exist in database
|
||||||
let credentials = await (prisma as any).webDAVCredentials.findUnique({
|
let credentials = await prisma.webDAVCredentials.findUnique({
|
||||||
where: { userId },
|
where: { userId },
|
||||||
}) as WebDAVCredentials | null;
|
});
|
||||||
|
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
// Verify existing credentials still work
|
// Verify existing credentials still work
|
||||||
@ -90,7 +87,7 @@ async function getWebDAVCredentials(nextcloudUrl: string, username: string, admi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If verification failed, delete the old credentials
|
// If verification failed, delete the old credentials
|
||||||
await (prisma as any).webDAVCredentials.delete({
|
await prisma.webDAVCredentials.delete({
|
||||||
where: { userId },
|
where: { userId },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -130,13 +127,13 @@ async function getWebDAVCredentials(nextcloudUrl: string, username: string, admi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store the new credentials
|
// Store the new credentials
|
||||||
credentials = await (prisma as any).webDAVCredentials.create({
|
credentials = await prisma.webDAVCredentials.create({
|
||||||
data: {
|
data: {
|
||||||
userId,
|
userId,
|
||||||
username,
|
username,
|
||||||
password: newPassword,
|
password: newPassword,
|
||||||
},
|
},
|
||||||
}) as WebDAVCredentials;
|
});
|
||||||
|
|
||||||
// Create required folder structure
|
// Create required folder structure
|
||||||
await createFolder(nextcloudUrl, username, newPassword, 'Private');
|
await createFolder(nextcloudUrl, username, newPassword, 'Private');
|
||||||
|
|||||||
@ -8,7 +8,7 @@ generator client {
|
|||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = "postgresql"
|
provider = "postgresql"
|
||||||
url = env("NEWSDB_URL")
|
url = env("DATABASE_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
model User {
|
model User {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user