Organization and Pro tier link sharing features exposure (#6986)

* Improve url sharing for orgs and pros

* Remove sharing via menu item

* fmt

* Not sure what's different but it is

* fmt & lint

* whoops

* Update snapshots

* Typos from codespell

* Fix alignment

* Update snapshots

* Prune

---------

Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
This commit is contained in:
Zookeeper Lee
2025-05-16 05:51:08 -04:00
committed by GitHub
parent 17eb84325f
commit 48a4fd8373
36 changed files with 259 additions and 117 deletions

View File

@ -11,6 +11,8 @@ import { err } from '@src/lib/trap'
export interface FileLinkParams {
code: string
name: string
isRestrictedToOrg: boolean
password?: string
}
export async function copyFileShareLink(
@ -24,7 +26,12 @@ export async function copyFileShareLink(
return
}
const shareUrl = createCreateFileUrl(args)
const shortlink = await createShortlink(token, shareUrl.toString())
const shortlink = await createShortlink(
token,
shareUrl.toString(),
args.isRestrictedToOrg,
args.password
)
if (err(shortlink)) {
toast.error(shortlink.message, {
@ -70,23 +77,32 @@ export function createCreateFileUrl({ code, name }: FileLinkParams) {
*/
export async function createShortlink(
token: string,
url: string
url: string,
isRestrictedToOrg: boolean,
password?: string
): Promise<Error | { key: string; url: string }> {
/**
* We don't use our `withBaseURL` function here because
* there is no URL shortener service in the dev API.
*/
const body: {
url: string
restrict_to_org: boolean
password?: string
} = {
url,
restrict_to_org: isRestrictedToOrg,
}
if (password) {
body.password = password
}
const response = await fetch(`${VITE_KC_API_BASE_URL}/user/shortlinks`, {
method: 'POST',
headers: {
'Content-type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
url,
// In future we can support org-scoped and password-protected shortlinks here
// https://zoo.dev/docs/api/shortlinks/create-a-shortlink-for-a-user?lang=typescript
}),
body: JSON.stringify(body),
})
if (!response.ok) {
const error = await response.json()