-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
38 changed files
with
915 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "@calcom/features/calendar-cache/api/cron"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as add } from "./add"; | ||
export { default as callback } from "./callback"; | ||
export { default as webhook } from "./webhook"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { NextApiRequest } from "next"; | ||
|
||
import { HttpError } from "@calcom/lib/http-error"; | ||
import { defaultHandler, defaultResponder } from "@calcom/lib/server"; | ||
import { SelectedCalendarRepository } from "@calcom/lib/server/repository/selectedCalendar"; | ||
|
||
import { getCalendar } from "../../_utils/getCalendar"; | ||
|
||
async function postHandler(req: NextApiRequest) { | ||
if (req.headers["x-goog-channel-token"] !== process.env.GOOGLE_WEBHOOK_TOKEN) { | ||
throw new HttpError({ statusCode: 403, message: "Invalid API key" }); | ||
} | ||
if (typeof req.headers["x-goog-channel-id"] !== "string") { | ||
throw new HttpError({ statusCode: 403, message: "Missing Channel ID" }); | ||
} | ||
|
||
const selectedCalendar = await SelectedCalendarRepository.findByGoogleChannelId( | ||
req.headers["x-goog-channel-id"] | ||
); | ||
|
||
if (!selectedCalendar) { | ||
throw new HttpError({ | ||
statusCode: 200, | ||
message: `No selected calendar found for googleChannelId: ${req.headers["x-goog-channel-id"]}`, | ||
}); | ||
} | ||
const { credential } = selectedCalendar; | ||
if (!credential) | ||
throw new HttpError({ | ||
statusCode: 200, | ||
message: `No credential found for selected calendar for googleChannelId: ${req.headers["x-goog-channel-id"]}`, | ||
}); | ||
const { selectedCalendars } = credential; | ||
const calendar = await getCalendar(credential); | ||
await calendar?.fetchAvailabilityAndSetCache?.(selectedCalendars); | ||
return { message: "ok" }; | ||
} | ||
|
||
export default defaultHandler({ | ||
POST: Promise.resolve({ default: defaultResponder(postHandler) }), | ||
}); |
Oops, something went wrong.