diff options
author | Hailey <me@haileyok.com> | 2024-08-29 13:44:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-29 13:44:47 -0700 |
commit | 69e896c221be26cefdf1030f527ebf9e1e4ce1f7 (patch) | |
tree | 0de2deb9d863e10744714f7ff7004e6a3684887c /src | |
parent | 91fe41670f0060e6d648a88fd8255caa42eb3143 (diff) | |
download | voidsky-69e896c221be26cefdf1030f527ebf9e1e4ce1f7.tar.zst |
[Video] Properly get the service auth aud from the session (#5025)
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/strings/url-helpers.ts | 18 | ||||
-rw-r--r-- | src/state/queries/video/video-upload.ts | 11 | ||||
-rw-r--r-- | src/state/queries/video/video-upload.web.ts | 11 |
3 files changed, 34 insertions, 6 deletions
diff --git a/src/lib/strings/url-helpers.ts b/src/lib/strings/url-helpers.ts index 0407df757..95c6bcead 100644 --- a/src/lib/strings/url-helpers.ts +++ b/src/lib/strings/url-helpers.ts @@ -339,3 +339,21 @@ export function shortLinkToHref(url: string): string { return url } } + +export function getHostnameFromUrl(url: string): string | null { + let urlp + try { + urlp = new URL(url) + } catch (e) { + return null + } + return urlp.hostname +} + +export function getServiceAuthAudFromUrl(url: string): string | null { + const hostname = getHostnameFromUrl(url) + if (!hostname) { + return null + } + return `did:web:${hostname}` +} diff --git a/src/state/queries/video/video-upload.ts b/src/state/queries/video/video-upload.ts index a41d4dd1e..11c8390ce 100644 --- a/src/state/queries/video/video-upload.ts +++ b/src/state/queries/video/video-upload.ts @@ -7,6 +7,7 @@ import {cancelable} from '#/lib/async/cancelable' import {CompressedVideo} from '#/lib/media/video/compress' import {createVideoEndpointUrl} from '#/state/queries/video/util' import {useAgent, useSession} from '#/state/session' +import {getServiceAuthAudFromUrl} from 'lib/strings/url-helpers' export const useUploadVideoMutation = ({ onSuccess, @@ -30,14 +31,18 @@ export const useUploadVideoMutation = ({ name: `${nanoid(12)}.mp4`, // @TODO what are we limiting this to? }) - // a logged-in agent should have this set, but we'll check just in case - if (!agent.pdsUrl) { + if (!currentAccount?.service) { + throw new Error('User is not logged in') + } + + const serviceAuthAud = getServiceAuthAudFromUrl(currentAccount.service) + if (!serviceAuthAud) { throw new Error('Agent does not have a PDS URL') } const {data: serviceAuth} = await agent.com.atproto.server.getServiceAuth( { - aud: `did:web:${agent.pdsUrl.hostname}`, + aud: serviceAuthAud, lxm: 'com.atproto.repo.uploadBlob', }, ) diff --git a/src/state/queries/video/video-upload.web.ts b/src/state/queries/video/video-upload.web.ts index 85e07c4e1..4673bc417 100644 --- a/src/state/queries/video/video-upload.web.ts +++ b/src/state/queries/video/video-upload.web.ts @@ -6,6 +6,7 @@ import {cancelable} from '#/lib/async/cancelable' import {CompressedVideo} from '#/lib/media/video/compress' import {createVideoEndpointUrl} from '#/state/queries/video/util' import {useAgent, useSession} from '#/state/session' +import {getServiceAuthAudFromUrl} from 'lib/strings/url-helpers' export const useUploadVideoMutation = ({ onSuccess, @@ -29,14 +30,18 @@ export const useUploadVideoMutation = ({ name: `${nanoid(12)}.mp4`, // @TODO: make sure it's always mp4' }) - // a logged-in agent should have this set, but we'll check just in case - if (!agent.pdsUrl) { + if (!currentAccount?.service) { + throw new Error('User is not logged in') + } + + const serviceAuthAud = getServiceAuthAudFromUrl(currentAccount.service) + if (!serviceAuthAud) { throw new Error('Agent does not have a PDS URL') } const {data: serviceAuth} = await agent.com.atproto.server.getServiceAuth( { - aud: `did:web:${agent.pdsUrl.hostname}`, + aud: serviceAuthAud, lxm: 'com.atproto.repo.uploadBlob', }, ) |