forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {logger} from '#/logger'
2
3export function useShortenLink() {
4 return async (inputUrl: string): Promise<{url: string}> => {
5 const url = new URL(inputUrl)
6 const res = await fetch('https://go.bsky.app/link', {
7 method: 'POST',
8 body: JSON.stringify({
9 path: url.pathname,
10 }),
11 headers: {
12 'Content-Type': 'application/json',
13 },
14 })
15
16 if (!res.ok) {
17 logger.error('Failed to shorten link', {safeMessage: res.status})
18 return {url: inputUrl}
19 }
20
21 return res.json()
22 }
23}