Bluesky app fork with some witchin' additions 💫

[Video] Properly get the service auth aud from the session (#5025)

authored by hailey.at and committed by

GitHub 69e896c2 91fe4167

+34 -6
+18
src/lib/strings/url-helpers.ts
··· 339 339 return url 340 340 } 341 341 } 342 + 343 + export function getHostnameFromUrl(url: string): string | null { 344 + let urlp 345 + try { 346 + urlp = new URL(url) 347 + } catch (e) { 348 + return null 349 + } 350 + return urlp.hostname 351 + } 352 + 353 + export function getServiceAuthAudFromUrl(url: string): string | null { 354 + const hostname = getHostnameFromUrl(url) 355 + if (!hostname) { 356 + return null 357 + } 358 + return `did:web:${hostname}` 359 + }
+8 -3
src/state/queries/video/video-upload.ts
··· 7 7 import {CompressedVideo} from '#/lib/media/video/compress' 8 8 import {createVideoEndpointUrl} from '#/state/queries/video/util' 9 9 import {useAgent, useSession} from '#/state/session' 10 + import {getServiceAuthAudFromUrl} from 'lib/strings/url-helpers' 10 11 11 12 export const useUploadVideoMutation = ({ 12 13 onSuccess, ··· 30 31 name: `${nanoid(12)}.mp4`, // @TODO what are we limiting this to? 31 32 }) 32 33 33 - // a logged-in agent should have this set, but we'll check just in case 34 - if (!agent.pdsUrl) { 34 + if (!currentAccount?.service) { 35 + throw new Error('User is not logged in') 36 + } 37 + 38 + const serviceAuthAud = getServiceAuthAudFromUrl(currentAccount.service) 39 + if (!serviceAuthAud) { 35 40 throw new Error('Agent does not have a PDS URL') 36 41 } 37 42 38 43 const {data: serviceAuth} = await agent.com.atproto.server.getServiceAuth( 39 44 { 40 - aud: `did:web:${agent.pdsUrl.hostname}`, 45 + aud: serviceAuthAud, 41 46 lxm: 'com.atproto.repo.uploadBlob', 42 47 }, 43 48 )
+8 -3
src/state/queries/video/video-upload.web.ts
··· 6 6 import {CompressedVideo} from '#/lib/media/video/compress' 7 7 import {createVideoEndpointUrl} from '#/state/queries/video/util' 8 8 import {useAgent, useSession} from '#/state/session' 9 + import {getServiceAuthAudFromUrl} from 'lib/strings/url-helpers' 9 10 10 11 export const useUploadVideoMutation = ({ 11 12 onSuccess, ··· 29 30 name: `${nanoid(12)}.mp4`, // @TODO: make sure it's always mp4' 30 31 }) 31 32 32 - // a logged-in agent should have this set, but we'll check just in case 33 - if (!agent.pdsUrl) { 33 + if (!currentAccount?.service) { 34 + throw new Error('User is not logged in') 35 + } 36 + 37 + const serviceAuthAud = getServiceAuthAudFromUrl(currentAccount.service) 38 + if (!serviceAuthAud) { 34 39 throw new Error('Agent does not have a PDS URL') 35 40 } 36 41 37 42 const {data: serviceAuth} = await agent.com.atproto.server.getServiceAuth( 38 43 { 39 - aud: `did:web:${agent.pdsUrl.hostname}`, 44 + aud: serviceAuthAud, 40 45 lxm: 'com.atproto.repo.uploadBlob', 41 46 }, 42 47 )