diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-08-30 18:44:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-30 18:44:00 +0100 |
commit | e7954e590b92b69dad8aabb0085a02e65024837d (patch) | |
tree | c86fcf4dfa156ac7f3a824630ba6c1e7eaa30ff4 /src | |
parent | c60e8d0772d93fb3b0eca00b5fb1de9e110df320 (diff) | |
download | voidsky-e7954e590b92b69dad8aabb0085a02e65024837d.tar.zst |
[Videos] Fix uploads (#5042)
* fix pds url * fix service auth exp * whoopsie wrong branch
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/strings/url-helpers.ts | 4 | ||||
-rw-r--r-- | src/state/queries/video/video-upload.ts | 9 | ||||
-rw-r--r-- | src/state/queries/video/video-upload.web.ts | 13 |
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>( |