Merge pull request #459 from femyeda/caldav-connection-issues
This commit is contained in:
commit
ec9fefefec
2 changed files with 26 additions and 39 deletions
|
@ -103,6 +103,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
|
||||||
};
|
};
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
console.error(reason);
|
||||||
|
throw reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +154,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
|
||||||
return null;
|
return null;
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
console.error(reason);
|
||||||
|
throw reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,6 +188,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
|
||||||
return null;
|
return null;
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
console.error(reason);
|
||||||
|
throw reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,6 +215,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
|
||||||
return events;
|
return events;
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
console.error(reason);
|
||||||
|
throw reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +239,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
|
||||||
}));
|
}));
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
console.error(reason);
|
||||||
|
throw reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,6 +300,7 @@ export class CalDavCalendar implements CalendarApiAdapter {
|
||||||
return events;
|
return events;
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
console.error(reason);
|
console.error(reason);
|
||||||
|
throw reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { getSession } from "next-auth/client";
|
||||||
import prisma from "../../../../lib/prisma";
|
import prisma from "../../../../lib/prisma";
|
||||||
import { symmetricEncrypt } from "@lib/crypto";
|
import { symmetricEncrypt } from "@lib/crypto";
|
||||||
import logger from "@lib/logger";
|
import logger from "@lib/logger";
|
||||||
import { davRequest, getBasicAuthHeaders } from "tsdav";
|
import { CalDavCalendar } from "@lib/integrations/CalDav/CalDavCalendarAdapter";
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
if (req.method === "POST") {
|
if (req.method === "POST") {
|
||||||
|
@ -26,47 +26,28 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const header = getBasicAuthHeaders({
|
|
||||||
username,
|
|
||||||
password,
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [response] = await davRequest({
|
const dav = new CalDavCalendar({
|
||||||
url: url,
|
id: 0,
|
||||||
init: {
|
type: "caldav_calendar",
|
||||||
method: "PROPFIND",
|
key: symmetricEncrypt(
|
||||||
namespace: "d",
|
JSON.stringify({ username, password, url }),
|
||||||
body: {
|
process.env.CALENDSO_ENCRYPTION_KEY
|
||||||
propfind: {
|
),
|
||||||
_attributes: {
|
userId: session.user.id,
|
||||||
"xmlns:d": "DAV:",
|
|
||||||
},
|
|
||||||
prop: { "d:current-user-principal": {} },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
headers: header,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
await dav.listCalendars();
|
||||||
logger.error("Could not add this caldav account", response?.statusText);
|
await prisma.credential.create({
|
||||||
logger.error(response.error);
|
data: {
|
||||||
return res.status(200).json({ message: "Could not add this caldav account" });
|
type: "caldav_calendar",
|
||||||
}
|
key: symmetricEncrypt(
|
||||||
|
JSON.stringify({ username, password, url }),
|
||||||
if (response.ok) {
|
process.env.CALENDSO_ENCRYPTION_KEY
|
||||||
await prisma.credential.create({
|
),
|
||||||
data: {
|
userId: session.user.id,
|
||||||
type: "caldav_calendar",
|
},
|
||||||
key: symmetricEncrypt(
|
});
|
||||||
JSON.stringify({ username, password, url }),
|
|
||||||
process.env.CALENDSO_ENCRYPTION_KEY
|
|
||||||
),
|
|
||||||
userId: session.user.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
logger.error("Could not add this caldav account", reason);
|
logger.error("Could not add this caldav account", reason);
|
||||||
return res.status(500).json({ message: "Could not add this caldav account" });
|
return res.status(500).json({ message: "Could not add this caldav account" });
|
||||||
|
|
Loading…
Reference in a new issue