From 3761a75b28bc787aa87c6710736ceb46ed0e75c5 Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Thu, 23 Dec 2021 04:38:24 +0800 Subject: [PATCH] fixed zoom video not creating when credentials are not valid (#1329) * fixed nextcloud * fixed nextcloud & fastmail issues * fixed zoom video not creating when credentials are not valid also fixed reponse to reflect create failure. Co-authored-by: Peer Richelsen Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- lib/integrations/Zoom/ZoomVideoApiAdapter.ts | 5 +++-- lib/videoClient.ts | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/integrations/Zoom/ZoomVideoApiAdapter.ts b/lib/integrations/Zoom/ZoomVideoApiAdapter.ts index 8ac07b66ee..ea48ddad6b 100644 --- a/lib/integrations/Zoom/ZoomVideoApiAdapter.ts +++ b/lib/integrations/Zoom/ZoomVideoApiAdapter.ts @@ -69,7 +69,8 @@ interface ZoomToken { const zoomAuth = (credential: Credential) => { const credentialKey = credential.key as unknown as ZoomToken; - const isExpired = (expiryDate: number) => expiryDate < Date.now(); + const isTokenValid = (token: ZoomToken) => + token && token.token_type && token.access_token && (token.expires_in || token.expiry_date) < Date.now(); const authHeader = "Basic " + Buffer.from(process.env.ZOOM_CLIENT_ID + ":" + process.env.ZOOM_CLIENT_SECRET).toString("base64"); @@ -107,7 +108,7 @@ const zoomAuth = (credential: Credential) => { return { getToken: () => - !isExpired(credentialKey.expires_in || credentialKey.expiry_date) + !isTokenValid(credentialKey) ? Promise.resolve(credentialKey.access_token) : refreshAccessToken(credentialKey.refresh_token), }; diff --git a/lib/videoClient.ts b/lib/videoClient.ts index e57d23476f..7e5d7168f7 100644 --- a/lib/videoClient.ts +++ b/lib/videoClient.ts @@ -68,19 +68,16 @@ const createMeeting = async ( ); } - let success = true; - const videoAdapters = getVideoAdapters([credential]); const [firstVideoAdapter] = videoAdapters; const createdMeeting = await firstVideoAdapter.createMeeting(calEvent).catch((e) => { log.error("createMeeting failed", e, calEvent); - success = false; }); if (!createdMeeting) { return { type: credential.type, - success, + success: false, uid, originalEvent: calEvent, }; @@ -88,7 +85,7 @@ const createMeeting = async ( return { type: credential.type, - success, + success: true, uid, createdEvent: createdMeeting, originalEvent: calEvent,