about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/strings/url-helpers.ts4
-rw-r--r--src/state/queries/video/video-upload.ts9
-rw-r--r--src/state/queries/video/video-upload.web.ts13
3 files changed, 12 insertions, 14 deletions
diff --git a/src/lib/strings/url-helpers.ts b/src/lib/strings/url-helpers.ts
index 95c6bcead..4c8db8399 100644
--- a/src/lib/strings/url-helpers.ts
+++ b/src/lib/strings/url-helpers.ts
@@ -340,7 +340,7 @@ export function shortLinkToHref(url: string): string {
   }
 }
 
-export function getHostnameFromUrl(url: string): string | null {
+export function getHostnameFromUrl(url: string | URL): string | null {
   let urlp
   try {
     urlp = new URL(url)
@@ -350,7 +350,7 @@ export function getHostnameFromUrl(url: string): string | null {
   return urlp.hostname
 }
 
-export function getServiceAuthAudFromUrl(url: string): string | null {
+export function getServiceAuthAudFromUrl(url: string | URL): string | null {
   const hostname = getHostnameFromUrl(url)
   if (!hostname) {
     return null
diff --git a/src/state/queries/video/video-upload.ts b/src/state/queries/video/video-upload.ts
index 50aa8bb6c..5dde5c31b 100644
--- a/src/state/queries/video/video-upload.ts
+++ b/src/state/queries/video/video-upload.ts
@@ -28,14 +28,11 @@ export const useUploadVideoMutation = ({
     mutationFn: cancelable(async (video: CompressedVideo) => {
       const uri = createVideoEndpointUrl('/xrpc/app.bsky.video.uploadVideo', {
         did: currentAccount!.did,
-        name: `${nanoid(12)}.mp4`, // @TODO what are we limiting this to?
+        name: `${nanoid(12)}.mp4`,
       })
 
-      if (!currentAccount?.service) {
-        throw new Error('User is not logged in')
-      }
+      const serviceAuthAud = getServiceAuthAudFromUrl(agent.dispatchUrl)
 
-      const serviceAuthAud = getServiceAuthAudFromUrl(currentAccount.service)
       if (!serviceAuthAud) {
         throw new Error('Agent does not have a PDS URL')
       }
@@ -44,7 +41,7 @@ export const useUploadVideoMutation = ({
         {
           aud: serviceAuthAud,
           lxm: 'com.atproto.repo.uploadBlob',
-          exp: Date.now() + 1000 * 60 * 30, // 30 minutes
+          exp: Date.now() / 1000 + 60 * 30, // 30 minutes
         },
       )
 
diff --git a/src/state/queries/video/video-upload.web.ts b/src/state/queries/video/video-upload.web.ts
index 123c60155..a8494970a 100644
--- a/src/state/queries/video/video-upload.web.ts
+++ b/src/state/queries/video/video-upload.web.ts
@@ -30,11 +30,8 @@ export const useUploadVideoMutation = ({
         name: `${nanoid(12)}.mp4`, // @TODO: make sure it's always mp4'
       })
 
-      if (!currentAccount?.service) {
-        throw new Error('User is not logged in')
-      }
+      const serviceAuthAud = getServiceAuthAudFromUrl(agent.dispatchUrl)
 
-      const serviceAuthAud = getServiceAuthAudFromUrl(currentAccount.service)
       if (!serviceAuthAud) {
         throw new Error('Agent does not have a PDS URL')
       }
@@ -43,11 +40,15 @@ export const useUploadVideoMutation = ({
         {
           aud: serviceAuthAud,
           lxm: 'com.atproto.repo.uploadBlob',
-          exp: Date.now() + 1000 * 60 * 30, // 30 minutes
+          exp: Date.now() / 1000 + 60 * 30, // 30 minutes
         },
       )
 
-      const bytes = await fetch(video.uri).then(res => res.arrayBuffer())
+      let bytes = video.bytes
+
+      if (!bytes) {
+        bytes = await fetch(video.uri).then(res => res.arrayBuffer())
+      }
 
       const xhr = new XMLHttpRequest()
       const res = await new Promise<AppBskyVideoDefs.JobStatus>(