Bluesky app fork with some witchin' additions 💫

[Videos] Fix uploads (#5042)

* fix pds url

* fix service auth exp

* whoopsie wrong branch

authored by samuel.fm and committed by

GitHub e7954e59 c60e8d07

+12 -14
+2 -2
src/lib/strings/url-helpers.ts
··· 340 340 } 341 341 } 342 342 343 - export function getHostnameFromUrl(url: string): string | null { 343 + export function getHostnameFromUrl(url: string | URL): string | null { 344 344 let urlp 345 345 try { 346 346 urlp = new URL(url) ··· 350 350 return urlp.hostname 351 351 } 352 352 353 - export function getServiceAuthAudFromUrl(url: string): string | null { 353 + export function getServiceAuthAudFromUrl(url: string | URL): string | null { 354 354 const hostname = getHostnameFromUrl(url) 355 355 if (!hostname) { 356 356 return null
+3 -6
src/state/queries/video/video-upload.ts
··· 28 28 mutationFn: cancelable(async (video: CompressedVideo) => { 29 29 const uri = createVideoEndpointUrl('/xrpc/app.bsky.video.uploadVideo', { 30 30 did: currentAccount!.did, 31 - name: `${nanoid(12)}.mp4`, // @TODO what are we limiting this to? 31 + name: `${nanoid(12)}.mp4`, 32 32 }) 33 33 34 - if (!currentAccount?.service) { 35 - throw new Error('User is not logged in') 36 - } 34 + const serviceAuthAud = getServiceAuthAudFromUrl(agent.dispatchUrl) 37 35 38 - const serviceAuthAud = getServiceAuthAudFromUrl(currentAccount.service) 39 36 if (!serviceAuthAud) { 40 37 throw new Error('Agent does not have a PDS URL') 41 38 } ··· 44 41 { 45 42 aud: serviceAuthAud, 46 43 lxm: 'com.atproto.repo.uploadBlob', 47 - exp: Date.now() + 1000 * 60 * 30, // 30 minutes 44 + exp: Date.now() / 1000 + 60 * 30, // 30 minutes 48 45 }, 49 46 ) 50 47
+7 -6
src/state/queries/video/video-upload.web.ts
··· 30 30 name: `${nanoid(12)}.mp4`, // @TODO: make sure it's always mp4' 31 31 }) 32 32 33 - if (!currentAccount?.service) { 34 - throw new Error('User is not logged in') 35 - } 33 + const serviceAuthAud = getServiceAuthAudFromUrl(agent.dispatchUrl) 36 34 37 - const serviceAuthAud = getServiceAuthAudFromUrl(currentAccount.service) 38 35 if (!serviceAuthAud) { 39 36 throw new Error('Agent does not have a PDS URL') 40 37 } ··· 43 40 { 44 41 aud: serviceAuthAud, 45 42 lxm: 'com.atproto.repo.uploadBlob', 46 - exp: Date.now() + 1000 * 60 * 30, // 30 minutes 43 + exp: Date.now() / 1000 + 60 * 30, // 30 minutes 47 44 }, 48 45 ) 49 46 50 - const bytes = await fetch(video.uri).then(res => res.arrayBuffer()) 47 + let bytes = video.bytes 48 + 49 + if (!bytes) { 50 + bytes = await fetch(video.uri).then(res => res.arrayBuffer()) 51 + } 51 52 52 53 const xhr = new XMLHttpRequest() 53 54 const res = await new Promise<AppBskyVideoDefs.JobStatus>(