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

renterd multipart upload hooks #494

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions .changeset/two-ducks-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@siafoundation/react-renterd': minor
---

Add useMultipartUploadCreate, useMultipartUploadComplete, useMultipartUploadAbort, useMultipartUploadAddPart, useMultipartUploadChunk.
96 changes: 96 additions & 0 deletions libs/react-renterd/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import {
Host,
HostSettings,
Obj,
PartialSlab,
SiacoinElement,
SlabSlice,
WalletTransaction,
} from './siaTypes'

Expand Down Expand Up @@ -838,3 +840,97 @@ export function useMetricsWallet(
// hostKey: string
// origin: string
// }

// multipart

export type MultipartUploadCreatePayload = {
path: string
bucket: string
key?: string /// defaults to key:0000000000000000000000000000000000000000000000000000000000000000
}

export function useMultipartUploadCreate(
args?: HookArgsCallback<
void,
MultipartUploadCreatePayload,
{ uploadID: string }
>
) {
return usePostFunc(
{ ...args, route: '/bus/multipart/create' },
async (mutate) => {
mutate((key) => {
return key.startsWith('/bus/multipart')
})
}
)
}

export type MultipartUploadPart = {
partNumber: number
eTag: string
}

export type MultipartUploadCompletePayload = {
path: string
bucket: string
uploadID: string
parts: MultipartUploadPart[]
}

export function useMultipartUploadComplete(
args?: HookArgsCallback<void, MultipartUploadCompletePayload, void>
) {
return usePostFunc(
{ ...args, route: '/bus/multipart/complete' },
async (mutate) => {
mutate((key) => {
return key.startsWith('/bus/multipart')
})
}
)
}

export type MultipartUploadAbortPayload = {
path: string
bucket: string
uploadID: string
}

export function useMultipartUploadAbort(
args?: HookArgsCallback<void, MultipartUploadAbortPayload, void>
) {
return usePostFunc(
{ ...args, route: '/bus/multipart/abort' },
async (mutate) => {
mutate((key) => {
return key.startsWith('/bus/multipart')
})
}
)
}

export type MultipartUploadAddPartPayload = {
path: string
bucket: string
uploadID: string
eTag: string
partNumber: number
contractSet?: string
partialSlabs?: PartialSlab[]
slices?: SlabSlice[]
usedContracts?: Contract[]
}

export function useMultipartUploadAddPart(
args?: HookArgsCallback<void, MultipartUploadAddPartPayload, void>
) {
return usePostFunc(
{ ...args, route: '/bus/multipart/part' },
async (mutate) => {
mutate((key) => {
return key.startsWith('/bus/multipart/listparts')
})
}
)
}
6 changes: 6 additions & 0 deletions libs/react-renterd/src/siaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ export type Sector = {
root: string
}

export type PartialSlab = {
key: EncryptionKey
offset: number
length: number
}

export type Slab = {
health: number
key: EncryptionKey
Expand Down
30 changes: 30 additions & 0 deletions libs/react-renterd/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,36 @@ export function useObjectUpload(
)
}

export type MultipartUploadChunkParams = {
key: string
bucket?: string
contractset?: string
uploadid: string
partnumber: number
minshards?: number
totalshards?: number
offset?: number
disablepreshardingencryption?: boolean
}

export function useMultipartUploadChunk(
args?: HookArgsCallback<MultipartUploadChunkParams, Blob, void>
) {
return usePutFunc({
...args,
config: {
...args?.config,
axios: {
...args?.config?.axios,
headers: {
'Content-Type': 'multipart/form-data',
},
},
},
route: '/worker/multipart/:key',
})
}

export type RhpScanRequest = {
hostKey: string
hostIP: string
Expand Down
Loading