[Video] Properly get the service auth aud from the session (#5025)
parent
91fe41670f
commit
69e896c221
|
@ -339,3 +339,21 @@ export function shortLinkToHref(url: string): string {
|
||||||
return url
|
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}`
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {cancelable} from '#/lib/async/cancelable'
|
||||||
import {CompressedVideo} from '#/lib/media/video/compress'
|
import {CompressedVideo} from '#/lib/media/video/compress'
|
||||||
import {createVideoEndpointUrl} from '#/state/queries/video/util'
|
import {createVideoEndpointUrl} from '#/state/queries/video/util'
|
||||||
import {useAgent, useSession} from '#/state/session'
|
import {useAgent, useSession} from '#/state/session'
|
||||||
|
import {getServiceAuthAudFromUrl} from 'lib/strings/url-helpers'
|
||||||
|
|
||||||
export const useUploadVideoMutation = ({
|
export const useUploadVideoMutation = ({
|
||||||
onSuccess,
|
onSuccess,
|
||||||
|
@ -30,14 +31,18 @@ export const useUploadVideoMutation = ({
|
||||||
name: `${nanoid(12)}.mp4`, // @TODO what are we limiting this to?
|
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 (!currentAccount?.service) {
|
||||||
if (!agent.pdsUrl) {
|
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')
|
throw new Error('Agent does not have a PDS URL')
|
||||||
}
|
}
|
||||||
|
|
||||||
const {data: serviceAuth} = await agent.com.atproto.server.getServiceAuth(
|
const {data: serviceAuth} = await agent.com.atproto.server.getServiceAuth(
|
||||||
{
|
{
|
||||||
aud: `did:web:${agent.pdsUrl.hostname}`,
|
aud: serviceAuthAud,
|
||||||
lxm: 'com.atproto.repo.uploadBlob',
|
lxm: 'com.atproto.repo.uploadBlob',
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {cancelable} from '#/lib/async/cancelable'
|
||||||
import {CompressedVideo} from '#/lib/media/video/compress'
|
import {CompressedVideo} from '#/lib/media/video/compress'
|
||||||
import {createVideoEndpointUrl} from '#/state/queries/video/util'
|
import {createVideoEndpointUrl} from '#/state/queries/video/util'
|
||||||
import {useAgent, useSession} from '#/state/session'
|
import {useAgent, useSession} from '#/state/session'
|
||||||
|
import {getServiceAuthAudFromUrl} from 'lib/strings/url-helpers'
|
||||||
|
|
||||||
export const useUploadVideoMutation = ({
|
export const useUploadVideoMutation = ({
|
||||||
onSuccess,
|
onSuccess,
|
||||||
|
@ -29,14 +30,18 @@ export const useUploadVideoMutation = ({
|
||||||
name: `${nanoid(12)}.mp4`, // @TODO: make sure it's always mp4'
|
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 (!currentAccount?.service) {
|
||||||
if (!agent.pdsUrl) {
|
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')
|
throw new Error('Agent does not have a PDS URL')
|
||||||
}
|
}
|
||||||
|
|
||||||
const {data: serviceAuth} = await agent.com.atproto.server.getServiceAuth(
|
const {data: serviceAuth} = await agent.com.atproto.server.getServiceAuth(
|
||||||
{
|
{
|
||||||
aud: `did:web:${agent.pdsUrl.hostname}`,
|
aud: serviceAuthAud,
|
||||||
lxm: 'com.atproto.repo.uploadBlob',
|
lxm: 'com.atproto.repo.uploadBlob',
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue