carnet api nc
This commit is contained in:
parent
d2366a8c74
commit
61f603d002
@ -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');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user