Files
otunes/apps/mobile/lib/media-links.ts
T

41 lines
1.0 KiB
TypeScript

export type MediaShareContext = (
| { type: "album"; albumId: string }
| { type: "song"; albumId: string; songId: string }
| { type: "playlist"; playlistId: string; isFavorites?: boolean }
| { type: "artist"; artistId: string }
) & { title: string }
export function shouldShowShare(
share: MediaShareContext | undefined,
selectedCount: number
) {
if (!share) {
return false
}
if (share.type === "song") {
return selectedCount === 1
}
return true
}
export function mediaShareUrl(
serverUrl: string,
share: MediaShareContext
): string {
const origin = serverUrl.replace(/\/+$/, "")
switch (share.type) {
case "album":
return `${origin}/album/${share.albumId}`
case "song":
return `${origin}/album/${share.albumId}?s=${share.songId}`
case "playlist":
if (share.isFavorites) {
return `${origin}/playlist/favorites`
}
return `${origin}/playlist/${share.playlistId}`
case "artist":
return `${origin}/artist/${share.artistId}`
}
}