File tree Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -339,3 +339,21 @@ export function shortLinkToHref(url: string): string {
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
+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import {cancelable} from '#/lib/async/cancelable'
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,14 +31,18 @@ export const useUploadVideoMutation = ({
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
)
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import {cancelable} from '#/lib/async/cancelable'
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,14 +30,18 @@ export const useUploadVideoMutation = ({
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
)
You can’t perform that action at this time.
0 commit comments