2024-10-08 12:32:47 -04:00
|
|
|
import { UnitLength_type } from '@kittycad/lib/dist/types/src/models'
|
|
|
|
import { CREATE_FILE_URL_PARAM, PROD_APP_URL } from './constants'
|
|
|
|
import { stringToBase64 } from './base64'
|
|
|
|
|
2024-10-08 14:52:38 -04:00
|
|
|
export interface FileLinkParams {
|
|
|
|
code: string
|
|
|
|
name: string
|
|
|
|
units: UnitLength_type
|
|
|
|
}
|
|
|
|
|
2024-10-08 12:32:47 -04:00
|
|
|
/**
|
|
|
|
* Given a file's code, name, and units, creates shareable link
|
|
|
|
* TODO: make the app respect this link
|
|
|
|
*/
|
|
|
|
export function createFileLink({
|
|
|
|
code,
|
|
|
|
name,
|
|
|
|
units,
|
2024-10-08 14:52:38 -04:00
|
|
|
}: FileLinkParams) {
|
2024-10-08 12:32:47 -04:00
|
|
|
return new URL(
|
|
|
|
`/?${CREATE_FILE_URL_PARAM}&name=${encodeURIComponent(
|
|
|
|
name
|
|
|
|
)}&units=${units}&code=${encodeURIComponent(stringToBase64(code))}`,
|
|
|
|
PROD_APP_URL
|
|
|
|
).href
|
|
|
|
}
|