[SDK] Migrate the post pipeline and blob uploads (#11380)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-13 22:26:20 +03:00
committed by GitHub
parent 75e4180800
commit 0c93d1e416
13 changed files with 483 additions and 223 deletions
+5 -11
View File
@@ -1,5 +1,5 @@
import {type AppBskyGraphDefs} from '@atproto/api'
import {type $Typed, type Client, type l} from '@atproto/lex'
import {type $Typed, type Client} from '@atproto/lex'
import {
type AtIdentifierString,
AtUri,
@@ -56,7 +56,6 @@ export interface ListCreateMutateParams {
export function useListCreateMutation() {
const {currentAccount} = useSession()
const queryClient = useQueryClient()
const agent = useAgent()
const appviewClient = useAppviewClient()
const pdsClient = usePdsClient()
return useMutation<{uri: string; cid: string}, Error, ListCreateMutateParams>(
@@ -86,12 +85,8 @@ export function useListCreateMutation() {
createdAt: toDatetimeString(new Date()),
}
if (avatar) {
const blobRes = await uploadBlob(agent, avatar.path, avatar.mime)
/*
* `uploadBlob` still returns the legacy `BlobRef` class instance;
* it moves to the client with the rest of the blob pipeline.
*/
record.avatar = blobRes.data.blob as unknown as l.BlobRef
const blobRes = await uploadBlob(pdsClient, avatar.path, avatar.mime)
record.avatar = blobRes.blob
}
const res = await pdsClient.create(app.bsky.graph.list, record)
@@ -120,7 +115,6 @@ export interface ListMetadataMutateParams {
}
export function useListMetadataMutation() {
const {currentAccount} = useSession()
const agent = useAgent()
const appviewClient = useAppviewClient()
const pdsClient = usePdsClient()
const queryClient = useQueryClient()
@@ -149,8 +143,8 @@ export function useListMetadataMutation() {
record.description = description
record.descriptionFacets = descriptionFacets
if (avatar) {
const blobRes = await uploadBlob(agent, avatar.path, avatar.mime)
record.avatar = blobRes.data.blob as unknown as l.BlobRef
const blobRes = await uploadBlob(pdsClient, avatar.path, avatar.mime)
record.avatar = blobRes.blob
} else if (avatar === null) {
record.avatar = undefined
}
+8 -11
View File
@@ -7,7 +7,6 @@ import {
type AppBskyGraphGetFollows,
type AtpAgent,
AtUri,
type ComAtprotoRepoUploadBlob,
type Un$Typed,
} from '@atproto/api'
import {
@@ -25,6 +24,7 @@ import {
} from '@tanstack/react-query'
import {uploadBlob} from '#/lib/api'
import {toLegacyBlobRef} from '#/lib/api/legacy-blob'
import {until} from '#/lib/async/until'
import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue'
import {updateProfileShadow} from '#/state/cache/profile-shadow'
@@ -149,6 +149,7 @@ interface ProfileUpdateParams {
export function useProfileUpdateMutation() {
const queryClient = useQueryClient()
const agent = useAgent()
const pdsClient = usePdsClient()
const updateProfileVerificationCache = useUpdateProfileVerificationCache()
return useMutation<void, Error, ProfileUpdateParams>({
mutationFn: async ({
@@ -158,22 +159,18 @@ export function useProfileUpdateMutation() {
newUserBanner,
checkCommitted,
}) => {
let newUserAvatarPromise:
| Promise<ComAtprotoRepoUploadBlob.Response>
| undefined
let newUserAvatarPromise: ReturnType<typeof uploadBlob> | undefined
if (newUserAvatar) {
newUserAvatarPromise = uploadBlob(
agent,
pdsClient,
newUserAvatar.path,
newUserAvatar.mime,
)
}
let newUserBannerPromise:
| Promise<ComAtprotoRepoUploadBlob.Response>
| undefined
let newUserBannerPromise: ReturnType<typeof uploadBlob> | undefined
if (newUserBanner) {
newUserBannerPromise = uploadBlob(
agent,
pdsClient,
newUserBanner.path,
newUserBanner.mime,
)
@@ -191,13 +188,13 @@ export function useProfileUpdateMutation() {
}
if (newUserAvatarPromise) {
const res = await newUserAvatarPromise
next.avatar = res.data.blob
next.avatar = toLegacyBlobRef(res.blob)
} else if (newUserAvatar === null) {
next.avatar = undefined
}
if (newUserBannerPromise) {
const res = await newUserBannerPromise
next.banner = res.data.blob
next.banner = toLegacyBlobRef(res.blob)
} else if (newUserBanner === null) {
next.banner = undefined
}