-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Bump Dub version to fix createMany error (#18591)
Co-authored-by: Alex van Andel <me@alexvanandel.com>
- Loading branch information
1 parent
b63c979
commit 6be69b8
Showing
5 changed files
with
28 additions
and
59 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 |
---|---|---|
@@ -1,14 +1,19 @@ | ||
import { dub } from "@calcom/features/auth/lib/dub"; | ||
|
||
export const getShortenLink = (link: string) => { | ||
// don't hit dub with with empty string | ||
if (!link.length) { | ||
const pr: Promise<string> = new Promise((resolve) => resolve(link)); | ||
return pr; | ||
} else { | ||
return dub.links.create({ | ||
url: link, | ||
domain: "sms.cal.com", | ||
}); | ||
} | ||
export const bulkShortenLinks = async (links: string[]) => { | ||
const linksToShorten = links.filter((link) => link); | ||
const results = await dub.links.createMany( | ||
linksToShorten.map((link) => ({ domain: "sms.cal.com", url: link })) | ||
); | ||
return links.map((link) => { | ||
const createdLink = results.find( | ||
(result): result is Extract<typeof result, { url: string }> => | ||
!("error" in result) && result.url === link | ||
); | ||
if (createdLink) { | ||
return { shortLink: createdLink.shortLink }; | ||
} else { | ||
return { shortLink: link }; | ||
} | ||
}); | ||
}; |
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