Skip to content

Commit

Permalink
refactor(renterd): object routes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Sep 26, 2024
1 parent a4db3e9 commit 3a2519a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 48 deletions.
7 changes: 7 additions & 0 deletions .changeset/fresh-ravens-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

The single object and list APIs routes have been updated.
24 changes: 12 additions & 12 deletions libs/renterd-js/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ import {
ObjectDeleteParams,
ObjectDeletePayload,
ObjectDeleteResponse,
ObjectListParams,
ObjectListPayload,
ObjectListResponse,
ObjectsParams,
ObjectsPayload,
ObjectsResponse,
ObjectParams,
ObjectPayload,
ObjectRenameParams,
Expand Down Expand Up @@ -208,7 +208,7 @@ import {
busMultipartListpartsRoute,
busMultipartListuploadsRoute,
busMultipartPartRoute,
busObjectsKeyRoute,
busObjectKeyRoute,
busObjectsRenameRoute,
busHostsRoute,
busSlabKeyObjectsRoute,
Expand All @@ -230,7 +230,7 @@ import {
AutopilotsPayload,
AutopilotsResponse,
busWalletEventsRoute,
busListObjectsPrefixRoute,
busObjectsPrefixRoute,
SettingsGougingParams,
SettingsGougingPayload,
SettingsGougingResponse,
Expand Down Expand Up @@ -472,20 +472,20 @@ export function Bus({ api, password }: { api: string; password?: string }) {
BucketDeleteResponse
>(axios, 'delete', busBucketNameRoute),
objectList: buildRequestHandler<
ObjectListParams,
ObjectListPayload,
ObjectListResponse
>(axios, 'get', busListObjectsPrefixRoute),
ObjectsParams,
ObjectsPayload,
ObjectsResponse
>(axios, 'get', busObjectsPrefixRoute),
object: buildRequestHandler<ObjectParams, ObjectPayload, ObjectResponse>(
axios,
'get',
busObjectsKeyRoute
busObjectKeyRoute
),
objectAdd: buildRequestHandler<
ObjectAddParams,
ObjectAddPayload,
ObjectAddResponse
>(axios, 'put', busObjectsKeyRoute),
>(axios, 'put', busObjectKeyRoute),
objectRename: buildRequestHandler<
ObjectRenameParams,
ObjectRenamePayload,
Expand All @@ -495,7 +495,7 @@ export function Bus({ api, password }: { api: string; password?: string }) {
ObjectDeleteParams,
ObjectDeletePayload,
ObjectDeleteResponse
>(axios, 'delete', busObjectsKeyRoute),
>(axios, 'delete', busObjectKeyRoute),
objectStats: buildRequestHandler<
ObjectsStatsParams,
ObjectsStatsPayload,
Expand Down
24 changes: 10 additions & 14 deletions libs/renterd-react/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ import {
ObjectDeleteParams,
ObjectDeletePayload,
ObjectDeleteResponse,
ObjectListParams,
ObjectListResponse,
ObjectsParams,
ObjectsResponse,
ObjectParams,
ObjectRenameParams,
ObjectRenamePayload,
Expand Down Expand Up @@ -176,7 +176,7 @@ import {
busHostsBlocklistRoute,
busHostsHostKeyRoute,
busObjectsRoute,
busObjectsKeyRoute,
busObjectKeyRoute,
busObjectsRenameRoute,
busHostsRoute,
busStateRoute,
Expand Down Expand Up @@ -222,8 +222,7 @@ import {
WalletEventsParams,
WalletEventsResponse,
busWalletEventsRoute,
busListObjectsPrefixRoute,
busListObjectsRoute,
busObjectsPrefixRoute,
busSettingsGougingRoute,
busSettingsPinnedRoute,
busSettingsS3Route,
Expand Down Expand Up @@ -704,19 +703,19 @@ export function useBucketDelete(
}

export function useObjectList(
args: HookArgsSwr<ObjectListParams, ObjectListResponse>
args: HookArgsSwr<ObjectsParams, ObjectsResponse>
) {
return useGetSwr({ ...args, route: busListObjectsPrefixRoute })
return useGetSwr({ ...args, route: busObjectsPrefixRoute })
}

export function useObject(args: HookArgsSwr<ObjectParams, ObjectResponse>) {
return useGetSwr({ ...args, route: busObjectsKeyRoute })
return useGetSwr({ ...args, route: busObjectKeyRoute })
}

export function useObjectAdd(
args: HookArgsCallback<ObjectAddParams, ObjectAddPayload, ObjectAddResponse>
) {
return usePutFunc({ ...args, route: busObjectsKeyRoute })
return usePutFunc({ ...args, route: busObjectKeyRoute })
}

export function useObjectRename(
Expand All @@ -737,12 +736,9 @@ export function useObjectDelete(
>
) {
return useDeleteFunc(
{ ...args, route: busObjectsKeyRoute },
{ ...args, route: busObjectKeyRoute },
async (mutate) => {
mutate(
(key) =>
key.startsWith(busObjectsRoute) || key.startsWith(busListObjectsRoute)
)
mutate((key) => key.startsWith(busObjectsRoute))
}
)
}
Expand Down
7 changes: 2 additions & 5 deletions libs/renterd-react/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
workerObjectsKeyRoute,
workerRhpScanRoute,
workerStateRoute,
busListObjectsRoute,
busObjectsRoute,
Host,
} from '@siafoundation/renterd-types'

Expand Down Expand Up @@ -79,10 +79,7 @@ export function useObjectUpload(
route: workerObjectsKeyRoute,
},
async (mutate) => {
mutate(
(key) =>
key.startsWith(busObjectsRoute) || key.startsWith(busListObjectsRoute)
)
mutate((key) => key.startsWith(busObjectsRoute))
}
)
}
Expand Down
24 changes: 7 additions & 17 deletions libs/renterd-types/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ export const busBucketsRoute = '/bus/buckets'
export const busBucketNameRoute = '/bus/bucket/:name'
export const busBucketNamePolicyRoute = '/bus/bucket/:name/policy'
export const busObjectsRoute = '/bus/objects'
export const busListObjectsRoute = '/bus/listobjects'
export const busListObjectsPrefixRoute = '/bus/listobjects/:prefix'
export const busObjectsKeyRoute = '/bus/objects/:key'
export const busObjectsPrefixRoute = '/bus/objects/:prefix'
export const busObjectKeyRoute = '/bus/object/:key'
export const busObjectsRenameRoute = '/bus/objects/rename'
export const busStatsObjectsRoute = '/bus/stats/objects'
export const busSettingRoute = '/bus/setting'
Expand Down Expand Up @@ -399,19 +398,19 @@ export type BucketDeleteParams = { name: string }
export type BucketDeletePayload = void
export type BucketDeleteResponse = void

export type ObjectListParams = {
bucket?: string
export type ObjectsParams = {
bucket: string
prefix?: string
delimiter?: string
limit?: number
marker?: string
sortBy?: 'name' | 'health' | 'size'
sortDir?: 'asc' | 'desc'
substring?: string
slabEncryptionKey?: string
slabEncryptionKey: string
}
export type ObjectListPayload = void
export type ObjectListResponse = {
export type ObjectsPayload = void
export type ObjectsResponse = {
hasMore: boolean
nextMarker: string
objects?: ObjectMetadata[]
Expand All @@ -421,15 +420,6 @@ export type ObjectParams = { key: string; bucket: string }
export type ObjectPayload = void
export type ObjectResponse = { object: Obj }

export type ObjectSearchParams = {
key: string
bucket: string
offset: number
limit: number
}
export type ObjectSearchPayload = void
export type ObjectSearchResponse = ObjectMetadata[]

export type ObjectAddParams = { key: string; bucket: string }
export type ObjectAddPayload = {
object: Obj
Expand Down

0 comments on commit 3a2519a

Please sign in to comment.