extract functions and add tests

This commit is contained in:
Hailey
2024-06-17 16:28:17 -07:00
parent e62f029152
commit 90f299f6e2
4 changed files with 170 additions and 29 deletions
+54
View File
@@ -0,0 +1,54 @@
import {makeStarterPackLink} from 'lib/routes/links'
export function createStarterPackLinkFromAndroidReferrer(
referrerQueryString: string,
): string | null {
try {
// The referrer string is just some URL parameters, so lets add them to a fake URL
const url = new URL('http://throwaway.com/?' + referrerQueryString)
const utmContent = url.searchParams.get('utm_content')
const utmSource = url.searchParams.get('utm_source')
if (!utmContent) return null
if (utmSource !== 'bluesky') return null
// This should be a string like `starterpack-haileyok.com-rkey`
const contentParts = utmContent.split('-')
if (contentParts[0] !== 'starterpack') return null
if (contentParts.length !== 3) return null
return makeStarterPackLink(contentParts[1], contentParts[2])
} catch (e) {
return null
}
}
export function parseStarterPackHttpUri(uri: string): {
name?: string
rkey?: string
} | null {
try {
const url = new URL(uri)
const parts = url.pathname.split('/')
const name = parts[2]
const rkey = parts[3]
if (parts.length !== 4) return null
if (!name || !rkey) return null
return {
name,
rkey,
}
} catch (e) {
return null
}
}
export function createStarterPackGooglePlayUri(
name: string,
rkey: string,
): string | null {
if (!name || !rkey) return null
return `https://play.google.com/store/apps/details?id=xyz.blueskyweb.app&referrer=utm_source%3Dbluesky%26utm_medium%3Dstarterpack%26utm_content%3Dstarterpack-${name}-${rkey}`
}