Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Videos] Fix uploads #5042

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/strings/url-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/state/queries/video/video-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand All @@ -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
},
)

Expand Down
13 changes: 7 additions & 6 deletions src/state/queries/video/video-upload.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand All @@ -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>(
Expand Down
Loading