mirror of
https://github.com/supabase/supabase.git
synced 2026-10-19 16:19:10 +03:00
* Migrate all API calls to data folder. * Remove unused mutation. * MInor leftover type fixes. * chore: Make the `StorageExplorerStore` fully typed (#23397) * Migrate all API calls to data folder. * Convert the poor man enums into proper enums. * Add types to most of the methods. * Add types around the methods for uploading files. * Add types for file cache. * Add types for buckets. * Fix bunch of type errors. * Add types to all store methods. Fix all types in components related to the store. * Remove all anys from the Storage components. * Fix the multiple selection. * Fix the selected checkbox. * Set all private methods to private and delete some unneeded code. * Remove unneeded mutation. * Update all mutations for storage explorer to follow template syntax * Update apps/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.tsx Co-authored-by: Alaister Young <alaister@users.noreply.github.com> --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com> Co-authored-by: Alaister Young <alaister@users.noreply.github.com>
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import { UseMutationOptions, useMutation } from '@tanstack/react-query'
|
|
import toast from 'react-hot-toast'
|
|
|
|
import { components } from 'data/api'
|
|
import { handleError, post } from 'data/fetchers'
|
|
import { ResponseError } from 'types'
|
|
|
|
type ListBucketObjectsParams = {
|
|
projectRef: string
|
|
bucketId?: string
|
|
path: string
|
|
options: components['schemas']['StorageObjectSearchOptions']
|
|
}
|
|
|
|
export type StorageObject = components['schemas']['StorageObject']
|
|
|
|
// [Joshen] Ideally we transform this into a query that uses a POST i think
|
|
export const listBucketObjects = async (
|
|
{ projectRef, bucketId, path, options }: ListBucketObjectsParams,
|
|
signal?: AbortSignal
|
|
) => {
|
|
if (!bucketId) throw new Error('bucketId is required')
|
|
|
|
const { data, error } = await post('/platform/storage/{ref}/buckets/{id}/objects/list', {
|
|
params: {
|
|
path: {
|
|
ref: projectRef,
|
|
id: bucketId,
|
|
},
|
|
},
|
|
body: {
|
|
path,
|
|
options,
|
|
},
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type ListBucketObjectsData = Awaited<ReturnType<typeof listBucketObjects>>
|
|
|
|
export const useGetSignBucketObjectMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseMutationOptions<ListBucketObjectsData, ResponseError, ListBucketObjectsParams>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
return useMutation<ListBucketObjectsData, ResponseError, ListBucketObjectsParams>(
|
|
(vars) => listBucketObjects(vars),
|
|
{
|
|
async onSuccess(data, variables, context) {
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to list bucket objects: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
}
|
|
)
|
|
}
|