[Videos] Fix uploads (#5042)
* fix pds url * fix service auth exp * whoopsie wrong branchzio/stable
parent
c60e8d0772
commit
e7954e590b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
@ -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>(
|
||||
|
|
Loading…
Reference in New Issue